ffmpeg: overlay multiple images to a video - image

In order to overlay a single image to a video, I can do:
ffmpeg -i vid00.mp4 -i img00.png -filter_complex "[0:v][1:v]overlay=0:0:enable='between(t, 1, 2)'" -c:v libx264 -preset ultrafast -qp 20 -c:a copy -y vid01.mp4
How can I overlay multiple images to a video in a single ffmpeg call?
I've tried stuff like:
ffmpeg -i vid00.mp4 -i img00.png -i img01.png -filter_complex "\
[0:v][1:v]overlay=0:0:enable='between(t, 1, 2)'[v0]; \
[2:v][3:v]overlay=0:0:enable='between(t, 3, 4)'[v1]; \
[v0][v1]concat=n=2:v=1:a=0,format=yuv420p[v]" -map "[v]" -map 0:a -c:v libx264 -preset ultrafast -qp 20 -c:a copy -y vid01.mp4
and variations thereof (by messing with the [0:v][1:v] indices), but to avail.,

Combined command:
ffmpeg -i vid00.mp4 -i img00.png -i img00.png -filter_complex "[0:v][1:v]overlay=0:0:enable='between(t, 1, 2)'[v0];[v0][2:v]overlay=0:0:enable='between(t, 3, 4)'" -c:v libx264 -preset ultrafast -qp 20 -c:a copy -y vid01.mp4

Related

ffmpeg combine 3 filter_complex commands

Can anyone help me. I want to combine 3 ffmpeg commands:
1:
ffmpeg -y -i input.mp4 -vf scale=720:-2,setsar=1:1 -c:v libx264 -preset ultrafast -c:a copy out1.mp4
2:
ffmpeg -i out1.mp4 -filter_complex '[0:v]crop=$url_width_:$barik:$url_width_:$url_height_, boxblur=10[fg]; [0:v]crop=$url_width_:$barik:0:0,boxblur=10[fg2]; [0:v][fg]'overlay=0:$blur_y'[bg]; [bg][fg2]overlay=0:0' -preset ultrafast -c:a copy out2.mp4
3:
ffmpeg -i out2.mp4 -i $wmf -filter_complex '[1]scale=iw*$scale:-1[wm];[0][wm] overlay=$pos' -preset ultrafast -codec:a copy final.mp4
Please help me to combine this commands to one command.
As follows:
ffmpeg -i input.mp4 -i $wmf -filter_complex '[0:v]scale=720:-2,split=3[v0][fg][fg2];[fg]crop=$url_width_:$barik:$url_width_:$url_height_, boxblur=10[fg]; [fg2]crop=$url_width_:$barik:0:0,boxblur=10[fg2];[v0][fg]'overlay=0:$blur_y'[bg]; [bg][fg2]overlay=0:0[v0];[1]scale=iw*$scale:-1[wm];[v0][wm] overlay=$pos' -preset ultrafast -c:a copy final.mp4

How to combine this 2 ffmpeg commands?

I need to combine this 2 ffmpeg commands:
"-i videoFile.mp4 -c:a copy -c:v libx264 -vf pad=$length:height=$length:x=-1:y=-1:color=#195766 resultFile"
and
"-i videoFile.mp4 -i waterMark.png -filter_complex 'overlay=10:main_h-overlay_h-10' resultFile.mp4"
Is it possible? How result command will look like?
I hope I have got it right...
The combined command is:
ffmpeg -y -i videoFile.mp4 -i waterMark.png -c:a copy -c:v libx264 -filter_complex "[0:v]pad=384:height=216:x=-1:y=-1:color=#195766[t];[t][1:v]overlay=10:main_h-overlay_h-10[v]" -map "[v]" -map 0:a resultFile.mp4
For mobile FFmpeg on android (according to OP's comment):
"-y -i ${videoFile.absolutePath} -i $waterMarkPath -c:a copy -c:v libx264 -filter_complex pad=$length:height=$length:x=-1:y=-1:color=#195766[t];[t][1:v]overlay=10:main_h-overlay_h-10[v] -map [v] -map 0:a ${resultFile.absolutePath}"
I used the following post as reference: Create video with 5 images with fadeIn/out effect in ffmpeg.
Testing:
Creating a sample video file (with audio):
ffmpeg -y -r 25 -f lavfi -i testsrc=size=192x108:rate=30 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -filter_complex amerge -vcodec libx265 -crf 17 -pix_fmt yuv420p -acodec aac -ar 22050 -t 30 videoFile.mp4
Creating a sample PNG image file:
ffmpeg -y -f lavfi -i mandelbrot=rate=1:size=192x108 -t 1 waterMark.png
Executing the combined command:
ffmpeg -y -i videoFile.mp4 -i waterMark.png -c:a copy -c:v libx264 -filter_complex "[0:v]pad=$length:$length=216:x=-1:y=-1:color=#195766[t];[t][1:v]overlay=10:main_h-overlay_h-10[v]" -map "[v]" -map 0:a resultFile.mp4
Result (first frame of the output of the test):

Can I combine these 2 commands? (or am I fighting a losing battle?)

I'm very new to ffmpeg but so far I'm enjoying it. But I'm stuck on something. I want to combine these two commands into one, something I'm sure must be possible, but after countless hours and no luck, here I am :)
ffmpeg -y -f concat -safe 0 -protocol_whitelist "file,http,https,tcp,tls" -i "tmp.images.txt" -i "tmp.audio.mp3" -filter_complex "drawbox=y=ih-38:color=black#0.6:width=iw:height=38:t=fill, drawtext=fontfile=Assets/calibrib.ttf:text='%%~ni':fontcolor=white:fontsize=14:x=(w-tw)/2:y=(h)-24" -c:v libx264 -preset veryfast -tune stillimage -shortest -pix_fmt yuv420p "tmp.slide.mp4"
ffmpeg -loop 1 -framerate 2 -i "Assets/studio.jpg" -i tmp.slide.mp4 -filter_complex "[1]scale=879:496[inner];[0][inner]overlay=207:49:shortest=1[out]" -map "[out]" -map 1:a -c:a aac -y tmp.output.mp4
the first line creates a slideshow and places text at bottom
the second line takes the slideshow video and inserts it into a background image before outputting final video
Use
ffmpeg -y -f concat -safe 0 -protocol_whitelist "file,http,https,tcp,tls" -i "tmp.images.txt" -i "tmp.audio.mp3" -i "Assets/studio.jpg" -filter_complex "[0]drawbox=y=ih-38:color=black#0.6:width=iw:height=38:t=fill, drawtext=fontfile=Assets/calibrib.ttf:text='%%~ni':fontcolor=white:fontsize=14:x=(w-tw)/2:y=(h)-24,scale=879:496[inner];[2][inner]overlay=207:49" -c:v libx264 -preset veryfast -tune stillimage -c:a aac -shortest -pix_fmt yuv420p "tmp.slide.mp4"

ffmpeg wmv to mp4 and synchronous add a logo image

The script I use to add a logo:
ffmpeg -i input.mp4 -framerate 30000/1001 -loop 1 -i test.png \
-filter_complex "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; \
[0:v][ov] overlay=10:10 [v]" -map "[v]" -map 0:a \
-c:v libx264 -c:a copy -shortest output.mp4
The command I use to convert video. (With this command, synchronize your webm and mp4 and get the picture.)
ffmpeg -i input.wmv -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis \
outputwebm.webm -c:v libx264 -crf 35 outputmp4.mp4 \
-vf "thumbnail,scale=640:360" -frames:v 1 outputpng.png
I want to add the logo image as synchronous.
The command I tried:
ffmpeg -i input.wmv -c:v libvpx -crf 10 -b:v 1M \
-c:a libvorbis outputwebm.webm -c:v libx264 \
-crf 35 -framerate 30000/1001 -loop 1 -i test.png \
-filter_complex "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; \
[0:v][ov] overlay=10:10 [v]" -map "[v]" -map 0:a \
-c:v libx264 -c:a copy -shortest outputmp4.mp4 \
-vf "thumbnail,scale=640:360" -frames:v 1 outputpng.png
Result:
Group all inputs at the front of the command and remove the encoding for the temp MP4 file.
ffmpeg -i input.wmv -framerate 30000/1001 -loop 1 -i test.png -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis outputwebm.webm -filter_complex "[1:v] fade=out:st=30:d=1:alpha=1 [ov]; [0:v][ov] overlay=10:10 [v]" -map "[v]" -map 0:a -c:v libx264 -c:a copy -shortest outputmp4.mp4 -vf "thumbnail,scale=640:360" -frames:v 1 outputpng.png
If your PNG has greater resolution than the WMV then you'll need to map the video for the webm and png outputs.

Cutting audio and adding overlay in single command FFMPEG

How to add overlay and cut audio from a particular time in any type of video?
Here is what I am trying
ffmpeg -ss 5 -t 30 -i Happier.mp4 -i Watermark.png-filter_complex "[0:v][1:v] overlay=0:0:enable='between(t,5,30)'" -preset ultrafast -pix_fmt yuv420p -c:a copy output.mp4
Use
ffmpeg -i Happier.mp4 -i Watermark.png \
-filter_complex "[0:v][1:v] overlay=0:0:enable='between(t,5,30)'[v]; \
[0]volume=0:enable='between(t,5,30)'[a]" \
-map "[v]" -map "[a]" -preset ultrafast -pix_fmt yuv420p output.mp4

Resources