#re-encode original with varying CRF values
for i in 14 18 24 28 32 38 46 51; do
ffmpeg -i original.mp4 -c:a copy -c:v libx264 \
-preset fast -crf $i -qphist -tune stillimage \
crf_$i.mp4
Examples:
source video size: 233mb
with configuration:
source video:
Duration: 00:25:21.21, start: 0.000000, bitrate: 1288 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1151 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
source audio:
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Examples:
CRF Guide
for i in 14 18 24 28 32 38 46 51; do
ffmpeg -i original.mp4 -c:a copy -c:v libx264 \
-preset fast -crf $i -qphist -tune stillimage \
crf_$i.mp4
Examples:
source video size: 233mb
with configuration:
source video:
Duration: 00:25:21.21, start: 0.000000, bitrate: 1288 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 1151 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
source audio:
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Examples:
commands | size | video output format | audio output format |
Original | 233 MB | 1280x720, 1151 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc | aac, 44100 Hz, stereo, fltp, 128 kb/s |
ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4 | 336 MB | 1280x720, 1465 kb/s, q=-1--1, 30 fps, 15360 tbn, 30 tbc | same |
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -qphist -tune stillimage crfimage.mp4 | 344 MB | 1280x720, 1764 kb/s, q=-1--1, 30 fps, 15360 tbn, 30 tbc | same |
ffmpeg -i input.mp4 -c:v libx264 -crf 23 crf23.mp4 | 290 MB | 1280x720, 1465kb/s, q=-1--1, 30 fps, 15360 tbn, 30 tbc | same |
ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4 | 336 MB | 1280x720, 1465 kb/s, q=-1--1, 30 fps, 15360 tbn, 30 tbc | same |
ffmpeg -i input.mp4 -c:v libx264 -preset fast -crf 18 crf18fast.mp4 | 468 MB | 1280x720, 2447 kbps, 30fps, 16:9 | aac 4 40Lc, 128 Kbps, 2 chan, 44100, 16 bits |
ffmpeg -i input.mp4 -c:v libx264 -b:v 500k 500knoaudioption.mp4 | 116 MB | 1280x720, 500 Kbps, 30 fps, 16:9 | aac 4 40LC, 128 Kbps, 2 chan, 44100, 16 bits |
ffmpeg -i input.mp4 -r 25 framerate25fps.mp4 | 282 MB | 1280x720, 1423 kb/s, q=-1--1, 25 fps, 12800 tbn, 25 tbc | aac 4 40LC, 128 Kbps, 2 chan, 44100, 16 bits |
ffmpeg -i input.mp4 -b:v 64k -bufsize 64k videobitrate64kbits.mp4 | 37 MB | 1280x720, 66 kb/s, q=-1--1, 64 kb/s, 30 fps, 15360 tbn, 30 tbc | aac 4 40LC, 128 Kbps, 2 chan, 44100, 16 bits |
ffmpeg -i input.mp4 -c:v libx264 -crf 28 crf28.mp4 | 195 MB | 1280x720, 1051.1kbits/s, q=-1--1, 30 fps, 15360 tbn, 30 tbc | aac 4 40LC, 128 Kbps, 2 chan, 44100, 16 bits |
ffmpeg -i input.mp4 -c:v libx264 -crf 28 -acodec libmp3lame -b:a 16k -ac 1 -ar 16000 crf2811.mp4 | 178 MB | 1280x720, 913kbps, q=-1--1, 30 fps, 15360 tbn, 30 tbc | MPEG ver 2 69 Layer 3, 64kbs, 1 chan, 24000 Hz, 16 bits |
ffmpeg -i input.mp4 -c:v libx264 -crf 26 -acodec libmp3lame -b:a 24k -ac 2 -ar 24000 crf2611.mp4 | MB | 1280x720, 913kbps, q=-1--1, 30 fps, 15360 tbn, 30 tbc | MPEG ver 2 69 Layer 3, 64kbs, 1 chan, 24000 Hz, 16 bits |
ffmpeg -i input.mp4 -acodec libopus crf2811.mp4 | ts |
Lossless H.264
You can use -crf 0 to encode a lossless output. Two useful presets for this are ultrafast or veryslow since either a fast encoding speed or best compression are usually the most important factors.
Lossless Example (fastest encoding)
ffmpeg -i input -c:v libx264 -preset ultrafast -crf 0 output.mkv
Lossless Example (best compression)
ffmpeg -i input -c:v libx264 -preset veryslow -crf 0 output.mkv
Note that lossless output files will likely be huge, and most non-FFmpeg based players will not be able to decode lossless, so if compatibility or file size issues you should not use lossless. If you're looking for an output that is roughly "visually lossless" but not technically lossless use a -crf value of around 17 or 18 (you'll have to experiment to see which value is acceptable for you). It will likely be indistinguishable from the source and not result in a huge, possibly incompatible file like true lossless mode.
CRF stands for Constant Rate Factor, x264’s best single-pass encoding method.
Quick Summary: What is the Constant Rate Factor?
The Constant Rate Factor (CRF) is the default quality setting for the x264 encoder. You can set the values between 0 and 51, where lower values would result in better quality (at the expense of higher file sizes). Sane values are between 18 and 28. The default for x264 is 23, so you can use this as a starting point.
With
ffmpeg
, it'd look like this:ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4
If you're unsure about what CRF to use, begin with 23 and change it according to your subjective impression of the output. Is the quality good enough? No? Then set a lower CRF. Is the file size too high? Choose a higher CRF. A change of ±6 should result in about half/double the file size, although your results might vary.
Video format = Timeline
The following table is a partial history of international video compression
standards.
Levels
As the term is used in the standard, a "level" is a specified set of constraints that indicate a degree of required decoder performance for a profile. For example, a level of support within a profile specifies the maximum picture resolution, frame rate, and bit rate that a decoder may use. A decoder that conforms to a given level must be able to decode all bitstreams encoded for that level and all lower levels.
The maximum bit rate for High Profile is 1.25 times that of the Base/Extended/Main Profiles, 3 times for Hi10P, and 4 times for Hi422P/Hi444PP.
The number of luma samples is 16x16=256 times the number of macroblocks (and the number of luma samples per second is 256 times the number of macroblocks per second).
Decoded picture buffering
Previously encoded pictures are used by H.264/AVC encoders to provide predictions of the values of samples in other pictures. This allows the encoder to make efficient decisions on the best way to encode a given picture. At the decoder, such pictures are stored in a virtual decoded picture buffer (DPB). The maximum capacity of the DPB is in units of frames (or pairs of fields), as shown in parentheses in the right column of the table above, can be computed as follows:
Where MaxDpbMbs is a constant value provided in the table below as a function of level number, and PicWidthInMbs and FrameHeightInMbs are the picture width and frame height for the coded video data, expressed in units of macroblocks (rounded up to integer values and accounting for cropping and macroblock pairing when applicable). This formula is specified in sections A.3.1.h and A.3.2.f of the 2009 edition of the standard.
For example, for an HDTV picture that is 1920 samples wide (PicWidthInMbs = 120) and 1080 samples high (FrameHeightInMbs = 68), a Level 4 decoder has a maximum DPB storage capacity of Floor(32768/(120*68)) = 4 frames (or 8 fields) when encoded with minimal cropping parameter values. Thus, the value 4 is shown in parentheses in the table above in the right column of the row for Level 4 with the frame size 1920×1080.
It is important to note that the current picture being decoded is not included in the computation of DPB fullness (unless the encoder has indicated for it to be stored for use as a reference for decoding other pictures or for delayed output timing). Thus, a decoder needs to actually have sufficient memory to handle (at least) one frame more than the maximum capacity of the DPB as calculated above.
Audio format
You can use the following table to select the target sound format based on
characteristics of sound source.
High quality formats
Starting with version 5.2, Total Recorder Professional Edition supports
high-quality formats. This includes high-quality PCM formats (up to 192kHz 24bit
and float mono and stereo), high-quality FLAC formats (up to 192kHz 24bit mono
and stereo), high-quality Windows Media Audio Lossless stereo formats (up to
96kHz 24bit), and the stereo formats of the Windows Media Audio Professional
codec.
This is a reference to compare the monophonic (not stereophonic)
audio quality and compression bitrates of audio coding formats available for WAV
files including PCM, ADPCM,
Microsoft GSM
06.10, CELP, SBC, Truespeech and MPEG Layer-3.
.wav "
extension.Technical information LAME#Recommended_encoder_settingsRecommended settings details[edit]
The default lowpass settings were not chosen at random; for general use, they are as high as they can be without putting quality at risk. Raising the the cutoff via command-line options is not recommended. See the high-frequency content in MP3s article for more info.
Recommended upload encoding settings |