Correctly splitting an avi file

avconvcommand linemediavideovideo editing

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?

Best Answer

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.

Related Question