concat 2 different image size multiple tracks videos - ffmpeg

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

Related

ffmpeg - Generate a ping-pong looping Gif with images as input [duplicate]

I was able to reverse with:
ffmpeg -i input.mp4 -vf reverse output_reversed.mp4
And I can concat with:
ffmpeg -i input.mp4 -i input.mp4 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4
But can I concat with a reverse version of the video, with a single command?
What I am trying to achieve is a ping pong effect, where the video plays once, then plays backwards right after.
Thanks!
Technically, you can do it using
ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][0:a][r] [0:a]concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4
But the reverse filter will use a lot of memory for large videos. I've added a fifo filter to avoid frame drops. But test and see. (I haven't reversed the audio)
If your clip has no audio, the above command will throw an error – instead, use:
ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" 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.

can we use -vf and -filter:a with -filter_complex

I want to combine some videos with some specific features like(video Speed, volume increase, resolution, rotation, framerate) of the final output of the video
We can do this process in 2 steps like
Combine video
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] output.mp4
Then apply filters
ffmpeg -i output.mp4 -filter:a volume=1.0,atempo=1.0 -vf transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30 final.mp4
I can do it this way but is there any way to do it in 1 step
thank you
You have to apply the filters after concat.
ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex [0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[v][a];[v]transpose=2,setpts=1/1.0*PTS,scale=3840X2160,fps=30[outv];[a]volume=1.0,atempo=1.0[outa] -map [outv] -map [outa] output.mp4

adding background music to video using ffmpeg

I am trying to add bacground music to a video using ffmpeg and it is working fine but I want if length of video is more than the music file then music should start playing again till the video is over -
ffmpeg -i 1.mp4 -i 2.mp3 -map 0:v:0 -map 1:a:0 output.mp4
is there anyway to perform this action?
you can use the following example:
ffmpeg -i ./INPUUT_VIDEO.mp4 -filter_complex "amovie=./INPUT_MUSIC.M4A:loop=0,asetpts=N/SR/TB[aud];[0:a][aud]amix[a]" -map 0:v -map '[a]' -c:v copy -c:a aac -b:a 256k -shortest ./OUTPUT_VIDEO.mp4
you can set/change the audio bit rate by using -b:a flag, for more detail, take a look at this document.
EDIT:
for replacing new audio in the video (repeat it until the end of the video):
ffmpeg -i VIDEO.mp4 -stream_loop -1 -i MUSIC.mp3 -c copy -shortest -map 0:v:0 -map 1:a:0 OUTPUT.mp4
replacing new audio in the video (repeat video until the end of the audio):
ffmpeg -stream_loop -1 -i VIDEO.mp4 -i MUSIC.mp3 -c copy -shortest -map 0:v:0 -map 1:a:0 OUTPUT.mp4

ffmpeg combine 2 filters (with lavfi, -vf and -complex_filter)

I have 2 working code's but can't combine them (they both work separately).
ffmpeg -i video.mp4 -i audio.mp3 -shortest -t 8 -vf "lutrgb=r=1.5, crop:500:500" output.mp4
ffmpeg -i video.mp4 -f lavfi -i "color=Red:s=1280x720"
-filter_complex "[0:v]setsar=sar=1/1[s];
[s][1:v]blend=shortest=1:all_mode=overlay:all_opacity=0.7[out]"
-map [out] -map 0:a output.mp4
the lutrgb will be replaced but the color overlay so we can remove that.
endresult will take video, audio, color overlay, crop it to 1:1 and duration length of video.
Thanks
Felix
ffmpeg -i video.mp4 -i audio.mp3 -f lavfi -i "color=Red:s=500x500" \
-filter_complex "[0:v]lutrgb=r=1.5,crop=500:500,setsar=sar=1/1[crop];\
[crop][2:v]blend=shortest=1:all_mode=overlay:all_opacity=0.7[out]" \
-map [out] -map 1:a -shortest output.mp4
Use three inputs:
video.mp4 --> 0
audio.mp3 --> 1
lavfi --> 2
Chain the filters:
crop, setsar etc. the video stream in the first input and name it [crop]
[0:v]lutrgb=r=1.5,crop=320:240,setsar=sar=1/1[crop]
blend the video stream of the third input with the crop as [out]
[crop][2:v]blend=shortest=1:all_mode=overlay:all_opacity=0.7[out]
finally map the outputs using out as the video stream and the mp3 track as audio
-map [out] -map 1:a

Resources