FFMPEG add image at the end of a video - ffmpeg

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.

Related

FFMPEG attach thumbnail to first frame of the video

I want to attach/append an image (something like youtube) to first frame of the video, i tried this command :
ffmpeg -i video.mp4 -i image.png -map 1 -map 0 -c copy -disposition:0 attached_pic out.mp4
But it doesnt working, the first frame is not my custom image
my ffmpeg version:
ffmpeg version n4.4-80-gbf87bdd3f6-20210830 Copyright (c) 2000-2021 the FFmpeg developers
You will have to concatenate a frame to the beginning.
Re-encode audio in video.mp4. The audio is HE-AACv2, but you don't have a HE-AACv2 encoder. So it has to be changed to the more common AAC-LC to allow concatenation with the video generated from the image.
ffmpeg -i video.mp4 -c:v copy -c:a aac main.mp4
Make a video from image.png with silent filler audio. It has to have the same attributes as main.mp4.
ffmpeg -loop 1 -framerate 30 -i image.png -f lavfi -i anullsrc=r=48000 -frames:v 2 -c:v libx264 -vf format=yuv420p -video_track_timescale 30k -c:a aac image.mp4
-frames:v 2 is used instead of -frames:v 1 as required for the audio.
Make input.txt containing:
file 'image.mp4'
file 'main.mp4'
Concatenate:
ffmpeg -f concat -i input.txt -c copy output.mp4

How can I combine these two filters in ffmpeg

So Im trying to overlay a video on top of an image and then add text over the image in ffmpeg I found that Im able to do all these separately but when combining it gives me the error of
Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_drawtext_2
The line of code:
ffmpeg -loop 1 -i overlay.png -re
-i overlay.mp4
-filter_complex "[1]scale=1660:934[inner];[0][inner]overlay=0:0:shortest=1[out];
drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=text.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1"
-map "[out]" -map 1:a -c:a copy -y -s 1280x800 output.mp4
Can anyone help me with this?
You almost got it. Only needs some re-arranging:
ffmpeg -loop 1 -i overlay.png
-i overlay.mp4
-filter_complex "[1]scale=1660:934[inner];[0][inner]overlay=0:0:shortest=1,scale=1280:800,drawtext=fontsize=40:fontfile=FreeSerif.ttf:textfile=text.txt:x=(w-text_w)/2:y=(h-text_h)/2:reload=1[out]"
-map "[out]" -map 1:a -c:a copy output.mp4
See FFmpeg filtering intro for a quick explanation of the syntax.

concat 2 different image size multiple tracks videos

I try concat two videos (1.mkv has 640:360 image size, 2.mkv has 1280:720 image size), both videos have 2 video tracks and 0 audio tracks. I tried this code:
ffmpeg -i 1.mkv -i 2.mkv -filter_complex "[0:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[0:v:1]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[v0][1:v:0][1:v:1]concat=n=2:v=2:a=0[v]" -map "[v]" -c:v "libvpx" 1+2.mkv
But I have wrong:
Filter pad has an unconnected output
Your filter labels need to be adjusted, and you need to change v=2 to v=1 in concat filter:
ffmpeg -i 1.mkv -i 2.mkv -filter_complex "[0:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[1:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v1];[v0][v1]concat=n=2:v=1:a=0[v]" -map "[v]" -c:v libvpx 1+2.mkv
Since 2.mkv is already 1280x720 you can avoid processing that input:
ffmpeg -i 1.mkv -i 2.mkv -filter_complex "[0:v:0]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2[v0];[v0][1:v]concat=n=2:v=1:a=0[v]" -map "[v]" -c:v libvpx 1+2.mkv

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

Change image overlay on demand

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.

Resources