Turn image sequence into video with transparency

前端 未结 5 1497
你的背包
你的背包 2020-12-23 11:08

I\'ve got what seems like it should be a really simple problem, but it\'s proving much harder than I expected. Here\'s the issue:

I\'ve got a fairly large image seq

相关标签:
5条回答
  • 2020-12-23 11:38

    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.

    0 讨论(0)
  • 2020-12-23 11:40

    check your version of ffmpeg

    ffmpeg -version
    

    ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

    you'll need to update to v4 for alpha support use

    sudo snap install ffmpeg 
    

    N.B. you'll need to ditch the old ffmpeg from your system.

    sudo apt-get remove ffmpeg  
    ffmpeg -version
    
    ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
      built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
      configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-avisynth --enable-cuda --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
      libavutil      56. 22.100 / 56. 22.100
      libavcodec     58. 35.100 / 58. 35.100
      libavformat    58. 20.100 / 58. 20.100
      libavdevice    58.  5.100 / 58.  5.100
      libavfilter     7. 40.101 /  7. 40.101
      libswscale      5.  3.100 /  5.  3.100
      libswresample   3.  3.100 /  3.  3.100
      libpostproc    55.  3.100 / 55.  3.100
    

    N.B. - you can hide the above from constantly appearing every time you run ffmpeg by passing

    -hide_banner

    0 讨论(0)
  • 2020-12-23 11:41

    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.

    0 讨论(0)
  • 2020-12-23 11:43

    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

    0 讨论(0)
  • 2020-12-23 11:46

    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

    0 讨论(0)
提交回复
热议问题