ffmpeg - 有没有办法使用各种 ffmpeg 命令来确定 ffmpeg 在我的系统中的性能是否最佳?
问题描述
我正在使用以下命令对文件(下面的媒体信息)进行编码:
ffmpeg -i AHomeMovie.mkv -map 0 -c copy -c:v libx264 -preset veryslow -crf 17 -c:a aac -b:a 256k -threads 8 resultdir/AHomeMovie.mkv
并在几分钟后或多或少地获得以下性能:
frame= 2036 fps=2.5 q=22.0 size= 87535kB time=00:01:25.25 bitrate=8411.2kbits/s speed=0.104x
对于配备 i7-8550U、16gb 内存、运行 Linux 的 UHD 显卡 620 的笔记本电脑来说,这是正常的性能吗?有没有办法使用各种 ffmpeg 命令找出 ffmpeg 是否以最佳方式执行?我现在知道它是商品硬件,但我只是想了解一下系统的性能。我知道我可以使用不同的 -preset 速度顺便说一句。
媒体信息:
General
Unique ID : 25145236523685421256398752247554522365 (0x14258745965823652446224452555874)
Complete name : AHomeMovie.mkv
Format : Matroska
Format version : Version 4
File size : 6.35 GiB
Duration : 22 min 47 s
Overall bit rate mode : Variable
Overall bit rate : 39.9 Mb/s
Movie name : A Home Movie
Encoded date : UTC 2020-09-10 22:10:12
Writing application : mkvmerge v42.0.0 ('Overtime') 64-bit
Writing library : libebml v1.3.10 + libmatroska v1.5.2
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, Reference frames : 4 frames
Codec ID : V_MPEG4/ISO/AVC
Duration : 22 min 45 s
Bit rate mode : Variable
Bit rate : 38.0 Mb/s
Maximum bit rate : 40.0 Mb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.764
Stream size : 6.04 GiB (95%)
Default : Yes
Forced : No
Audio #1
ID : 2
Format : FLAC
Format/Info : Free Lossless Audio Codec
Codec ID : A_FLAC
Duration : 22 min 45 s
Bit rate mode : Variable
Bit rate : 614 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 11.719 FPS (4096 SPF)
Bit depth : 16 bits
Compression mode : Lossless
Stream size : 100 MiB (2%)
Writing library : libFLAC 1.2.1 (UTC 2007-09-17)
Language : Japanese
Default : Yes
Forced : No
Audio #2
ID : 3
Format : FLAC
Format/Info : Free Lossless Audio Codec
Codec ID : A_FLAC
Duration : 22 min 46 s
Bit rate mode : Variable
Bit rate : 1 317 kb/s
Channel(s) : 2 channels
Channel layout : L R
Sampling rate : 48.0 kHz
Frame rate : 11.719 FPS (4096 SPF)
Bit depth : 24 bits
Compression mode : Lossless
Delay relative to video : 24 ms
Stream size : 215 MiB (3%)
Writing library : libFLAC 1.2.1 (UTC 2007-09-17)
Language : English
Default : No
Forced : No
解决方案
已经优化过了
您正在使用 libx264 进行编码。这是一个具有出色默认设置的编码器,因此无需进行太多优化。
唯一的性能建议是不要手动声明线程,它会自动为您的硬件使用最佳值。所以删除-threads 8
并让它选择。
基本建议是使用您有耐心的最慢和看起来可以接受-preset
的最高值。-crf
而已。请参阅FFmpeg 维基:H.264。
H.264 → H.264:为什么要重新编码?
最优化的过程是不重新编码。您正在引入generation loss。
硬件编码器
您也许可以使用QuickSync进行编码。它可能相对较快,并且可以为其他任务节省更多的 CPU,但在相同比特率的情况下,它看起来永远不会像 x264 一样好。
x265
目前尚不清楚您为什么要重新编码,但如果您的输入编码效率低下并且空间非常宝贵,您可以考虑使用 libx265 进行编码以输出 HEVC 格式。它比 x264 慢得多,但您可能会看到文件大小有所减小。
推荐阅读
- c++ - 推断外部类型的模板参数
- rust - 无法通过在引用上链接迭代器来构造 Vec
- java - 在 RecyclerView 中过滤
- spring-boot - 使用 RestTemplate POST 方法仅使用查询参数发布请求
- typescript - Typescript 有时不接受 Redux 容器传递的 props
- javascript - HTML AJAX 实时更新 PHP 变量,使用 ajax 计数动画
- postgresql - Postgres 批量插入不同的模式
- python - 如何在熊猫上将一列年份与一列月份字符串连接起来以创建一个新的日期时间列
- .net - vb.net 拆分字符串组
- python - 将上下文传递给 django 管理索引页面