Cutting the beginning and end off a recorded file

Added by Andy Lear over 7 years ago


This may well be a daft question, but is there a nice easy one line command that will allow me to take off the first 5 minutes say of a recording and the last 2 minutes whilst maintaining the rest of the file, ie audio and video and subtitles just copy for the section I want?

I have tried things like this:

mencoder -ss 00:05:44 -oac copy -ovc copy -idx recorded_file.mkv -o output.mkv

but get really strange results.

eg. in mplayer the sound is fine but the video is really sped up, however in vlc the video is fine, but no sound!

Any help is much appreciated


Replies (27)

RE: Cutting the beginning and end off a recorded file - Added by K Shea over 1 year ago

I think it can be done using ffmpeg, but you would need to specify times from the start of the file:

ffmpeg -i "original file.ts" -ss 00:05:00 -to 01:02:00 -c copy "output file.ts"

Would copy from 5 minutes from the start to 1 hour and 2 minutes from the start of the file.

See and (on that last one you might want to look at the entire thread). If there is a specific option in ffmpeg to trim a certain amount of time from the end of a file, I haven't found it. It looks to me like people are using ffprobe to get the duration, and then using that in a script to calculate the option values to be sent to ffmpeg. If the command really has to be all on one line for some reason, but it doesn't matter how long the line is, and if you have perl installed, you could try asking in one of the perl sites - for some reason some perl users get their kicks creating complex one-liners, so maybe one of them would be willing to tackle this for you.

I will note that ffmpeg doesn't always do well in preserving subtitles. I'm guessing you are not in the USA (due to your use of the word "whilst" - we use "while" here) but in my experience ffmpeg does not usually properly pass ATSC subtitles, even if you tell it to do a straight copy of all streams using the -c copy option. Whether it works any better in non-ATSC countries I have no idea.

RE: Cutting the beginning and end off a recorded file - Added by Kerat 1 about 1 year ago

Stéphane Bidoul wrote:

Hi Markus,

Last year I also tried to find a solution to cut mkv files easily and never found something that was suiting my tastes.

So I resolved to write mine. It's working quite nicely to fit my needs, but I never got the time to package it.

Since you seem to have just the same requirements, I just pushed the code on github (

What you'll find there is a small GUI program (edledit/ to preview a mkv file, and create cuts. There is a variety of shortcuts to start/end cuts, move by adjustable steps in the movie (including shortcuts to reduce the step size and move forward or backwards in one operation, to quickly zero-in on the point where you want to cut).

edledit saves the cutlist as an edl file (, which can be interpreted natively by mplayer and XBMC.

If you want to definitively remove the cut parts, you can then run the included mkvedlmerge which will read the edl file and call mkvmerge to split the mkv and merge it again without the cuts. Be careful: while edledit is most probably harmless, mkvedlmerge may wreck havoc with your precious movies, so please test it before doing anything serious with it...

Let me know what you think.

Best regards,


this tool looks exactly like what I am trying to do. Specifically, I would like to:
1. Use comskip to create an edl file that enumerates the commercials.
2. Use mkvmerge to split the video at and after the commercials.
3. Merge the video back together without the split commercials.
I have installed mkvtoolbox, and python on my system. How do I run mkvedlmerge?

1 2 (26-27/27)