Overlay an image with an opacity setting in Ffmpeg

5,004

Use the command below.

ffmpeg -i in.mp4 -i image.png \
-af "pan=stereo|c0<c0+c2|c1<c1+c3,aeval=val(0)|val(1),volume=1.6" \
-filter_complex "[1]geq=r='r(X,Y)':a='0.5*alpha(X,Y)'[a];[0][a]overlay" out.mp4

The a='0.5*alpha(X,Y)' sets the alpha i.e. opacity.

The geq filter doesn't autodetect whether the input is RGB or YUV and takes its cue from the presence of an expression of one of the non-alpha planes, so one of those has to be specified. I've specified an expression for the R plane and set it to identity, so it isn't altered.

Share:
5,004

Related videos on Youtube

Ffmpeg fans
Author by

Ffmpeg fans

Updated on September 18, 2022

Comments

  • Ffmpeg fans
    Ffmpeg fans almost 2 years
    • I want to overlay an image with an opacity setting

    • I know how to overlay an image on a video, but I don’t understand how to set its opacity level too. I can easily add a watermark on my video, but this watermark is on opacity 100%:

    • But how do I make the image file have an opacity of 50%?

      Example: ffmpeg -i in.mp4 -i image.png -af "pan=stereo|c0<c0+c2|c1<c1+c3,aeval=val(0)|val(1),volume=1.6" -vf "opacity=0.5" out.mp4

    [AVFilterGraph @ 0000000000316dc0] No such filter: 'opacity' Error opening filters!

    • Elisa Cha Cha
      Elisa Cha Cha about 8 years
      What's your reason for using pan=stereo|c0<c0+c2|c1<c1+c3,aeval=val(0)|val(1)? I see this or similar variants often, but nobody knows why they add it.
    • Ffmpeg fans
      Ffmpeg fans about 8 years
      That 's just an example :)
  • Ffmpeg fans
    Ffmpeg fans about 8 years
    I tried , but the picture does not show opacity
  • Gyan
    Gyan about 8 years
    Show the full console output. Add it to the Q.
  • Ffmpeg fans
    Ffmpeg fans about 8 years
    Hey @Mulvya, I want to add commands to crop video and video formats , but it is an error that I do not get treated , you can help me? : ffmpeg -i in.mp4 -i image.png -af "pan=stereo|c0<c0+c2|c1<c1+c3,aeval=val(0)|val(1),volume=1.6‌​" -filter_complex "crop=iw/1.3:ih/1.3,scale=640:480,[1]geq=r='r(X,Y)':a='0.5*a‌​lpha(X,Y)'[a];[0][a]‌​overlay" out.mp4 ///===> Error: [AVFilterGraph @ 00000000027af4c0] Too many inputs specified for the "geq" filter. Error initializing complex filters.
  • Gyan
    Gyan about 8 years
    Use -filter_complex "[0]crop=iw/1.3:ih/1.3,scale=640:480[base];[1]geq=r='r(X,Y)'‌​:a='0.5*alpha(X,Y)'[‌​a];[base][a]‌​overla‌​y"
  • Ffmpeg fans
    Ffmpeg fans about 8 years
    Hey @Mulvya, it is faulty: [AVFilterGraph @ 00000000004b3760] No such filter: 'ΓÇîΓÇïoverlay' Error initializing complex filters. Invalid argument
  • Gyan
    Gyan about 8 years
    Looks like your command is either malformed or your ffmpeg does not have overlay.
  • Ffmpeg fans
    Ffmpeg fans about 8 years
    I have tried but failed on:////===> D:\ffmpeg\bin >ffmpeg -i in.mp4 -i image.png -af "pan=stereo|c0<c0+c2|c1<c1+c3,aeval=val(0)|va l(1),volume=1.6" -filter_complex "[0]crop=iw/1.3:ih/1.3,scale=640:480[base];[1]g eq=r='r(X,Y)':a='0.5*alpha(X,Y)'[??a];[base][a]??overlay" output.mp4 ...... Input #1, png_pipe, from 'image.png': Duration: N/A, bitrate: N/A Stream #1:0: Video: png, rgba(pc), 640x480 [SAR 2835:2835 DAR 4:3], 25 tbr, 25 tbn, 25 tbc [AVFilterGraph @ 0000000002708f00] No such filter: 'ΓÇîΓÇïoverlay' Error initializing complex filters. Invalid argument
  • Gyan
    Gyan about 8 years
    What's [??a] and ??overlay ? ?? should not be there,
  • Ffmpeg fans
    Ffmpeg fans about 8 years
    I don't understand , so any solution has to do the job as above ?
  • Gyan
    Gyan about 8 years
    Check the command you posted. There's ?? in there.