mkvmerge --split returns unexpected results

MKV playback, recompression, remuxing, codec packs, players, howtos, etc.
RAHRL
Posts: 80
Joined: Tue Dec 05, 2023 6:44 pm

mkvmerge --split returns unexpected results

Post by RAHRL »

I have a movie (Penelope (1966)) that consists of two .mp4 files, i.e. part 1 and part 2. I already know how to combine the two parts into one file, but unfortunately part1.mp4 ends with a 6 second banner that I want to discard before stitching the two parts together.

I have tried to use mkvmerge --split, but whatever I try (using duration or timestamps), the file is not split at the expected point.

For example, according to the Windows Explorer:
part1.mp4 duration = 00:49:09

and after:
mkvmerge -o output.mkv --split timestamps:00:49:03 part1.mkv

I get:
output-001 duration = 00:49:06
output-002 duration = 00:00:03


There is also a message:
Timestamp used in split decision: 00:49:05.992000000

I couldn't try using frame numbers, because I do not know how to display frame number and go through them one by one.
Sunoo
Posts: 89
Joined: Fri Feb 03, 2023 7:15 pm

Re: mkvmerge --split returns unexpected results

Post by Sunoo »

It will split at the nearest keyframe, which can potentially be far away depending on the video.

My solution for that sort of thing is to use LosslessCut, which can be frame perfect in more situations: https://github.com/mifi/lossless-cut
Radiocomms237
Posts: 405
Joined: Mon Oct 18, 2021 12:23 am

Re: mkvmerge --split returns unexpected results

Post by Radiocomms237 »

I tried (and abandoned) LosslessCut because it too would only cut on keyframes, maybe I had some setting incorrect (or maybe it's been changed via an update since I tried it).

Every video editing suite I've ever used has been able to cut on an exact timecode though, and most have a lossless output function if the codec is supported.

Unfortunately video editing suites, in my experience, won't trim ALL the associated tracks (audio, subtitles, chapters) like MKVToolNix does.
Last edited by Radiocomms237 on Sun Mar 24, 2024 1:17 am, edited 1 time in total.
Sunoo
Posts: 89
Joined: Fri Feb 03, 2023 7:15 pm

Re: mkvmerge --split returns unexpected results

Post by Sunoo »

In LosslessCut, on the Export screen, turn off “Keyframe cut mode”.

Depending on what you’re doing, you may want to try turning on “Smart cut”, which reencodes only the section between the closest keyframe and the cut point. In my experience, that is usually not required when trimming off the end though.
Radiocomms237
Posts: 405
Joined: Mon Oct 18, 2021 12:23 am

Re: mkvmerge --split returns unexpected results

Post by Radiocomms237 »

It's a shame we can't turn off the keyframe mode in MKVToolNix as well!
Sunoo
Posts: 89
Joined: Fri Feb 03, 2023 7:15 pm

Re: mkvmerge --split returns unexpected results

Post by Sunoo »

The trick is that you can’t easily split without a keyframe, since you can’t start the next segment between keyframes without re-encoding at least a piece of it.
RAHRL
Posts: 80
Joined: Tue Dec 05, 2023 6:44 pm

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

I played a bit with a VLC addon "Jump to time Previous frame" which lead me nowhere, but I finally managed to trim the .mp4 file with the standard Windows 10 video editor (and then it hung up my laptop, fortunately after saving the trimmed file).

It let's you determine the exact (well, in seconds) position where to trim using the mouse and better: the cursor keys.

The trimmed file is now 6 seconds shorter than the original, which is what I needed, but I still have no idea why mkvmerge wouldn't do it, with a part of the banner noticably remaining in the video.

Without much knowledge of matters I keep thinking "How can such a simple thing, like trimming a video file, be so complicated to do?"
dcoke22
Posts: 3086
Joined: Wed Jul 22, 2020 11:25 pm

Re: mkvmerge --split returns unexpected results

Post by dcoke22 »

RAHRL wrote:
Mon Mar 25, 2024 9:52 pm
Without much knowledge of matters I keep thinking "How can such a simple thing, like trimming a video file, be so complicated to do?"
If you want to learn a little bit: Video compression picture types
RAHRL
Posts: 80
Joined: Tue Dec 05, 2023 6:44 pm

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

dcoke22 wrote:
Mon Mar 25, 2024 10:11 pm
If you want to learn a little bit: Video compression picture types
That's exactly what I mean, too complicated material for me. I want to be the driver of the car, not an automotive engineer.
The tooling for even the simplest operations on video files (e.g. splitting, stitching, subtitles, etc.) is all over the place, it comes from every corner of the internet.

LosslessCut seems nice at first sight, but costs around 20 euro to download from the MS app store and there is no trial version. The source code on github is free, but do I really need to be a source code developer to trim a video file?
Sunoo
Posts: 89
Joined: Fri Feb 03, 2023 7:15 pm

Re: mkvmerge --split returns unexpected results

Post by Sunoo »

RAHRL wrote:
Tue Mar 26, 2024 3:22 am
LosslessCut seems nice at first sight, but costs around 20 euro to download from the MS app store and there is no trial version. The source code on github is free, but do I really need to be a source code developer to trim a video file?
It’s free on GitHub, and you do not need to compile it yourself… https://github.com/mifi/lossless-cut/releases/latest
RAHRL
Posts: 80
Joined: Tue Dec 05, 2023 6:44 pm

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

Sunoo wrote:
Tue Mar 26, 2024 1:07 pm
It’s free on GitHub, and you do not need to compile it yourself… https://github.com/mifi/lossless-cut/releases/latest
Yep, thx, I managed to download and decompress it. No further installation required, just clicking on the .exe file suffices. Works far better than the Windows tool that I used. It also shows the absolute framenumber and it can also merge video files.

Next question, regarding the merge, how can I get a smooth transition between the two parts? At the moment, the transition is very abrupt.
Sunoo
Posts: 89
Joined: Fri Feb 03, 2023 7:15 pm

Re: mkvmerge --split returns unexpected results

Post by Sunoo »

It’s not clear to me what you’re looking for. A merge is effectively just playing two files back to back.
Radiocomms237
Posts: 405
Joined: Mon Oct 18, 2021 12:23 am

Re: mkvmerge --split returns unexpected results

Post by Radiocomms237 »

AFAIK, the only way to add a "transition" is by using a video editing suite (pretty much ANY video editing suite).
RAHRL
Posts: 80
Joined: Tue Dec 05, 2023 6:44 pm

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

Sunoo wrote:
Tue Mar 26, 2024 11:45 pm
It’s not clear to me what you’re looking for. A merge is effectively just playing two files back to back.
I'll try to explain better. The first part ends with a particular scene, the second part starts with an other scene. When I stitch them to together with MKVmerge, it just does its job and there is no smooth transition the two scenes. As an alternative, there is also no "black screen" interval between the two scenes. It just jumps from one scene to the other which is not pleasant to watch.

Ideal would be that the first scene is faded out, and the second scene is faded in. I found something promising like that on:

How To Fade to Black in Shotcut | Fade In and Fade Out Effect | Shotcut Tutorial
https://www.youtube.com/watch?v=FLPOqcylAnQ

but I haven't got around to testing it.

I wonder if LosslessCut could do it, because the amount of tools for doing this and that with video's on my laptop seems to never stop increasing.

To be honest, I cannot imagine that somebody stitching 2 parts of a movie together, wouldn't want this.
Mr. Red
Posts: 20
Joined: Wed Nov 01, 2023 10:19 am

Re: mkvmerge --split returns unexpected results

Post by Mr. Red »

Depends on the videos/scenes you stitch together. It works really well for the extended Lord of the Ring films (disc 1 and 2).

You could make a feature request on github for losslesscut. But I doubt that it will be considered since it is not what the program is intended for.
Furthermore it would require to re-render at least the changed part.
If you want to limit yourself to a single program that can cut, merge, sync, add transitions, etc. you have to use one of the full fledged video editing tools.


What you could try is to search for a black and silent part of the video and cut a chunk of it (~1s) with losslesscut. Than you can stitch it (with mkvtoolnix) between the two parts. You won't have a fancy fade-out/in effect, but at least some kind of separator between the scenes.
Post Reply