6

I'm trying to split an avi file as follows.

avconv -i file.avi -vcodec copy -acodec copy -ss 0 -t 10 out.avi

and this works (It creates a chunk with first 10 seconds of the video).

The problem is when I want to split from tenth second to twentieth second of the video

avconv -i file.avi -vcodec copy -acodec copy -ss 10 -t 10 out.avi

The resulting video has only sound for the first two seconds.

I use it in a loop. So similarly chunks 20-30.avi, 30-40.avi ... are chunked badly and contain only sound of various length from the beginning.

Do you know how to chunk avi videos correctly?

  • 1
    Works fine here (I'm using ffmpeg not avconv but other than that I copy/pasted your exact commands) – don_crissti Jun 2 '16 at 20:27
  • 1
    Perhaps it's a problematic codec. mediainfo file.avi should provide more info, an abbreviated output mediainfo file.avi | grep Codec | cut -d: -f 2 | tr '\n' ',' ; echo would fit in a comment. – agc Jun 5 '16 at 15:03
  • @agc The problem occurs at more files, e.g. DX50, DivX 5, 162, Windows Media Audio or Advanced Video Codec, 7, Advanced Audio Codec, 10 or isom, Advanced Video Codec, avc1, Advanced Video Coding, Advanced Audio Codec, 40 – xralf Jun 6 '16 at 6:35
  • You may need to convert it to a lossless format that splits better (see L. Levrel's answer), perform the splitting, then convert it back to the target format. Note that you'll lose some quality in doing it this way, so it's best to choose the exact same codec and encoder as the original, probably with a slightly higher quality setting. – Adam Katz Jun 8 '16 at 21:39
1
+50

Many video codecs encode video frames in two or three different ways: I-frames, P-frames, and B-frames. In short, only I-frames hold enough data to make a video starting point. With -vcodec copy, the software only does this — copying frames. So, if your cut happens at such a time that the chunk starts on an I-frame, it will play fine; otherwise, not.

Hence, there's no way around reencoding the video. Some GUI software (e.g., avidemux) do this "smartly": they reencode only the very start of the chunk, up to the first available I-frame, then copy the rest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.