Adding overlay image to video on specific position ffmpeg - ffmpeg

I want to add one or multiple resized images anywhere over the video using ffmpeg. It works well for some position. However, it does not add images to the exact position I want. I have tested it on console and its embedded in php with dynamic variables.
ffmpeg -y -i vid_1561454052.mp4 -i Penguins.jpg -filter_complex
"[0:v][1:v] overlay=221:127:enable='between(t,0,5)'" -pix_fmt yuv420p
-aspect 16:9 -c:a copy vid_1562740969.mp4
Please Help me out...

use loop option
ffmpeg -y -i vid_1561454052.mp4 -loop 1 -i Penguins.jpg \
-filter_complex "[0:v][1:v] overlay=221:127:enable='between(t,0,5)'" \
-pix_fmt yuv420p -aspect 16:9 -c:a copy vid_1562740969.mp4

Related

FFMPEG - How to resize an image overlay?

I need to resize input 3 (logo.gif) to 360x360, but using scale=360:360 just made my video quality really bad. Here's my code:
ffmpeg -y -hide_banner -safe 0 -f concat -i "concat.txt" -i "overlay.png" -i "audio.mp3" -ignore_loop 0 -i "logo.gif" -filter_complex "[0]scale=3840x2160,zoompan=z='if(lte(zoom,1.0),1.25,max(1.001,zoom-0.0012))':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':fps=20:d=200:s=1920x1080[p];[p][1]overlay, scale=1920:1080, drawtext=fontfile=Heathergreen.otf:text=TITLE':fontcolor=black:fontsize=62:x=135:y=940, drawtext=fontfile=voxbox.ttf:text='TEXT':fontcolor=white:fontsize=70:x=120:y=885[v];[2:a]showwaves=mode=cline:s=178x56:r=20:scale=sqrt:colors=0x222222,colorkey=0x000000:0.01:0.1,format=yuva420p[w];[v][3]overlay=20:500[z];[z][w]overlay=108:740[outv]" -map "[outv]" -map 2:a -pix_fmt yuv420p -c:v libx264 -c:a aac -preset veryfast -shortest -movflags faststart -fflags genpts -r 20 "output.mp4"
UPDATE: I've simply resized the image and used that as input rather than resizing during the encode. It works fine, but if anyone has an answer to this I'd be curious to know where I was going wrong.
Instead of [v][3]overlay=20:500[z] you would use [3]scale=360:360[3v];[v][3v]overlay=20:500[z]. Your GIF should be square-shaped to begin with, to avoid distorting it.

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.

Overlaying a webm with transparency over an image with FFMpeg

I'm trying to overlay a webm file with transparency over a png background
What I have so far is this
ffmpeg -y -nostdin -i inputvideo.webm -itsoffset 2 -i background.png -filter_complex " [1]format=yuva420p,fade=in:st=0:d=1[i]; [0][i]overlay=x=0:y=0:shortest=1 " outputvideovideo.mp4
The issues with this is that it cuts the duration of the webm video from it's full length to 2 seconds and the image is on top of the webm
I've also tried, amongst other things, ffmpeg -y -nostdin -i background.png -i inputvideo.webm -filter_complex "overlay=(W/w)/2:(H-h)/2:shortest=1,format=yuv420p" outputvideo.mp4 but this just produces a black 0 second length video
I would appreciate any help or insight you can give me
I've solved this with
ffmpeg -c:v libvpx-vp9 -i inputvideo.webm -i template.png -filter_complex "[1:v][0:v] overlay=25:25:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4

ffmpeg - how to pan left on an image

I have a command that works well to pan right on an image:
ffmpeg -nostdin -loop 1 -i image0.jpg -filter_complex "[0:v]crop=ih:ih:iw/2*t/20:0,trim=duration=5,scale=-2:720" -c:a copy -pix_fmt yuv420p output.mp4
but I can't find what would be the equivalent to pan right. I tried something like this
ffmpeg -nostdin -loop 1 -i image0.jpg -filter_complex "[0:v]crop=ih:ih:iw/2-t*20:0,trim=duration=5,scale=-2:720" -c:a copy -pix_fmt yuv420p output.mp4
but it's not giving good results
Use
ffmpeg -nostdin -loop 1 -i image0.jpg -filter_complex "[0:v]crop=ih:ih:iw-ih-(iw-ih)*t/20:0,trim=duration=5,scale=-2:720" -c:a copy -pix_fmt yuv420p output.mp4
You have to set an initial offset, mine is iw-ih and then subtract an argument which expresses movement in time, here (iw-ih)*t/20

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