ffmpeg How to make timed picture overlay changes that repeat - ffmpeg

Hello I am working to figure out how to make it so that my live stream has logos that change into another logo every 20 seconds currently all I have been able to figure out is how to enable them at a certain time like this.
ffmpeg -re -i "https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8" -i ./public/images/ACE.png -i ./public/images/logo2.jpg -i ./public/images/crunchy.png -i ./public/images/red.jpg -filter_complex \
"[0]scale=1290:720,setsar=1[ovrl0]; \
[1]scale=40:40[ovrl1]; \
[2]scale=40:40[ovrl2]; \
[3]scale=40:40[ovrl3]; \
[4]scale=40:40[ovrl4]; \
[ovrl0][ovrl1] overlay=x=(main_w-overlay_w)/1.025:y=(main_h-overlay_h)/18:enable='lt(mod(t,40),10)'[v1]; \
[v1][ovrl2] overlay=x=(main_w-overlay_w)/1.025:y=(main_h-overlay_h)/18:enable='between(mod(t,40),10,20)'[v2]; \
[v2][ovrl3] overlay=x=(main_w-overlay_w)/1.025:y=(main_h-overlay_h)/18:enable='gt(mod(t,40),20)'[v3]; \
[v3][ovrl4] overlay=x=(main_w-overlay_w)/1.025:y=(main_h-overlay_h)/18:enable='gt(mod(t,40),30)'" -acodec aac -vcodec libx264 -f flv "rtmp://a.rtmp.youtube.com/live2/2222-2222-2222-2222"

Set enable for first logo overlay to lt(mod(t,40),20), and for 2nd logo overlay to gte(mod(t,40),20).
This will show 1st logo at t = 0-20,40-60,80-100.. and 2nd logo at t = 20-40,60-80,100-120..

Related

overlay multiple images on a video with specific time per image and repeat (loop) the process the images until video end

I am trying to making video with ffmpeg where I want to overlay images on a video.
I want to show the image for 5 secound each and want to the process to loop until the video end.
I am using following commend which working perfectly but want to modify to loop the images.
ffmpeg -y -i long_process/2-scrolling.mp4 \
-i upload-images/040820221255452.png \
-i upload-images/040820221255453.png \
-filter_complex "[0:v][1:v]overlay=75:(H-h)/2:enable='between(t, 1, 5)'[v0]; \
[v0][2:v]overlay=75:(H-h)/2:enable='between(t, 5, 10)'" \
-c:a copy long_process/output.mp4
I am very new to ffmpeg looking for help from you.
Thanks in advance
I got the answer
ffmpeg -y -i long_process/2-scrolling.mp4 -framerate 1/3 -pattern_type glob -loop 1 -i 'tools/*.png' \
-filter_complex "[0]overlay=75:(H-h)/2:shortest=1" \
-r 60 -c:a copy long_process/output.mp4

FFMPEG picture in picture and watermark

I'm trying to take create a picture in picture effect with 2 videos and add a watermark with 1 command. Here's what I have so far, it works great, except the watermark is on the picture in picture video, not the main background video. How do I make the watermark on the main video?
ffmpeg -y -i pip.mp4 -i main.mp4 -i logo.png -filter_complex \
"[0]scale=iw/4:-1[pip]; \
[pip][2]overlay=10:10[watermark]; \
[1][watermark]overlay=main_w-overlay_w-10:main_h-overlay_h-10" output.mp4
Rearrange your labels:
ffmpeg -y -i pip.mp4 -i main.mp4 -i logo.png -filter_complex \
"[0]scale=iw/4:-1[pip]; \
[1][pip]overlay=10:10[watermark]; \
[watermark][2]overlay=main_w-overlay_w-10:main_h-overlay_h-10" output.mp4

FFMPEG zoom-pan multiple images

I am trying to stitch multiple images with some zoom-pan happening on the images to create a video.
Command:-
ffmpeg -f lavfi -r 30 -t 10 -i \
color=#000000:1920x1080 \
-f lavfi \
-r 30 -t 10 \
-i aevalsrc=0 \
-i "image-1.png" \
-i "image-2.png" \
-y -filter_complex \
"[0:v]fifo[bg];\
[2:v]setpts=PTS-STARTPTS+0/TB,scale=4455:2506:force_original_aspect_ratio=decrease,zoompan=z='min(zoom+0.0015,2.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=150:fps='30':s='1920x1080'[v2];\
[bg][v2]overlay=0:0:enable='between(t,0, 5)'[bg];\
[3:v]setpts=PTS-STARTPTS+5.07/TB,scale=3840:2160:force_original_aspect_ratio=decrease,zoompan=z='min(zoom+0.0015,2.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=150:fps='30':s='1920x1080'[v3];\
[bg][v3]overlay=0:0:enable='between(t,5, 10)'[bg];\
[1:a]amix=inputs=1:duration=first:dropout_transition=0" \
-map "[bg]" -vcodec "libx264" -preset "veryfast" -crf "15" "output.mp4"
The output is not as expected, it only zooms only on the first image, the second image is just static.
FFMPEG version - 4.1
Use
ffmpeg -f lavfi -i color=#000000:1920x1080:r=30:d=10 \
-f lavfi -t 10 -i anullsrc \
-i "image-1.png" \
-i "image-2.png" \
-filter_complex \
"[2:v]scale=4455:2506:force_original_aspect_ratio=decrease,zoompan=z='min(zoom+0.0015,2.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=150:fps=30:s='1920x1080'[v2];\
[bg][v2]overlay=0:0:enable='between(t,0,5)'[bg];\
[3:v]scale=3840:2160:force_original_aspect_ratio=decrease,zoompan=z='min(zoom+0.0015,2.5)':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=150:fps=30:s='1920x1080',setpts=PTS+5/TB[v3];\
[bg][v3]overlay=0:0:enable='between(t,5,10)'[bg];\
-map "[bg]" -map 1:a -vcodec libx264 -preset veryfast -crf 15 -y "output.mp4"
For lavfi sources, it's best to set frame rate and duration where applicable within the filter.
Since you're not looping the images, -t won't have any effect. Since zoompan will set fps in its output, you can skip input rate setting. And since it's a single image, setpts before zoompan has no relevance. It should be set only on the zoompan whose timestamps need to be shifted.
Since you've only one audio, no point sending it to amix - there's nothing to mix with! Just map it directly.

ffmpeg multiple text/logo elements

I am trying to add multiple items to an ffmpeg command and am getting stuck.
So far in the command I am automatically updating one image, which I'm using as a video, I also want to add a logo and two lines of text.
I have been successful until the last item, which is the logo overlay.
This is the relevant part of code:
ffmpeg \
-f image2 -loop 1 \
-y \
-i "/var/www/html/image_rotate.png" \
-re \
-i audio.mp3 \
-vf "movie=/var/www/html/overlay_logo.png [watermark]; [in][watermark] overlay=0:0 [out], drawtext=fontsize=10:fontfile=/var/www/html/OpenSans-Regular.ttf:textfile=/var/www/html/text1.txt:box=1:boxcolor=#000000:fontcolor=#FFFFFF:x=0:y=(h-text_h-20):reload=1, drawtext=fontsize=10:fontfile=/var/www/html/OpenSans-Regular.ttf:textfile=/var/www/htmltext2.txt:box=1:boxcolor=#000000:fontcolor=#FFFFFF:x=0:y=(h-text_h-30)" \
This gives me the following error:
Simple filtergraph ... was expected to have exactly 1 input and 1 output. However, it had >1 input(s) and >1 output(s). Please adjust, or use a complex filtergraph (-filter_complex) instead.
If I remove the last part I added (the overlay logo) I do not get the error.
If I add multiple -vf it only processes one (the text OR the logo).
I'm not sure how to achieve this.
When you need to work with multiple streams while filtering, the recommended method is to use a filter_complex.
ffmpeg \
-loop 1 \
-i "/var/www/html/image_rotate.png" \
-i "/var/www/html/overlay_logo.png" \
-i audio.mp3 \
-filter_complex "[0][1]overlay=0:0,drawtext=fontsize=10:fontfile=/var/www/html/OpenSans-Regular.ttf:textfile=/var/www/html/text1.txt:box=1:boxcolor=#000000:fontcolor=#FFFFFF:x=0:y=(h-text_h-20):reload=1, drawtext=fontsize=10:fontfile=/var/www/html/OpenSans-Regular.ttf:textfile=/var/www/htmltext2.txt:box=1:boxcolor=#000000:fontcolor=#FFFFFF:x=0:y=(h-text_h-30)" \
-y \
-shortest \
The logo is now fed as a regular input.

Combining multiple image files into a video while using filter_complex to apply a watermark

I'm trying to combine two ffmpeg operations into a single one.
Currently I have two sets of ffmpeg commands that first generate a video from existing images, then runs that video through ffmpeg again to apply a watermark.
I'd like to see if its possible to combine these into a single operation.
# Create the source video
ffmpeg -y \
-framerate 1/1 \
-i layer-%d.png \
-r 30 -vcodec libx264 -preset ultrafast -crf 23 -pix_fmt yuv420p \
output.mp4
# Apply the watermark and render the final output
ffmpeg -y \
-i output.mp4 \
-i logo.png \
-filter_complex "[1:v][0:v]scale2ref=40:40[a][b];[b][a]overlay=(80):(main_h-200-80)" \
final.mp4
Use
ffmpeg -y \
-framerate 1/1 -i layer-%d.png \
-i logo.png \
-filter_complex "[0:v]fps=30[img];
[1:v][img]scale2ref=40:40[a][b];[b][a]overlay=(80):(main_h-200-80)" \
final.mp4
(The use of scale2ref doesn't make sense since you're scaling to a fixed size).

Resources