Convert a video to transparent using ffmpeg

10,321

Use

ffmpeg -i video.mp4 -filter_complex
"[0]split[m][a];
 [a]geq='if(lt(lum(X,Y),16),0,255)',hue=s=0[al];
 [m][al]alphamerge,format=yuva420p"
-c:v libvpx output.webm

See here for how to use this file in Chrome.

As of now, VP8 alpha playback is behind a flag, so you have to either enable it in about:flags or set the command line flag --enable-vp8-alpha-playback when you start Chrome. When the flag is enabled, alpha playback also works with MediaSource.

Share:
10,321

Related videos on Youtube

somya bhargava
Author by

somya bhargava

A tech loving person, loves to learn about new technologies going on. Working and managing a team in Rocketium in a MERN stack and handling devops also. Love learning from new developers and sharing my knowledge wherever possible.

Updated on September 18, 2022

Comments

  • somya bhargava
    somya bhargava almost 2 years

    Want to convert the black part in the video to transparent so can be used in modern browsers to overlay

    Presently doing things using html canvas

    • somya bhargava
      somya bhargava almost 8 years
      Using html canvas have created two videos one grayscale and one with rgb just copying the rgb value from grayscale video to the alpha value of rgb video means in bytes R, G, B, A putting R,Gand B from video with color and A value from color of grayscale video
    • Gyan
      Gyan almost 8 years
      Which format? I only know of VP8/VP9, which at present, support alpha channel for web playback. See basic approach here.
    • somya bhargava
      somya bhargava almost 8 years
      Input files mp4 and output any format