retpower.blogg.se

Ffmpeg crf option
Ffmpeg crf option












ffmpeg crf option

(BR) Modify the bitrate, using: ffmpeg -i $infile -b $bitrate $newoutfile These are the proposed answers that I tested: I tested most of the other proposed answers to this question.

ffmpeg crf option

Be aware that changing the resolution always requires reencoding, so all the ins and outs of the other answers apply here as well. In these examples, the size is divided by twice the value and multiplied by two to ensure the pixel size is a multiple of two, which is required for some codecs including H265. One fifth size: ffmpeg -i input.mkv -vf "scale=trunc(iw/10)*2:trunc(ih/10)*2" -c:v libx265 -crf 28 a_fifth_the_frame_size.mkv

ffmpeg crf option

One quarter size: ffmpeg -i input.mkv -vf "scale=trunc(iw/8)*2:trunc(ih/8)*2" -c:v libx265 -crf 28 a_fourth_the_frame_size.mkv One third size: ffmpeg -i input.mkv -vf "scale=trunc(iw/6)*2:trunc(ih/6)*2" -c:v libx265 -crf 28 a_third_the_frame_size.mkv To scale to half size: ffmpeg -i input.mkv -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx265 -crf 28 half_the_frame_size.mkv See the ffmpeg docs on scaling for more info. But when converting for a small device this may be acceptable. The downside is you also lose a large amount of quality because less pixels mean less image details. Also the file size can be reduced significantly. It's a lot quicker, up to multiple times faster depending on your source and the amount of the resolution decrease, as there are less pixels to be encoded. All the answers here are for reducing the compression quality but nobody has mentioned reducing video frame size. You mentioned wanting to reduce filesize to fit more videos on a mobile device, which is my usecase as well. ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4 Vary the CRF between around 18 and 24 - the lower, the higher the bitrate. For example for a target size of 1 GB (one giga byte, which is 8 giga bits) and 10 000 seconds of video (2 h 46 min 40 s), use a bitrate of 800 000 bit/s (800 kbit/s): ffmpeg -i input.mp4 -b 800k output.mp4Īdditional options that might be worth considering is setting the Constant Rate Factor, which lowers the average bit rate, but retains better quality. To see this technique applied using the older H.264 format, see this answer, quoted below for convenience:Ĭalculate the bitrate you need by dividing your target size (in bits) by the video length (in seconds). ffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4 Note that lower CRF values correspond to higher bitrates, and hence produce higher quality videos. To use it, replace the libx264 codec with libx265, and push the compression lever further by increasing the CRF value - add, say, 4 or 6, since a reasonable range for H.265 may be 24 to 30. Since 2013 a video format much better than H.264 is widely available, namely H.265 (better in that it compresses more for the same quality, or gives higher quality for the same size). The rate-distortion tradeoff matters for final files that you're going to stream many times.Update 2020: This answer was written in 2009. If that's the case, you should probably require that they encode with x264 with at least preset=slower, so you can just give them a crf value if you're already requiring x264. LordNeckBeard brings up the question of whether you're delivering these files directly to clients. (actually, I think FFmpeg can decode higher bit depths, but x264 can only produce files up to 10bit.) Or I guess you could get them to send you slightly-lossy pro-res files, if that's a lot easier for your workflows. It's significantly smaller than huffyuv or utvideo, and can support up to 10bit. Lossless h.264 is probably the best format for sending files around. CRF targets a heuristic for quality, not strictly a quality target.)Īnyway, in that case, I have no idea what other encoders support. (Is there a word for this? flexible bitrate? Other than target-quality, as opposed to target-bitrate. However, you probably meant variable-across-clips, rather than the usual within-one-file meaning, because CFR as a quality target is clearly much better than blindly setting a target bitrate for many different sources. (h.264 is never going to be strictly CBR like mp3 or something, unless your I frames look HORRIBLE :P) You only get CBR with x264 if vbv-maxrate = bitrate, and even then it's can be VBR within the buffer size. the links I dug up for my answer on this question about VBR streaming). x264 2pass figures out what CRF will give the desired bitrate (pass1), and then uses it (pass2). Any decent encoder can hit a target bitrate (with 2pass), but still spend the bits intelligently to achieve similar quality throughout the file.














Ffmpeg crf option