0

I have a sequence of pngs with alpha, and I'd like to encode to h264 without alpha, overlaid on black.

My usual command for image sequence to h264 is

ffmpeg -r 30 -i 'template %05d.png' -c:v libx264 -pix_fmt yuv420p out.mp4

(unfortunately -pattern_type glob -i '*.png' doesn't work on windows)

But this seems to be doing something strange, as if treating the alpha as single bit:

  • Where the alpha is 1, the output pixels are from my input image (correct and nice).
  • Where the alpha is 0, the output pixels in the video is black (correct and nice).
  • But anywhere in between, it's as if it's ignoring the alpha for those pixels.

My alpha is straight (not premultiplied), and I'd like the output to be as if I'd overlaid the images with non-premultiplied alpha on black.

See image below (from aftereffects. left: alpha, middle: desired output, right: ffmpeg output)

enter image description here

(Note. Everything I've searched on this topic always comes up with "how to preserve alpha in video". But that's not what I'm after).

1 Answer 1

1

Use the overlay filter to composite the output image.

ffmpeg -framerate 30 -i 'template %05d.png' -vf "split=2[bg][img];[bg]format=yuv420p,drawbox=c=black:t=fill[bg];[bg][img]overlay=alpha=straight" -pix_fmt yuv420p -c:v libx264 out.mp4

1
  • That worked, Thank you!
    – memo
    Jan 23 at 5:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.