Overlay an image with an opacity setting in Ffmpeg
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.
Related videos on Youtube
Ffmpeg fans
Updated on September 18, 2022Comments
-
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 about 8 yearsWhat'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 about 8 yearsThat 's just an example :)
-
Ffmpeg fans about 8 yearsI tried , but the picture does not show opacity
-
Gyan about 8 yearsShow the full console output. Add it to the Q.
-
Ffmpeg fans about 8 yearsHey @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*alpha(X,Y)'[a];[0][a]overlay" out.mp4 ///===> Error: [AVFilterGraph @ 00000000027af4c0] Too many inputs specified for the "geq" filter. Error initializing complex filters.
-
Gyan about 8 yearsUse
-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]overlay"
-
Ffmpeg fans about 8 yearsHey @Mulvya, it is faulty: [AVFilterGraph @ 00000000004b3760] No such filter: 'ΓÇîΓÇïoverlay' Error initializing complex filters. Invalid argument
-
Gyan about 8 yearsLooks like your command is either malformed or your ffmpeg does not have overlay.
-
Ffmpeg fans about 8 yearsI 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 about 8 yearsWhat's
[??a]
and??overlay
???
should not be there, -
Ffmpeg fans about 8 yearsI don't understand , so any solution has to do the job as above ?
-
Gyan about 8 yearsCheck the command you posted. There's
??
in there.