I know this may sound like a weird statement coming from the author of FastFlix, but from the bottom of my heart, please stop the needless pixel loss! Every time you re-encode (aka transcode) a video it losses information, which lowers the quality and makes it a lot worse if you ever need to do it again. Re-encoding makes you a pixel killer!
Why am I saying re-encoding and not just “encoding” when you may have the original video? Sadly, to even fit onto your computer or device the video you are working with has already been encoded in a highly compressed manor. Even phones and professional cameras like the RED series use real-time compression. Raw video takes too much bandwidth for standard storage media. For example, imaging recording raw video using a video sensor at 16-bit 60FPS. A single minute of UHD footage would be near 60GB! That translates into a bitrate of over 7,500,000 kbps. Compare that to a re-encoded YouTube video of HDR 60FPS 4K footage is around 30,000 kbps, 250x times less quality!
Why does it matter?
Everyone has seen potato quality images and videos being re-shared again and again. The quality loss is due to needless re-encoding.
Websites generally always re-encode videos for a variety of reasons, such as adding watermarks or forcing certain bitrates. It may be required in some instances, but for most cases it’s overkill. If I had the power I would challenge websites to instead publish what encoding targets are required and allow for direct playback of the original file.
But while we don’t have control over that, that makes it even more important to not make it worse when you have control over it.
In the above example I took a short video and encoded it again and again and again using the same settings each time. The video still looks good while being watched, but if you zoom in you can see the entire thing has essentially become blurred. Don’t do this to your own videos, save the pixels!
Future Proofing
Another thing to consider is not just the result you have now, but how it will look in ten or twenty years. Sure, the single 1080p or 4K re-encode you did now may look perfect. But what about when 16K TVs are standard? What about when your phone or monitors pixel density is four to eight times higher than it is now? Behind the scenes of good TVs and devices is an “Ai” chip that upscales videos to look better on newer screens. With less detail to start with, it won’t look as good as if you didn’t re-encode.
Remember that amazing video you took with your flip phone all those years ago that you can’t even tell what is happening in it anymore? You don’t want that to happen to your videos now.
There are some cases that it cannot be avoided that we will cover later, but even common operations like trimming videos and rotating them can be accomplished without re-encoding.
Trim and Rotate without re-encoding
Two very common reasons people want to re-encode videos is to shorten them to a particular section, or rotate it the proper direction. Thankfully you can do both of those without modifying the original video stream. I am using the command line tool ffmpeg
to accomplish this, which is available for free.
Rotate
To rotate the video, you just have to add some metadata to the container the video is in. This is how phones set videos to portrait or landscape mode without having to change their encoder settings.
ffmpeg -i your_video.mp4 -metadata:s:v rotate=90 -map 0 -c copy rotated_video.mp4
In the above example, replace your_video.mp4
with the video file you need rotated. It will be copied with the new metadata to rotated_video.mp4
and now should be rotated properly.
Trim
To cut out a section of the video, you simply need to “copy” everything between the two desired points. For example if you want to cut out a 48 second section between 1:02
and 1:50
(one minute two seconds and one minute fifty seconds), use the following command.
ffmpeg --ss 1:02 -to 1:50 -i your_video.mp4 -map 0 -c copy rotated_video.mp4
Are there any exceptions?
There are a few cases where you simply cannot avoid re-encoding. If you need to add effects, crop, make any actual modifications to the video, you will need to re-encode.
However if you are keeping the video as is, there are only three instances you should consider re-encoding for:
- Limited bandwidth scenarios
- Device compatibility
- Cannot provide required storage space
Limited bandwidth scenario
ISPs still like to pretend upload speeds don’t matter. Even if an ISP provides 1Gbps down most still have less than 45Mbps upload peak. Things get even worse for mobile, where the average upload rate is around 10Mbps. Then on top of that, a general rule of thumb is your video bitrate should be around half or less of available bandwidth to ensure there isn’t stuttering.
That means if you’re planning to share videos in real time with the world, you simply have to re-encode (transcode) it.
Device compatibility
There are some large companies that have terrible compatibility with commonly accepted formats to be anti-competition. That means if you or a loved one is enslaved to some large fruit company, you may need to tinker with your videos to please the orchard overlords.
Storage space
“Storage is cheap” is a phrase I hear a little too much in the coding world. In the real world without a large quarterly tech budget, you have to count your pennies. If you can re-encode a video so that it’s near visually lossless while saving on storage space for your needs, go for it!
Well this is not visible if you re-encode once (only) and you use e.g. a 30GB source to create a 1.5GB 1080p file.
I would change the title of this article to something less abosolute.
I tried the similar trim command before and I think that can de-sync the audio and video. It might not be observable local but when you upload them to website like youtube it may happen
I have a 8TB HDD that’s filled up with all family videos. Most videos were taken by Sony A6400 (XAVC S 4K 30P 100M). I was about to start Handbrake to reduce the size of all videos to 1080p30Fast and 23 quality but concerned about this statement in your article above. Can you explain more? To my naked eye, the videos are indistinguishable to me after a test compression of a few videos but in 20 years, if there is quite a bit of difference, that’s something I need to think about
“Behind the scenes of good TVs and devices is an “Ai” chip that upscales videos to look better on newer screens. With less detail to start with, it won’t look as good as if you didn’t re-encode”
To start off with, you have great source quality videos there if you have 4K 100M from that Sony (I have a similar Sony, so good choice!), and honestly you will have some room to encode without visual loss, even in the long run.
But if you are going from 4K 100M down to 1080p 23 CRF, there will be very noticeable pixel loss. Just playing them back side by side on a screen isn’t the most telling (and really depends on screen resolution and physical size). I would zoom in on someone’s face while there is a bit of motion in the scene and compare visual artifacts to show the true difference. It should be pretty easy to see that stuff starts to become blockly instead of smooth edges.
Going from 4K -> 1080p you’re cutting your total pixels in forth (from 8 million pixels to 2 million). No matter how good the encoding is will replace that lost.
Doing a quick test from a XAVC S 4K 60p 150M I have down to 1080p 23crf it cuts it down from 150M bitrate to around 4M, a huge amount of information lost.
If your hurting on space, I would figure out how much you want to save space wise first to know how much you need to cut them down. For example, if instead keep it 4K, go to
slow
encoding speed (the slower the better usually), tune is film, Auto level and profile, and set CRF to 22, I go from 150M to 67M, under half the size but keeping most of the quality.Appreciate your guidance here! Do you possibly know Handbrake? I don’t see a 4k option – just see SuperHQ in presets along with some others for specific devices to playback on
In Handbrake I would start with the Matroska H.264 MKV 2160p60 preset.
In Summary tab, change Format MKV to MP4
In Dimensions tab, change Resolution Limit to None (aka keep the source resolution)
In Video tab:
Framerate: Same as Source
Quality: between 24-20 as you see fit
Encoder Preset: Slow
Encoder Tune: Film (for camera videos)
Encoder Profile: Auto
Encoder Level: Auto
Then Save New Preset so you can use it again!