Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to perform movie editing in an automated way with avconv. It is made in two steps:

  1. extract some parts of an input movie:
  2. 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:

  1. 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.avi
    
  2. audio 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-movie shows duration and video nb_frames longer than expected, although running avconv -i output-video -f image2 %06d.jpg produces 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?

share|improve this question
    
Just to clarify: Video and audio should only go out of sync if you use the copy codec 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 Mar 6 '13 at 6:22
    
@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 Mar 7 '13 at 3:32
    
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 Mar 7 '13 at 7:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.