【问题标题】:How to avoid color shift using FFmpeg libx264如何使用 FFmpeg libx264 避免颜色偏移
【发布时间】:2021-07-08 10:53:44
【问题描述】:

我想使用 ffmpeg 将一些素材转换为代理 H.264。使用以下命令,我得到了轻微的色偏:

ffmpeg -i /path/to/045_0054.MXF -map 0 -dn -c:v libx264 -preset slow -profile:v main -level:v 4.1 -coder 1 -pix_fmt yuv420p -crf 25 -vf "scale=1280:720:flags=lanczos" -movflags +faststart -colorspace 1 -color_primaries 1 -color_trc 1 -color_range 1 -brand mp42 -refs 1 -x264-params b-pyramid=0 -bf 2 -g 5 -y /path/to/045_0054.mp4

我怎样才能摆脱轻微的洋红色偏移?

mediainfo 打印以下关于源文件的信息:

General
Complete name                            : /path/to/045_0054.MXF
Format                                   : MXF
Format version                           : 1.3
Format profile                           : OP-1a
Format settings                          : Closed / Complete
File size                                : 180 MiB
Duration                                 : 14 s 720 ms
Overall bit rate mode                    : Variable
Overall bit rate                         : 102 Mb/s
Encoded date                             : 2021-02-19 13:13:15.000
Writing application                      : Sony Mem 2.00

Video
ID                                       : 2
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L5.1
Format settings                          : CABAC / 2 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 2 frames
Format settings, GOP                     : M=3, N=6
Format settings, wrapping mode           : Frame
Codec ID                                 : 0D01030102106001-0401020201314001
Duration                                 : 14 s 720 ms
Bit rate mode                            : Variable
Bit rate                                 : 97.8 Mb/s
Maximum bit rate                         : 100.0 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 25.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.472
Stream size                              : 172 MiB (95%)
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

【问题讨论】:

  • 尝试添加视频Bitstream Filter:-bsf:v h264_metadata=video_full_range_flag=0:colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1。使用mediainfo 验证目标颜色范围、颜色原色、传输特性、矩阵系数是否与输入相同。如果它解决了问题,请让我不。
  • 显示来自 ffmpeg 命令的完整日志。
  • 它没有帮助@Rotem这是一个非常非常轻微的洋红色转变。我确定 Adob​​e Media Encoder 不会出现这种情况。我试图发布 ffmpeg 日志,但 stackoverflow 不允许我发布,因为我的问题似乎代码太多……
  • 尝试使用合成模式重现问题。您可以使用以下命令构建合成视频(可用作您的输入):ffmpeg -y -r 25 -f lavfi -i testsrc=duration=10:size=3840x2160:rate=1 -vf setpts=N/25/TB -c:v libx264 -crf 17 -pix_fmt yuv420p -color_primaries bt709 -color_trc bt709 -colorspace bt709 -color_range 1 -bsf:v h264_metadata=video_full_range_flag=0:colour_primaries=1:transfer_characteristics=1:matrix_coefficients=1 vid.mxf

标签: ffmpeg libx264


【解决方案1】:

您需要使用 -vf scale=out_color_matrix=bt709 转换为 BT.709 矩阵,而不仅仅是使用 -colorspace bt709 标记输出。

所以在您的命令中只需更改为 -vf scale=1280:720:out_color_matrix=bt709:flags=lanczos

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 2013-09-14
    • 2021-05-10
    • 1970-01-01
    相关资源
    最近更新 更多