4
I'm trying to perform movie editing in an automated way with avconv. It is made in two steps:
- extract some parts of an input movie:
- concatenate the parts to form an output movie:
I tried some combinations of containers and codecs for the intermediate and output movies, but it always resulted in one of the following situations:
the audio becomes more and more delayed during playback of the output movie. It seems that each transition of the concatenated parts adds to the delay of the audio. This happens, e.g., with the following formats and codecs:
avconv -i input-movie.avi -ss $TIME_1 -vframes $NUMFRAMES_1 -f avi -q 1 -aq 1 -y movie-part1.avi avconv -i input-movie.avi -ss $TIME_2 -vframes $NUMFRAMES_2 -f avi -q 1 -aq 1 -y movie-part2.avi ... avconv -i input-movie.avi -ss $TIME_N -vframes $NUMFRAMES_N -f avi -q 1 -aq 1 -y movie-partN.avi avconv -i concat:movie-part1.avi|movie-part2.avi|...|movie-partN.avi -f avi -codec mpeg4 -q 1 -acodec libmp3lame -aq 1 -y output-movie.aviaudio and video in the output movie are in sync, but it is longer than it should be. In this situation the output of
avprobe -show_streams output-movieshows duration and videonb_frameslonger than expected, although runningavconv -i output-video -f image2 %06d.jpgproduces the expected number of jpg frame files (the expected number of frames is$NUMFRAMES_1 + $NUMFRAMES_2 + ... + $NUMFRAMES_N). This happens, e.g., with the following formats and codecs:avconv -i input-movie.avi -ss $TIME_1 -vframes $NUMFRAMES_1 -f mpeg -q 1 -aq 1 -y movie-part1.mpeg avconv -i input-movie.avi -ss $TIME_2 -vframes $NUMFRAMES_2 -f mpeg -q 1 -aq 1 -y movie-part2.mpeg ... avconv -i input-movie.avi -ss $TIME_N -vframes $NUMFRAMES_N -f mpeg -q 1 -aq 1 -y movie-partN.mpeg avconv -i concat:movie-part1.mpeg|movie-part2.mpeg|...|movie-partN.mpeg -f avi -codec mpeg4 -q 1 -acodec libmp3lame -aq 1 -y output-movie.avi
Is there a reliable/accurate way to perform these operations and get a resulting movie with audio and video in sync and with the expected number of frames?
Just to clarify: Video and audio should only go out of sync if you use the
copycodec for both audio and video (and even then it doesn't always happen). As for the output appearing longer than it should be: If you get the right number of images out of the concatenated movie, then it should have the right duration, right? Do you have some specific example? – slhck – 2013-03-06T06:22:38.170@slhck I'm re-elaborating this question. Should I split it into two questions - one for the out of sync audio and other one for the longer final duration? – erdavila – 2013-03-07T03:32:26.440
No, it's fine as-is. The problem with out of sync is something you probably can't solve anyway – at least when you're doing stream copy. If it's out of sync even though you're re-encoding, then consider putting that into another question. – slhck – 2013-03-07T07:42:02.707