Change image overlay on demand - ffmpeg

I need your help. I stream to Twitch with this Command:
ffmpeg -i input.mp4 -i image.jpg -filter_complex 'overlay=x=10:x=10' -s \
1920x1200 -framerate 15 -c:v libx264 -preset ultrafast -pix_fmt yuv420p \
-threads 0 -f flv 'rtmp://'
How is it possible to change the image.jpg picture to another picture on a variable time? I will don't restart the FFMPEG Command.

Add the -f image2 -loop 1 input options for the image input, then atomically replace image.jpg when desired such as by using mv.
Basic example:
ffmpeg -i input.mp4 -f image2 -loop 1 -i image.jpg -filter_complex overlay output.mp4
Streaming example:
ffmpeg -re -i input.mp4 -f image2 -loop 1 -i image.jpg -filter_complex "overlay,format=yuv420p" -c:v libx264 -preset fast -g 50 -b:v 4000k -maxrate 4000k -bufsize 8000k -f flv 'rtmp://'

To answer the "variable time" part of your question use a cron job to run scripts that update the overlay image at a specified time i.e. every 5 mins. For example you can create a folder of various overlays and select one randomly every 5 minutes and copy it to image.jpg. FFMPEG will then render the new image to your stream.
It is important to use -f image 2 -loop 1 -thread_queue_size 512 -i image.jpg especially when rendering other image formats.

Related

ffmpeg combine images and audio into video and loop through images until end of audio

I have found this code to combine multiple images and one audio file into video, but what I want is the images to loop until the end of audio. So what I mean, if I have 5 images and each image is shown for 5 seconds, after 25 seconds show again the first image, second image etc and this will continue until the end of audio.
ffmpeg -r 0.2 -i Scan-130802-%04d.jpg -i "1.mp3" \
-vcodec libx264 -vf scale=1920:1080 \
-crf 25 -preset slow -acodec copy video.mp4
another problem I have is that with the above code the images appear horizontally flipped for some reason.
It's more efficient to do this in two steps.
#1
ffmpeg -framerate 1/5 -i Scan-130802-%04d.jpg -vf "scale=1920:1080,setsar=1" -r 5 -c:v libx264 -crf 25 -preset slow scan-video.mp4
#2
ffmpeg -stream_loop -1 -i scan-video.mp4 -i "1.mp3" -codec copy -shortest -fflags +shortest -max_interleave_delta 200M video.mp4

FFMPEG Video loop from images files

I am trying to make a video from a bundle of image files and then apply a an overlay on top of it.Another requirement is to make the video loop 3x. It is simply not working.
The first three paths are pointing toward the same image bundle. (A folder containing images like the following DSC0001_0013.jpg,DSC0002_0013.jpg,etc)
Observed symptoms:
The script runs infinitely.I produces a video file of 0 KB.I have to abort script using CTRL+C
This is my script.
ffmpeg
-start_number 1 -framerate 3/1
-i "C:\Users\xxx\AppData\Local\xxx\xxx\xxx\xxx\xxx\xxx\xxx\963d9d9b8e1\DSC%04d_0013.jpg"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\xxx\xxx\xxx\xxx\963d9d9b8e1\DSC%04d_0013.jpg"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\xxx\xxx\xxx\xxx\963d9d9b8e1\DSC%04d_0013.jpg"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\1237\1138\overlay.png"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\1237\1138\overlay.png"
-i "C:\Users\xxx\AppData\Local\xxx\xxx\projects\1237\1138\overlay.png"
-filter_complex " [0:v]scale=600x900[scaled1]; [1:v]scale=600x900[scaled2]; [2:v]scale=600x900[scaled3]; [scaled1][3:v]overlay[tmp1]; [scaled2][4:v]overlay[tmp2]; [scaled3][5:v]overlay[tmp3]; [tmp1][tmp2][tmp3]concat=n=3[scaled] "
-map [scaled] -r 10 -vcodec libx264 -pix_fmt yuv420p -crf 23 "C:\Users\xxx\Documents\Projets\2020\xxx\video test ffmpeg\test.mp4"
Use the -stream_loop option:
ffmpeg -stream_loop 3 -framerate 3/1 -i DSC%04d_0013.jpg -i overlay.png -filter_complex "[0]scale=600:900[bg];[bg][1]overlay=format=auto,format=yuv420p[v]" -map "[v]" -r 10 -c:v libx264 -crf 23 output.mp4
#Ilogan, This is our solution.
-start_number 1 -framerate 3/1
-i DSC%04d_0013.jpg
-loop 1 -i overlay.png"
-filter_complex "
[0:v]scale=600x900[scaled];
[scaled][1:v]overlay,trim=duration=3,loop=loop=2:size=9[tmp]
" -map [tmp] -r 10 -vcodec libx264 -pix_fmt yuv420p -crf 23
test.mp4

Combine Two Commands (Get Video from Images)

I have 300 images and i wants to generate video from these images.
i am new to FFMPEG so now i am using two commands to generate video from images.
Command to generate video from images which also add Logo on video
ffmpeg -framerate 24 -i img_%d.jpg -i logo.png -filter_complex \
"[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \
-vcodec libx264 -crf 25 -pix_fmt yuv420p test_video.mp4
After using above command i am getting the video to add audio to this video i am using below command
ffmpeg -i test_video.mp4 -i inputfile.mp3 -c:v libx264 -c:a libvorbis -shortest final_video.mp4
which generates video and i am getting below message
MPEG-4 AAC decoder is required to play the file
Help to combine this both command. if possible can we add sound without any decoder required
Log for command 1 https://drive.google.com/file/d/1zS7gvrPy69VK_MkyE4127FpX2kEziJHq/view?usp=sharing
and Log command 2 https://drive.google.com/file/d/1rHqVGzj7f003aWP6eISiyUjsES8_EWuw/view?usp=sharing
Try next command:
ffmpeg -framerate 24 -i img_%d.jpg -i logo.png -i inputfile.mp3 -filter_complex \
"[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" \
-vcodec libx264 -crf 25 -map 2:a -c:a copy -pix_fmt yuv420p -shortest test_video.mp4
-map 2:a is needed to skip image in case if there is cover image in track.
With -c:a copy track will not be re-encoded, so you will have mp3 inside of your video file.

FFMPEG add image at the end of a video

I need to add an image for one second at the end of a .mp4 video file using FFMPEG. My video size is WxH and my image size is MxM, so video and image sizes are different.
I have tried different options in order to add the image at the end of the video as:
ffmpeg -i "concat: videoIn.mp4|image.jpg" -c copy videoOut.mp4
or
ffmpeg -i videoIn.mp4 -loop 1 -t 1 -i image.jpg -f lavfi -t 2 -i anullsrc -filter_complex "[0:v][0:a][1:v][2:a] concat = n=2:v=1:a=1[v][a] -c:v libx264 -c:a aac -strict -2 -map" [v] "-map" [a]" videoOut.mp4
but none gave me the result I need.
Can someone help me?
Kind regards
Use
ffmpeg -i videoIn.mp4 -loop 1 -t 1 -i image.jpg -f lavfi -t 1 -i anullsrc -filter_complex "[1:v]scale=WxH:force_original_aspect_ratio=decrease,pad=W:H:'(ow-iw)/2':'(oh-ih)/2'[i];[0:v][0:a][i][2:a] concat=n=2:v=1:a=1[v][a]" -c:v libx264 -c:a aac -map "[v]" -map "[a]" videoOut.mp4
The image is resized to fit within a WxH frame size and then padded to get the video's frame size.
You'll need ffmpeg 3.4.2 or later.

animation between images using FFmpeg

Hi I am new in FFmpeg,
I have made video from slideshow of sequential images (img001.jpg, img002.jpg, img003.jpg....). Using following commands in Ubuntu 14.04
ffmpeg -framerate 1/5 -i img%03d.jpg -c:v libx264 -r 30 -pix_fmt yuv420p -vf scale=320:240 out.mp4
But now I want to put animation like fade-in, fade-out between each sequential images, I want to generate video,
can anybody help me how to make it, i have searched lots of things but could not get....
The best way to do this is create intermediate mpeg's for each image and then concatenate them all into a video. For example, say you have 5 images; you would run this for each one of the images to create the intermediate mpeg's with a fade in at the beginning and a fade out at the end.
ffmpeg -y -loop 1 -i image -vf "fade=t=in:st=0:d=0.5,fade=t=out:st=4.5:d=0.5" -c:v mpeg2video -t 5 -q:v 1 image-1.mpeg
where t is the duration, or time, of each image. Once you have all of these mpeg's, you use ffmpeg's concat command to combine them all into an mp4.
ffmpeg -y -i image-1.mpeg -i image-2.mpeg -i image-3.mpeg -i image-4.mpeg -i image-5.mpeg -filter_complex '[0:v][1:v][2:v][3:v][4:v] concat=n=5:v=1 [v]' -map '[v]' -c:v libx264 -s 1280x720 -aspect 16:9 -q:v 1 -pix_fmt yuv420p output.mp4
This gives you the desired video and is the simplest and highest quality solution with ffmpeg. Let me know if you have any questions about how the above command works.

Resources