mkvmerge --split returns unexpected results

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

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

Shotcut (freeware) seems to be able to do all the video editing (e.g. trimming, stitching, fading in, fading out, inserting a black part between scenes, basically everything you could ever want). That would make all other editing tools (like MKVmerge, LosslessCut) superfluous, if and if, I managed to work with the program.

I gave it a first try (there are a lot of instructional videos on the internet), but it is so darn complicated to use; it requires an elaborate and time-consuming study to use the program plus a lot of internal technical knowledge about videofiles (codecs, keyframes, etc,) that I don't have.

And I strive not to become a video-editor, I just want have my movies, that need some simple adjusting, properly on my hard drive.

There are all sorts of basic things that happen that I just don't understand, for example:

1. When I save a video in Shortcut with quality 55% (default), I get a file size of around 600 MB. But when I save the same video with quality 100%, the size increases to 9 GB. The original file is about 800 MB, so why becomes the filesize more than 10-fold when I choose not to loose quality? What is being added?
2. In all cases the pixel dimensions of the video is 1280x720 and the framerate 23,976 fps, so in what way is the quality of the video different in the 3 files? What else is there, apart from pixel dimensions and framerate that determines video quality?

It doesn't make sense to me, but basically I don't know what I'm doing.
dcoke22
Posts: 3144
Joined: Wed Jul 22, 2020 11:25 pm

Re: mkvmerge --split returns unexpected results

Post by dcoke22 »

I think it might help if you take a moment and understand the difference between lossy and lossless compression.

Lossless compression is what you get with a zip file. When you decompress a zip file you get an exact duplicate of what was compressed; all of the data is returned.

Lossy compression is what you get with a .mp3 file or most video codecs. The algorithm is applied to an input file and the output is dramatically smaller; however, some of the original data from the input file is lost. The hope is what's lost won't be noticed.
For example, an audio CD can hold about 700MB of data, which is about 80 minutes of music. What is encoded on a CD is essentially a lossless copy of the original recording. A typical song ends up being 40 or 50 MB in size. A MP3 of one of those songs is typically one tenth the size, 4 or 5 MB. The MP3 algorithm encodes the input in a special way that saves space while throwing away some data in order to achieve its goal, but the missing data it isn't noticeable by most people. It is impossible to reverse the MP3 format and get back to the original CD quality input file.

Most video codecs are like this as well. They're a lossy compression scheme; they use a fancy encoding scheme and selectively throw away data in order to achieve their compression goals. The hope is what is missing in the output isn't noticeable by most people.

Your videos that you're editing together have been compressed with a lossy algorithm. When you use a video editing program like Shotcut it takes your lossy compressed input files, decompresses them the best it can, performs your edits, and then recompresses the whole thing again using a lossy compression scheme. Now your files have been compressed twice with a lossy compression, each time a little bit more of the file has been thrown away, which means the second copy is worse than the first copy. This is called generational loss.

The quality setting in Shotcut is a setting that controls how hard the lossy compression algorithm works, including how much data the algorithm can discard. When you say you want the quality at 100% what is most likely happening (speculating here since I don't know which algorithm is being used) is that algorithm is trying preserve all the data without throwing any away. Remember, this is at the recompress stage; the input files have already been decompressed (aka they're larger than the input files). Most lossy video codecs aren't very good when trying to work in a lossless way. There are different video codecs that are optimized for lossless encoding. The huge output size at 100% quality is a reflection of both the algorithm likely being bad at 'lossless' and lossless video is really quite big.
RAHRL
Posts: 93
Joined: Tue Dec 05, 2023 6:44 pm

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

dcoke22 wrote:
Fri Mar 29, 2024 3:42 pm
I think it might help if you take a moment and understand the difference between lossy and lossless compression.
....
Thank you for this very informative explanation. I didn't realize ShotCut had to decompress the source .mp4 file in order to edit it.
So, when, after editing it, I export an .mp4 file in ShotCut with 100% quality, it would be of the same quality as the original file and at the same time its file size could be more than 10 times larger. Really strange indeed.
RAHRL
Posts: 93
Joined: Tue Dec 05, 2023 6:44 pm

Re: mkvmerge --split returns unexpected results

Post by RAHRL »

I managed to struggle myself through ShotCut. I redid the trimming (although LosslessCut did a good job), stitched the two video's together, applied a video fade-out filter on the first video plus a video- and audio fade-in filter on the second video. Finally I exported the resulting video (which takes a while).

The first video ends with a dialogue, so I only used a video fade-out time of just 0.2 seconds and no audio fade-out filter.
The second video starts with a video fade-in of 2 seconds. Because there is no dialogue, just a police car with siren stopping in front of a building, I also applied a audio fade-in of 2 seconds.
The transition between the two scenes is much more smooth now.

I exported the result first with quality = 75% (crf=13) and did another export with quality = 100% (crf=0). This results in file sizes of 2984 MB resp. 18295 MB, while the constituent video's were around 800 MB each.
There are other export options in ShotCut that I do not understand (e.g. GVF = 125 and B-images = 3), so I left them as they were.

I kept the 75%-version and the quality of this video is probably lower than the original parts I started with, but I haven't really noticed any difference.

After checking the advanced export options, I have chosen for the same video settings as the original video's (1280x720 pixels and 23,976 fps)

Project Penelope is completed for now, I hope I don't have to do it over again anytime soon. Thx for all the support and information. Regards.
Post Reply