Outils pour utilisateurs

Outils du site


issue211:mon_opinion

Ceci est une ancienne révision du document !


I had upgraded my paltry 128GB SSD to 1TB for Christmas last year, so it came as quite a shock when I ran out already. I thought it may be a good subject for newbies and other Sunday drivers.

My first tool is usually df (with tack h by default). Just to find that my drive is 99% in use. My first stop is usually my iso folder and I delete a whole bunch of distros that I tested and was not impressed by; you know the kind that breaks. Having done this, I checked again and my disk is still 94% full. Yikes! (This tutorial will be about size only).

I turn to my next tool, ncdu, to find my video’s folder taking up waaay too much space.

Now I know Ubuntu comes with a disk usage analyser, but I prefer the terminal. Drilling down with the right-arrow key, in ncdu, I find a folder that is ten times to thirty times the size of the others! Inspection of said video series, confirms that it is encoded with h264 at 1080p.

This is where I fall down, I don’t really understand, or have I put effort into video encoding. I understand that bitrate obviously makes the biggest difference in size, but all my videos are variable bitrates, so I’m not sure how to measure it. I do, however, know that I can re-encode my videos with an excellent tool named handbrake. (I know online compressors exist, but uploading & downloading files takes time.)

With a tool like handbrake, I do not need to know ratios or algorithms, I can simply pick what format I would like and the resolution and the frame rate (for a start).

In general, hardware encoding is going to be a lot faster than software encoding, however, your file size may go up, instead of down. The most I have managed to save in hardware encoding with the same resolution, was 10%-15%. This will be a trend, the faster the encoding, the bigger the file size.

Handbrake also uses all your cores, so encoding on my dual-core CPU takes longer than on my quad-core CPU, even though the dual-core machine has twice the memory, so encode on your best CPU.

For me, if size is important (but I’d like to keep 1080p), I usually use Matroska, as it generally gives me a +-50% file size reduction from the original mp4. If the resolution is not that important to you, you will make the most gains dropping it from 1080p to, say, 720p, and still be able to read what is on the screen. You may be asking, if I am such a n00b at encoding, how would I know Matroska encodes to a smaller size? Well simple, I tested online. I took a file, uploaded it on https://www.freeconvert.com/video-compressor/download - and compared the output. MKV saved me 51% on average, and MP4 43% (when setting target size to 50%). The source encoding also makes a difference, so if you want to compress from MP4 to MP4, your best bet is to lower the resolution as there is not much more handbrake can do. Handbrake also has an option for web optimisation. We will talk about the interface in another issue. Now, without knowing what web optimization does, we can see, by the output file size, that it saves +-5MB on a 300MB file.

For most people interested in saving space, the preset “fast” (e.g. fast1080p30), will be enough. I found no difference between some of the presets like “discord” or “youtube”; the file size stayed the same. I can also not detect any difference in quality to the naked eye. I will include images at the end of the results. Webm being a newer format, will not support a wide variety of audio formats in the encoding, so it generally encodes faster than the other software compression algorithms, but slower than hardware compression. Again proving that faster means bigger file size. (In my case the file was always larger than the input file, so I have written it off completely.)

Now handbrake can do a lot more than just make video files smaller, but 99% of my use cases, be it at home or work, is making the files smaller to save space. Obviously frames-per-second makes a difference, so encoding something from 30FPS to 60FPS means your file size will increase without the video being clearer as you are simply doubling up every frame. Two of the same frame just means both will be played in the same time one is played on the original video, netting you zero gain for the larger file size.

So the tip I want to give you as a newbie, where the busy interface may seem scary, is simply choose fast1080p or Matroska if you want smaller files without losing resolution. In my case, it is all training videos, so I have to be able to read what is on screen. Thus I need to keep the best resolution possible. For work, it is videos of processes on machines, so the resolution is not important, but the machines they play on are not the best, so high CPU intensive encoding is out. Use cases are important, but we focus on Ubuntu in the home here.

Now it’s time for me to save another 20GB so I do not run out of space the next time my system does an update.

Can I tell the difference? I cannot (1080p video played at 4k). Even the instructor's Apache beard is in focus (you know, it grows a patchy here… a patchy there… OK I’ll see myself out!).

My original file was MP4 at 681MB, and the output is about 320MB average, so working back from that, my 39.5GB course should compress to about 20GB. I see no difference in the quality, even from the original, and I can read what is written on the screen, which is what was important to me. As they say in the adverts, your mileage may vary, but in our case, not by much. The only investment will be time.

issue211/mon_opinion.1732990030.txt.gz · Dernière modification : 2024/11/30 19:07 de auntiee