I have a transparent webm video I generated using a slightly modified version of electron-recorder that I need to overlay on an MP4 video from a smartphone. I've tried using the overlay filter but it always puts a black background on the overlay instead of transparent. I am sure that the overlay has a transparent background. I can play it in a webpage and the background shows through.

What command would I need to get this working?

This is the command I used to generate the webm from transparent PNGs (extracted and modified from electron-recorder for my testing): cat *.png | ffmpeg -y -f image2pipe -r 30 -i - -c:v libvpx -pix_fmt yuva420p -metadata:s:v:0 alpha_mode="1" output.webm

Here is the output of ffprobe overlay.webm:

ffprobe version 3.0.2 Copyright (c) 2007-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libfaac --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libx265 --disable-lzma --enable-nonfree --enable-vda
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, matroska,webm, from 'overlay.webm':
    encoder         : Lavf57.25.100
  Duration: 00:00:01.77, start: 0.000000, bitrate: 152 kb/s
    Stream #0:0: Video: vp8, yuv420p, 720x720, SAR 1:1 DAR 1:1, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
      alpha_mode      : 1
  • Confirm that the overlay has an alpha channel. On the webpage, maybe the background is being keyed out some way, or it uses the sidestream method of alpha i.e. the video is double-sized with one-half being the alpha. Run ffplay in.webm -vf alphaextract. If you see a full white output or there's an error, then there's no transparency. – Gyan Dec 5 '16 at 17:09
  • Interesting. I get this: [Parsed_alphaextract_0 @ 0x7fc6afd22d20] Requested planes not available. [Parsed_alphaextract_0 @ 0x7fc6afd22d20] Failed to configure input pad on Parsed_alphaextract_0 – Max Schmeling Dec 5 '16 at 17:19
  • So, there's no alpha. Paste the readout of ffprobe in.webm into your Q. – Gyan Dec 5 '16 at 17:30
  • I pasted that output as well as the command I used to generate the overlay. – Max Schmeling Dec 5 '16 at 17:45
  • Oops, I forgot that FFmpeg until recently couldn't decode the alpha channel in VP8, which your video does have. You'll need to upgrade to a ffmpeg build more recent than July '16. Get it from here. – Gyan Dec 5 '16 at 18:10

Until recently, FFmpeg couldn't decode the alpha plane in VP8/9 streams with alpha. It still can't.

But if you have a recent build (> July 16) of FFmpeg with libvpx compiled, then you can use

ffmpeg -i base.mp4 -c:v libvpx -i overlay.webm -filter_complex overlay output.mp4

If you want to do this now you will likely need the accepted answer with the small modification of appending -vp9 to libvpx:

ffmpeg -i base.mp4 -c:v libvpx-vp9 -i overlay.webm -filter_complex overlay output.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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