The scale
filter can do this :
if you want resize your input video to specific size such as 640x480 regardless of it's size and Aspect Ratio, then:
ffmpeg -i INPUT -filter_complex [0:v]scale=640:480[Scaled] -map [Scaled] OUTPUT
.
but, not preserving Aspect Ratio may result ugly videos. so if you want resize your input video and preserve Aspect Ratio, then specify one of dimensions and put -2
for other:
ffmpeg -i INPUT -filter_complex [0:v]scale=-2:480[Scaled] -map [Scaled] OUTPUT
.
(and 3.) Concatenating multiple streams can be done by concat
filter:
Below command will merge three video sreams (will drop audio streams if thay exist):
ffmpeg -i INPUT1 -i INPUT2 -i INPUT3 -filter_complex [0:v][1:v][2:v]concat=n=3:v=1:a=0[Merged] -map [Merged] OUTPUT
.
The whole command that do for you, will be something like below:
ffmpeg -i VideoBefore.mp4 -i MainVideo.mp4 -i VideoAfter.mp4 -i Audio.mp3 -filter_complex [1:v]scale=-2:480,setsar=sar=1[Scaled];[0:v][Scaled][2:v]concat=n=3:v=1:a=0[Merged] -map [Merged] -map 3:a OUTPUT.mp4
Important note : The concat
filter documentation says : All corresponding streams must have the same parameters in all segments; the filtering system will automatically select a common pixel format for video streams, and a common sample format, sample rate and channel layout for audio streams, but other settings, such as resolution, must be converted explicitly by the user. The SAR
(Sample Aspect Ratio) attribute is 1:1 often. but scale
filter will change it. and we need to change it again to be equal to other streams. the setsar
filter do it.
-map
option, and-c copy
. Maybe you can edit your question and show us what exactly you have. I just found concatenating to be a little difficult. Especially if it's MP4 or MKV, and the bitstreams are of the same format, you might want to look into MP4box or mkvtoolnix for file concatenation instead of FFmpeg.