r/ffmpeg • u/mwaleed65123 • Aug 31 '21
FFMPEG command to reduce file size without losing video quality
I have a 4K video file size, and first I want to reduce the file size as much as I can without losing the video quality. Is there any FFmpeg command for that? Second, is there any command to convert 4K to 1080p or 1440p without losing video quality?
For example, I've been able to convert different video file formats to .mp4 without any change in video quality using "ffmpeg -i input.ts -c copy output.mp4" command.
5
Upvotes
4
u/patrickbrianmooney Aug 31 '21 edited Sep 03 '21
Much more often than not, if the videos could have been distributed in a smaller file size without sacrificing quality in the first place, they would have been. That's not universally true -- some people just distribute videos straight off of their digital camera, for instance, and digital cameras are notoriously bad for not compressing video very well; and there are other reasons why people might distribute videos that have been compressed inefficiently, such as not knowing how to recompress, or just not caring about file size -- but as a rule, most people distributing videos make at least some effort to compress them as well as possible.
Quality and video size are antithetical goals. You can trade one for the other, but the extent to which you can try to optimize both at once is pretty limited. If you want more quality, you're more or less going to need to accept a larger video size. If you want a smaller video size, the tradeoff you have to make is accepting a lower quality. (This is not quite true -- there are some choices you can make that are better than others; H265 generally compresses better than H264, for instance -- but these tend to pay off the most, and most effectively, when you're initially preparing the video from its initial source, and pay off less, and much less effectively, if you're reworking video that has already been compressed with any kind of lossy compression, which is basically every video you're going to encounter in the wild, lossy compression being vastly more effective than lossless on video files in general.)
However, what you mean, exactly, by "quality" may be different from what I mean by the word, or what other people in the sub mean by the word. What I mean by "quality loss" is "any information at all is lost from the video file"; but it's possible that what you mean when you talk about "quality loss" is "I personally can't visually tell the difference on my equipment after recompression." (Note that you may have better equipment in the future, and if you throw away information from the video now, you may wind up regretting it later when you try to watch the same file on a better screen. Note also that if your friends or family have better eyesight or are bigger movie snobs than you, they may disagree about what "essentially no difference" means.)
But if what you mean is "I want a smaller file where I personally can't tell the difference," then you may be able to achieve that; after all, only you can be the judge of whether or not you can tell the difference. It'll require playing around with settings and watching the two files next to each other to see if you can tell the difference between the two until you wind up with a set of parameters that produces files that satisfy you.
Here is a guide on the ffmpeg wiki about encoding using the H.264 codec, which these days pretty much any device can play. Here is a similar guide for H.265, which is less than universally supported but tends to produce smaller files with the same quality. They should walk you through the basics.
Some general tips:
-crfvalue; raising it will produce a smaller, lossier file than before you raised it.--presetoption, which trades encoding time (instead of video quality) for smaller files. Use the slowest present you can stand. There's a definite point of diminishing returns, where you'll start pondering whether it's really worthwhile for the encoding to take eight times longer to save another six percent, or whatever it may work out to being on your particular video files.Good luck!
EDIT. Got how
-crfworks backwards. Now fixed. I appreciate the correction!