3

I'm encoding ProRes 4444 with alpha channel video's to transparent video for web in both VP9 (webm) and HEVC (mp4). I'm using a great free tool by Rotato to encode to both formats at once.

However, because I would like to have more control over e.g. the dimensions and the bitrate, I'm looking into ffmpeg. I can encode to both formats with the following params.

# vp9
ffmpeg -i in.mov -vf scale=-1:720 -c:v libvpx-vp9 -auto-alt-ref 0 -pix_fmt yuva420p -acodec libvorbis -cpu-used 3 -deadline good -crf 40 out.webm 

# hevc
ffmpeg -i in.mov -vf scale=-1:720 -c:v hevc_videotoolbox -allow_sw 1 -alpha_quality 0.9 -tag:v hvc1 -q:v 65 out.mp4

The problem: the videotoolbox encoder generates a weird white garbage around the black pencil animations and fade-in's from transparent to black pencil become fade-in's from white pencil to black pencil!?

Here are screenshots of the two compared (top one is my ffmpeg output):

hevc

rotato

Anyone have good settings for ffmpeg I cano use to encode good quality HEVC with alpha? Hardware: MacBook Air M1 and Win11 + GTX 1060 (I should be able to use NVEnc, but don't know how)

Jos
  • 1,387
  • 1
  • 13
  • 27
  • Have you tried to encode it with x265? I wonder if you are seeing artifacts from HW encoder – kesh Mar 17 '22 at 21:24
  • Yes, but x265 has no option to encode alpha, so that's not an option – Jos Mar 17 '22 at 21:25
  • Can you provide your input file? – Markus Schumann Mar 29 '22 at 15:37
  • Apart from being a file of 8Gb in size, I may not publish that file, because it's property of my client.. – Jos Mar 30 '22 at 16:58
  • Here's a free online example vid to test with: https://www.vecteezy.com/video/20153377-hand-draw-symbol-icon-2d-animation-alpha-channel. See below for an answer from @Kajuna – Jos Jun 29 '23 at 08:51

2 Answers2

4

For me, the solution was to use the premultiply filter

-vf premultiply=inplace=1

Kajuna
  • 449
  • 5
  • 20
  • That totally solved the white artifacts @Kajuna ! Thanks so much! – Jos Jun 29 '23 at 08:40
  • 1
    In addition to this, I lowered the quality to compensate for bigger filesize when using premultiply. My new full command is now `ffmpeg -i in.mov -vf scale=-1:720 -c:v hevc_videotoolbox -allow_sw 1 -alpha_quality 0.9 -tag:v hvc1 -q:v 35 -vf premultiply=inplace=1 out.mp4` – Jos Jun 29 '23 at 08:49
  • Great! @Jos, could you accept this answer? – Kajuna Jun 30 '23 at 13:47
  • 1
    Yes of course, I should have done so already. Sorry you had to ask ;-) – Jos Jul 01 '23 at 16:32
1

Before the options I would check the system preferences to retain the alpha channel transparency more from Larry here, they are build natively - see the two options larry has on his site.

Check to ensure in System Preferences > Keyboard. The Services category on the left, then select enable Encode Selected Video Files on the right. From any video application, export a project that contains transparency directly using the ProRes 4444 codec. Then, in the Finder, right-click the resulting .mov and select Services -> Encode Selected Video Files. Wait a few seconds for the next menu to appear.

enter image description here


Seems like you are looking for the encoder and bitrate options, you can list them out fully as below

Option 1: H.264 encoder

// Help you understand the ***H.264 encoder's options.
ffmpeg -hide_banner -h encoder=h264_nvenc | xclip -sel clip

[![enter image description here][1]][1]

Option 1: HEVC/H.265 encoder

// Help you understand the **H.265 encoder's options.
ffmpeg -hide_banner -h encoder=h264_nvenc | xclip -sel clip

Now for bitrates, setup values using -b:v, -maxrate:v and -bufsize:v options

And since you have Mac Hardware - if you type this it will tell your configuration.

 ~ ffmpeg -h encoder=hevc_videotoolbox

Once you have this you can choose to tweak it in the configuration, rebuild and yourself.. with different options look here for build on VM + Apple M1 and here for the encoding Support for Apple Silicon M1 encoders

Transformer
  • 6,963
  • 2
  • 26
  • 52
  • 1
    I'm confused. I'm not sure why I should use the 'encode video' from services. I've done that and I have no control over the bitrate, so the video gets very large in filesize. But more important, I cannot automate it. I'm also not sure what to do / expect from the above ffmpeg commands. The first two don't work (command xclip not found) and the third one shows me options I was already using. It's just that the black painted lines in the animation have white rubbish around them at any bitrate / quality – Jos Mar 31 '22 at 20:33
  • 1
    Hey Jos, did you find a solution or make any progress on this? Thx! – Mike Apr 06 '22 at 23:08
  • Jos or @Mike , did you ever find a solution to this issue? – Kajuna Jun 27 '23 at 22:22
  • 1
    Yes, finaly I can encode with ffmpeg, thanks to @Kajuna 's answer here: https://stackoverflow.com/a/76569133/757201 – Jos Jun 29 '23 at 08:42