How can I use the avconv tool to concatenate multiple .mp4 videos of different encoding parameters in a single container, without losing quality?
Asked
Active
Viewed 1,659 times
1
a06e
- 667
- 3
- 8
- 23
-
You can only do that if the output video is losslessly encoded. Is that acceptable? What's your use case here? – slhck Oct 02 '14 at 06:56
-
@slhck Yes, the output video can be losslessly encoded. The use case is that I have different scenes of a movie in separate files, encoded with different parameters. I would like to concatenate them in a single output file, in such a way that each scene retains original quality. – a06e Oct 02 '14 at 12:08
-
related: http://superuser.com/a/522658/91054, however that uses `ffmpeg`, and some options are not recognized by `avconv` – a06e Oct 02 '14 at 12:09
1 Answers
1
The commands given here will not work when videos have different encoding parameters. In fact, you can only concatenate them by bringing them to the same parameters first, working in the decoded (pixel) domain, and then losslessly storing them.
For example, harmonizing the framerate and video dimensions, audio sampling rate and audio channels:
avconv -i input_1.mp4 -s 1920x1080 -r 25 -c:v ffv1 -c:a pcm_s16le -ac 2 -ar 44100 out_1.avi
avconv -i input_2.mp4 -s 1920x1080 -r 25 -c:v ffv1 -c:a pcm_s16le -ac 2 -ar 44100 out_2.avi
avconv -i "concat:out_1.mp4|out_1.mp4" -c copy output.avi
This uses ffv1 as lossless codec, but any other lossless codec would work fine (e.g., huffyuv in an AVI or libx264 with -crf 0 in an MP4).
If you want a "small" output file again, you have no other choice than compressing output.avi with some lossy encoder.