Turn image sequence into video with transparency

人走茶凉 提交于 2019-11-29 21:23:20

Yes ffmpeg certainly does support alpha channel in a video file. Not all codecs in ffmpeg seem to support alpha yet tho. Motion PNG in a .MOV file is one good combination for alpha.

To encode/import images with alpha to a video with alpha try: ffmpeg -i %d.png -vcodec png z.mov

Quicktime will play that.

To decode/export a video with alpha to images with alpha try: ffmpeg -i z.mov -f image2 export2\%d.png

Note that I exported them to a directory called 'export2'. Be sure to leave the %d parts in there. These commands will work as is on a Windows system. Linux/Mac users may need to add quote marks and swap some \ for / as usual.

I know this topic is a bit old, but I am posting anyway.

FFMPEG with Quicktime Animation (RLE) or FFVHUFF/HUFFYUV will do.

  • ffmpeg -i yoursequence%d.png -vcodec qtrle movie_with_alpha.mov
  • ffmpeg -i yoursequence%d.png -vcodec ffvhuff movie_with_alpha.avi
  • ffmpeg -i yoursequence%d.png -vcodec huffyuv movie_with_alpha.avi

You will get video files with transparency(alpha channel) preserved.

I have also heard On2-VP6 variation (Not the WebM-VP8 yet) can handle alpha, but I do not have their codec at hand.

This also works. - ffmpeg -i yoursequence%d.png -vcodec png movie_with_alpha.mov

For web developers reaching this question and banging their heads against the wall in frustration… It is possible to create a transparent WebM video, but at the moment you might need to compile ffmpeg and the required libraries from source.

I wanted to display a rendered Blender video in a website but preserve the transparency. The first step was to render the Blender output as individual PNG files. After that, I spent quite a while trying to coerce ffmpeg to convert those PNG files into a single video. The basic command is simple:

ffmpeg -i input%04d.png output.webm

This command loads all PNGs with the filenames input0000.png through input9999.png and turns them into a video. The transparency was promptly lost. Combing through the output I realized ffmpeg was helpfully selecting a non-transparent format:

Incompatible pixel format 'yuva420p' for codec 'flv', auto-selecting format 'yuv420p'

At this point I was realizing I might have to recompile ffmpeg from scratch. I struggled with a few other tools, but ultimately ended up back with ffmpeg. After compiling libvbx and ffmpeg from the latest source, things worked a charm.

I'm assuming there's a strong possibility that you or others would want to use such video in an interactive flash piece. Here's a tutorial on doing so including ffmpeg compiling to uncompressed avi with alpha channel from png.

http://away3dtutorials.blogspot.com/2011/02/ffmpeg-to-compile-jpeg-to-video-with.html

Cody,

You can write your own command line utility using the Quicktime SDK for Windows, I would recommend sticking with the higher level Quicktime COM apis and only delving into the C-APIs if you really have to.

-Nick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!