-preset
主要用来调节编码速度和质量的平衡,虽然libx264和h264_nvenc都有此参数,但是该参数的可选项却不完全相同:
preset是通过设置一系列编码参数来实现调节编码速度和质量的效果的,
e.g. -preset faster
是做了如下设置 --no-mixed-refs --rc-lookahead 20 --ref 2 --subme 4 --weightp 1
详细信息见文章最后一章的x264 encoding options。
libx264 有10个选项
速度由快到慢,速度越慢,质量越好,压缩比越大;默认是medium。
h264_nvenc 有11个选项
默认是medium。
-profile
用来设置画质级别, 默认级别为 high:
H.264 Baseline profile和Main profile都是针对8位样本数据、4:2:0格式(YUV)的视频序列。在相同配置情况下,High profile(HP)可以比Main profile(MP)降低10%的码率。 根据应用领域的不同,Baseline profile多应用于实时通信领域,Main profile多应用于流媒体领域,High profile则多应用于广电和存储领域。
除了这三项之外,high还衍生出了 high10、 high422、 high444、high444p 等参数。。。。。
该参数覆盖的用户设置项见文章最后一章的x264 encoding options。
-level
-crf
-cq
crf可以根据视频的运动和静止动态的进行压缩。
与crf、cq、qp、vbr、cbr相关的解析可以参考:Understanding Rate Control Modes (x264, x265, vpx) 和 CRF Guide (Constant Rate Factor in x264 and x265)
libx264
-crf d Select the quality for constant quality mode (from -1 to FLT_MAX) (default -1)
h264_nvenc
-cq Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0)
-qp
类似于
crf
,但相同比特率下质量更差,建议使用crf
libx264
Constant quantization parameter rate control method (from -1 to INT_MAX) (default -1)
h264_nvenc
Constant quantization parameter rate control method (from -1 to 51) (default -1)
-tune
为特定类型的源或情况调整设置
主要参数有
查看指令
ffmpeg -h encoder=libx264
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-opencl --enable-videotoolbox
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Encoder libx264 [libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10]:
General capabilities: delay threads
Threading capabilities: auto
Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p nv12 nv16 nv21 yuv420p10le yuv422p10le yuv444p10le nv20le
libx264 AVOptions:
-preset E..V..... Set the encoding preset (cf. x264 --fullhelp) (default "medium")
-tune E..V..... Tune the encoding params (cf. x264 --fullhelp)
-profile E..V..... Set profile restrictions (cf. x264 --fullhelp)
-fastfirstpass E..V..... Use fast settings when encoding first pass (default true)
-level E..V..... Specify level (as defined by Annex A)
-passlogfile E..V..... Filename for 2 pass stats
-wpredp E..V..... Weighted prediction for P-frames
-a53cc E..V..... Use A53 Closed Captions (if available) (default true)
-x264opts E..V..... x264 options
-crf E..V..... Select the quality for constant quality mode (from -1 to FLT_MAX) (default -1)
-crf_max E..V..... In CRF mode, prevents VBV from lowering quality beyond this point. (from -1 to FLT_MAX) (default -1)
-qp E..V..... Constant quantization parameter rate control method (from -1 to INT_MAX) (default -1)
-aq-mode E..V..... AQ method (from -1 to INT_MAX) (default -1)
none E..V.....
variance E..V..... Variance AQ (complexity mask)
autovariance E..V..... Auto-variance AQ
autovariance-biased E..V..... Auto-variance AQ with bias to dark scenes
-aq-strength E..V..... AQ strength. Reduces blocking and blurring in flat and textured areas. (from -1 to FLT_MAX) (default -1)
-psy E..V..... Use psychovisual optimizations. (default auto)
-psy-rd E..V..... Strength of psychovisual optimization, in : format.
-rc-lookahead E..V..... Number of frames to look ahead for frametype and ratecontrol (from -1 to INT_MAX) (default -1)
-weightb E..V..... Weighted prediction for B-frames. (default auto)
-weightp E..V..... Weighted prediction analysis method. (from -1 to INT_MAX) (default -1)
none E..V.....
simple E..V.....
smart E..V.....
-ssim E..V..... Calculate and print SSIM stats. (default auto)
-intra-refresh E..V..... Use Periodic Intra Refresh instead of IDR frames. (default auto)
-bluray-compat E..V..... Bluray compatibility workarounds. (default auto)
-b-bias E..V..... Influences how often B-frames are used (from INT_MIN to INT_MAX) (default INT_MIN)
-b-pyramid E..V..... Keep some B-frames as references. (from -1 to INT_MAX) (default -1)
none E..V.....
strict E..V..... Strictly hierarchical pyramid
normal E..V..... Non-strict (not Blu-ray compatible)
-mixed-refs E..V..... One reference per partition, as opposed to one reference per macroblock (default auto)
-8x8dct E..V..... High profile 8x8 transform. (default auto)
-fast-pskip E..V..... (default auto)
-aud E..V..... Use access unit delimiters. (default auto)
-mbtree E..V..... Use macroblock tree ratecontrol. (default auto)
-deblock E..V..... Loop filter parameters, in form.
-cplxblur E..V..... Reduce fluctuations in QP (before curve compression) (from -1 to FLT_MAX) (default -1)
-partitions E..V..... A comma-separated list of partitions to consider. Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all
-direct-pred E..V..... Direct MV prediction mode (from -1 to INT_MAX) (default -1)
none E..V.....
spatial E..V.....
temporal E..V.....
auto E..V.....
-slice-max-size E..V..... Limit the size of each slice in bytes (from -1 to INT_MAX) (default -1)
-stats E..V..... Filename for 2 pass stats
-nal-hrd E..V..... Signal HRD information (requires vbv-bufsize; cbr not allowed in .mp4) (from -1 to INT_MAX) (default -1)
none E..V.....
vbr E..V.....
cbr E..V.....
-avcintra-class E..V..... AVC-Intra class 50/100/200 (from -1 to 200) (default -1)
-me_method E..V..... Set motion estimation method (from -1 to 4) (default -1)
dia E..V.....
hex E..V.....
umh E..V.....
esa E..V.....
tesa E..V.....
-motion-est E..V..... Set motion estimation method (from -1 to 4) (default -1)
dia E..V.....
hex E..V.....
umh E..V.....
esa E..V.....
tesa E..V.....
-forced-idr E..V..... If forcing keyframes, force them as IDR frames. (default false)
-coder E..V..... Coder type (from -1 to 1) (default default)
default E..V.....
cavlc E..V.....
cabac E..V.....
vlc E..V.....
ac E..V.....
-b_strategy E..V..... Strategy to choose between I/P/B-frames (from -1 to 2) (default -1)
-chromaoffset E..V..... QP difference between chroma and luma (from INT_MIN to INT_MAX) (default -1)
-sc_threshold E..V..... Scene change threshold (from INT_MIN to INT_MAX) (default -1)
-noise_reduction E..V..... Noise reduction (from INT_MIN to INT_MAX) (default -1)
-x264-params E..V..... Override the x264 configuration using a :-separated list of key=value parameters
查看指令
ffmpeg -h encoder=h264_nvenc
ffmpeg version 3.3.8 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags='-I/root/ffmpeg_build/include -I/usr/local/cuda/include' --extra-ldflags='-L/root/ffmpeg_build/lib -L/usr/local/cuda/lib64' --extra-libs=-lpthread --extra-libs=-lm --bindir=/root/bin --enable-gpl --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-cuda --enable-cuvid --enable-nvenc --enable-libnpp
libavutil 55. 58.100 / 55. 58.100
libavcodec 57. 89.100 / 57. 89.100
libavformat 57. 71.100 / 57. 71.100
libavdevice 57. 6.100 / 57. 6.100
libavfilter 6. 82.100 / 6. 82.100
libswscale 4. 6.100 / 4. 6.100
libswresample 2. 7.100 / 2. 7.100
libpostproc 54. 5.100 / 54. 5.100
Encoder h264_nvenc [NVIDIA NVENC H.264 encoder]:
General capabilities: delay
Threading capabilities: none
Supported pixel formats: yuv420p nv12 p010le yuv444p yuv444p16le bgr0 rgb0 cuda
h264_nvenc AVOptions:
-preset E..V.... Set the encoding preset (from 0 to 11) (default medium)
default E..V....
slow E..V.... hq 2 passes
medium E..V.... hq 1 pass
fast E..V.... hp 1 pass
hp E..V....
hq E..V....
bd E..V....
ll E..V.... low latency
llhq E..V.... low latency hq
llhp E..V.... low latency hp
lossless E..V....
losslesshp E..V....
-profile E..V.... Set the encoding profile (from 0 to 3) (default main)
baseline E..V....
main E..V....
high E..V....
high444p E..V....
-level E..V.... Set the encoding level restriction (from 0 to 51) (default auto)
auto E..V....
1 E..V....
1.0 E..V....
1b E..V....
1.0b E..V....
1.1 E..V....
1.2 E..V....
1.3 E..V....
2 E..V....
2.0 E..V....
2.1 E..V....
2.2 E..V....
3 E..V....
3.0 E..V....
3.1 E..V....
3.2 E..V....
4 E..V....
4.0 E..V....
4.1 E..V....
4.2 E..V....
5 E..V....
5.0 E..V....
5.1 E..V....
-rc E..V.... Override the preset rate-control (from -1 to INT_MAX) (default -1)
constqp E..V.... Constant QP mode
vbr E..V.... Variable bitrate mode
cbr E..V.... Constant bitrate mode
vbr_minqp E..V.... Variable bitrate mode with MinQP
ll_2pass_quality E..V.... Multi-pass optimized for image quality (only for low-latency presets)
ll_2pass_size E..V.... Multi-pass optimized for constant frame size (only for low-latency presets)
vbr_2pass E..V.... Multi-pass variable bitrate mode
-rc-lookahead E..V.... Number of frames to look ahead for rate-control (from -1 to INT_MAX) (default -1)
-surfaces E..V.... Number of concurrent surfaces (from 0 to 64) (default 32)
-cbr E..V.... Use cbr encoding mode (default false)
-2pass E..V.... Use 2pass encoding mode (default auto)
-gpu E..V.... Selects which NVENC capable GPU to use. First GPU is 0, second is 1, and so on. (from -2 to INT_MAX) (default any)
any E..V.... Pick the first device available
list E..V.... List the available devices
-delay E..V.... Delay frame output by the given amount of frames (from 0 to INT_MAX) (default INT_MAX)
-no-scenecut E..V.... When lookahead is enabled, set this to 1 to disable adaptive I-frame insertion at scene cuts (default false)
-forced-idr E..V.... If forcing keyframes, force them as IDR frames. (default false)
-b_adapt E..V.... When lookahead is enabled, set this to 0 to disable adaptive B-frame decision (default true)
-spatial-aq E..V.... set to 1 to enable Spatial AQ (default false)
-temporal-aq E..V.... set to 1 to enable Temporal AQ (default false)
-zerolatency E..V.... Set 1 to indicate zero latency operation (no reordering delay) (default false)
-nonref_p E..V.... Set this to 1 to enable automatic insertion of non-reference P-frames (default false)
-strict_gop E..V.... Set 1 to minimize GOP-to-GOP rate fluctuations (default false)
-aq-strength E..V.... When Spatial AQ is enabled, this field is used to specify AQ strength. AQ strength scale is from 1 (low) - 15 (aggressive) (from 1 to 15) (default 8)
-cq E..V.... Set target quality level (0 to 51, 0 means automatic) for constant quality mode in VBR rate control (from 0 to 51) (default 0)
-aud E..V.... Use access unit delimiters (default false)
-bluray-compat E..V.... Bluray compatibility workarounds (default false)
-init_qpP E..V.... Initial QP value for P frame (from -1 to 51) (default -1)
-init_qpB E..V.... Initial QP value for B frame (from -1 to 51) (default -1)
-init_qpI E..V.... Initial QP value for I frame (from -1 to 51) (default -1)
-qp E..V.... Constant quantization parameter rate control method (from -1 to 51) (default -1)
查看指令
x264 --fullhelp
x264 core:155 r2917 0a84d98
Syntax: x264 [options] -o outfile infile
Infile can be raw (in which case resolution is required),
or YUV4MPEG (*.y4m),
or Avisynth if compiled with support (yes).
or libav* formats if compiled with lavf support (no) or ffms support (no).
Outfile type is selected by filename:
.264 -> Raw bytestream
.mkv -> Matroska
.flv -> Flash Video
.mp4 -> MP4 if compiled with GPAC or L-SMASH support (no)
Output bit depth: 8/10
.
Options:
-h, --help List basic options
--longhelp List more options
--fullhelp List all options
Example usage:
Constant quality mode:
x264 --crf 24 -o