6

I need to perform 3 operations on a source video (in sequence)

1 resize the source video from 320X 240 to 640X480 (200%)
2 add another video file before
3 add a 3rd video after

In addition I need to combine an audio file with the finished result(3 video files concatentated.

I found a partial solution here, suggesting a way to concatenate 2 video files http://sonnati.wordpress.com/2012/07/02/ffmpeg-the-swiss-army-knife-of-internet-streaming-part-v/

But not sure of the proper syntax to concatenate a 3rd file and also mux an audio file with the finished result. Can anyone help with some suggested settings to try?

Journeyman Geek
  • 133,878
Bachalo
  • 2,857

1 Answers1

3
  1. 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.

  2. (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.