How do I split a WebM file without re-encoding?

4

1

I have this WebM file that I need to split, but I'd like to do it without re-encoding. Putting it in an MKV container doesn't work, because the point where I need to split it is not a keyframe, so it doesn't work.

Is this possible? I'd really like to do it without re-encoding if possible, because I don't want to have to lose any quality.

Tamara Macadam

Posted 2013-08-29T08:41:31.730

Reputation: 63

1If the point at which you wish to split it is not a keyframe, then no, this is not possible. All non-keyframes rely in part on the previous frame in the sequence (they essentially record changes to the previous image rather than a whole image -- there are b-frames that complicate this, but the same principle applies) and changing this to an I-frame (keyframe) involves re-encoding. – evilsoup – 2013-08-29T09:41:34.580

Damn. I assume there isn't any way to add a keyframe in or something, either... That's really annoying. – Tamara Macadam – 2013-08-29T09:53:46.207

I think @evilsoup should post this as an answer. There is really no way to add keyframes later on. Depending on your use case though, there might be other options. What do you need to achieve exactly, Tamara? – slhck – 2013-08-29T10:19:36.400

Basically, I need to split the video because it's part one of a two part video I got from YouTube. The problem being, there's an outro at the end of the video, and I'd like to cut that off. I already know how to join the videos back together, that's really easy. – Tamara Macadam – 2013-08-29T10:26:50.850

Answers

6

It's quite easy using the command avconv from the command line. You do not need to worry about splitting on a keyframe if, as the questioner later specified, you are cutting off an outro (the end of the video). Here's an example:

$ avconv -i videoandoutro.webm  -t 00:03:30  -codec: copy  videoonly.webm

That would take videoandoutro.webm and create a new file, videoonly.webm and truncate it after exactly 3 minutes and 30 seconds.

Cutting off an intro as well is actually not much harder, but doing that will run into keyframe issues.

$ avconv -ss 00:01:01 -i jossintro.webm  -t 00:00:30  -codec: copy oatybar.webm

The above will take a .webm file called "jossintro.webm" and cut a slice starting at around 1 minute, 1 second in. The output is put in "oatybar.webm", which is trimmed to (about) 30 seconds long. The result will actually be slightly longer since the start time will be rounded to the previous keyframe.

[Note that avconv is based on ffmpeg, and so that tool will likely also work, but I have only tested this with avconv.]

hackerb9

Posted 2013-08-29T08:41:31.730

Reputation: 579

This is a great answer. I used it to break a video into a front and back half and remove some in the middle. Then I used mkvmerge to hook them up as I couldn't get avconv to concat, although I think it should have worked. – Karl Henselin – 2015-12-12T15:10:04.260