6

I'm trying to merge two transparent webm videos together while keeping their transparency using ffmpeg.

Main video: https://s3.amazonaws.com/medlike/logo.webm

Overlay video: https://s3.amazonaws.com/medlike/cortina.webm

Reading trough ffmpeg wiki and some stackexchange answers I made this:

ffmpeg -i logo.webm -i cortina.webm -filter_complex 'overlay=format=rgb' -vcodec libvpx output.webm

The result: https://s3.amazonaws.com/medlike/output.webm

The desired output should look like this: https://s3.amazonaws.com/medlike/vinheta-completa.webm

ffmpeg output:

ffmpeg version 2.5.2 Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 15 2015 22:16:36 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus --enable-libquvi --enable-libx265 --enable-nonfree --enable-vda
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.102 / 56. 15.102
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, matroska,webm, from 'logo.webm':
  Metadata:
    encoder         : Lavf56.19.101
  Duration: 00:00:09.80, start: 0.000000, bitrate: 712 kb/s
    Stream #0:0: Video: vp8, yuv420p, 960x540, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      alpha_mode      : 1
Input #1, matroska,webm, from 'cortina.webm':
  Metadata:
    encoder         : Lavf56.19.101
  Duration: 00:00:09.80, start: 0.000000, bitrate: 436 kb/s
    Stream #1:0: Video: vp8, yuv420p, 960x540, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
    Metadata:
      alpha_mode      : 1
[swscaler @ 0x7f9512006800] No accelerated colorspace conversion found from yuv420p to argb.
[libvpx @ 0x7f9511827000] v1.3.0
Output #0, webm, to 'output.webm':
  Metadata:
    encoder         : Lavf56.15.102
    Stream #0:0: Video: vp8 (libvpx), yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc (default)
    Metadata:
      encoder         : Lavc56.13.100 libvpx
Stream mapping:
  Stream #0:0 (vp8) -> overlay:main
  Stream #1:0 (vp8) -> overlay:overlay
  overlay -> Stream #0:0 (libvpx)
Press [q] to stop, [?] for help
frame=  245 fps=6.3 q=0.0 Lsize=     114kB time=00:00:09.80 bitrate=  95.6kbits/s    
video:112kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.853043%

Thanks

5
  • Stream #1:0: Video: vp8, yuv420p Stream #0:0: Video: vp8, yuv420p Looks like your video doesn't have an alpha channel, if it did it would be yuva420p. See this post for more: bit.ly/1Es6KLK
    – stib
    Commented Feb 25, 2015 at 4:37
  • That's what I thought, too. metadata: alpha_mode: 1 is from libavformat/matroskadec.c. It means the alpha flag was set in the input webm. ffmpeg -h decoder=vp8 shows the vp8 decoder doesn't take any options, though. So if it's not decoding to yuva420p, IDK how to change that. Commented Feb 25, 2015 at 4:59
  • Also, why are you telling overlay to output RGB? I don't see anything in the docs about alpha-blending problems when operating in YUV space. Commented Feb 25, 2015 at 5:02
  • I wasn't able to solve the issue, instead, I rendered both videos using PNG codec and successfully merged them using the overlay ffmpeg filter, and than converted it to webm
    – DaviBenNun
    Commented Feb 26, 2015 at 14:16
  • Anyone make any progress? I have a non-transparent video and want to just force the video to not have transparency?
    – Meekohi
    Commented Nov 12, 2015 at 22:04

1 Answer 1

4

Since 2016-07-20, it's possible to decode properly a webm with alpha channel (VP8a or VP9a) but you need the -vcodec libvpx option. You must download an FFmpeg compiled after that date (or compile yourself with up-to-date commits) and use the following command:

ffmpeg -i logo.webm -vcodec libvpx -i cortina.webm -filter_complex overlay -vcodec libvpx output.webm

Note that -vcodec libvpx is before the input that needs to be read using the alpha planes (in this case, is cortina.webm the overlaid video, thus we put the option just before it).

(As Mulvya states, the format conversion should be avoided in this case.)

2
  • 1
    Why format=rgb? Unnecessary and lossy given that the inputs are YUV and vpx encodes to YUV.
    – Gyan
    Commented Aug 24, 2016 at 15:44
  • You're right. I didn't notice it (just copied his command and added the option). I correct it.
    – cdlvcdlv
    Commented Aug 24, 2016 at 15:54

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.