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?

2
  • Does concatenating work for you? If so, you could simply concat file 1 and 2, and then concat file 3 with the result from the first operation. To mux audio in, combine the complete video file with an audio track using the -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.
    – slhck
    Nov 25, 2012 at 10:12
  • 5
    Ah, great! Can you post the correct answer below, please? This way, others can benefit from the solution; you can even accept the answer
    – slhck
    Nov 26, 2012 at 5:19

1 Answer 1

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.

5
  • 2
    It can be simplified to setsar=1.
    – llogan
    Oct 10, 2016 at 1:17
  • @LordNeckbeard I edited it.
    – Behroozfar
    Oct 10, 2016 at 8:01
  • @LordNeckbeard What if the images are of different sizes. Thus using scale=WIDTH:-2 will lead to different resolutions which in turn leading to failure of merging. Aug 6, 2018 at 12:18
  • @Killer See the force_original_aspect_ratio option in the scale filter, and combine it with the pad or crop filter. Refer to Resizing videos with ffmpeg to fit into static sized player for examples.
    – llogan
    Aug 6, 2018 at 17:03
  • Yes did the same instead of crop. I scale properly, put the pad and maintained a common aspect ratio. I refer to your other answer. Sorry, I wasn't able to delete the comment. Aug 7, 2018 at 4:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .