ffmpeg H265 到 H264 颜色关闭?

问题描述 投票:0回答:2

我希望将 H265 视频转换为 H264,并且质量损失尽可能小或没有。然而,在转换时,输出颜色会关闭,最明显的是红色变成橙色。一般来说,输出视频颜色较暗/饱和/较灰。

我相信this问题是相关的,所以是否可以将 color_range、color_space、color_transfer 和 color_primaries 标志添加到文件中,而无需再次重新编码整个内容?

命令:

ffmpeg -i input.mkv -c:v libx264 -crf 17 output.mp4

输入视频流:

{
  "index": 0,
  "codec_name": "hevc",
  "codec_long_name": "H.265 / HEVC (High Efficiency Video Coding)",
  "profile": "Main 10",
  "codec_type": "video",
  "codec_time_base": "1/24",
  "codec_tag_string": "[0][0][0][0]",
  "codec_tag": "0x0000",
  "width": 1920,
  "height": 1080,
  "coded_width": 1920,
  "coded_height": 1080,
  "closed_captions": 0,
  "has_b_frames": 2,
  "sample_aspect_ratio": "1:1",
  "display_aspect_ratio": "16:9",
  "pix_fmt": "yuv420p10le",
  "level": 120,
  "color_range": "tv",
  "color_space": "bt2020nc",
  "color_transfer": "smpte2084",
  "color_primaries": "bt2020",
  "refs": 1,
  "r_frame_rate": "24/1",
  "avg_frame_rate": "24/1",
  "time_base": "1/1000",
  "start_pts": 0,
  "start_time": "0.000000",
  "disposition": {
    "default": 1,
    "dub": 0,
    "original": 0,
    "comment": 0,
    "lyrics": 0,
    "karaoke": 0,
    "forced": 0,
    "hearing_impaired": 0,
    "visual_impaired": 0,
    "clean_effects": 0,
    "attached_pic": 0,
    "timed_thumbnails": 0
  },
  "tags": {
    "language": "eng",
    "BPS": "4421595",
    "DURATION": "00:41:46.417000000",
    "NUMBER_OF_FRAMES": "60154",
    "NUMBER_OF_BYTES": "1385295394",
    "_STATISTICS_WRITING_APP": "mkvmerge v62.0.0 ('Apollo') 64-bit",
    "_STATISTICS_TAGS": "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES"
  }
}

输出视频流:

{
  "index": 0,
  "codec_name": "h264",
  "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
  "profile": "High 10",
  "codec_type": "video",
  "codec_time_base": "1/48",
  "codec_tag_string": "avc1",
  "codec_tag": "0x31637661",
  "width": 1920,
  "height": 1080,
  "coded_width": 1920,
  "coded_height": 1088,
  "closed_captions": 0,
  "has_b_frames": 2,
  "sample_aspect_ratio": "1:1",
  "display_aspect_ratio": "16:9",
  "pix_fmt": "yuv420p10le",
  "level": 40,
  "chroma_location": "left",
  "refs": 1,
  "is_avc": "true",
  "nal_length_size": "4",
  "r_frame_rate": "24/1",
  "avg_frame_rate": "24/1",
  "time_base": "1/12288",
  "start_pts": 0,
  "start_time": "0.000000",
  "duration_ts": 30798848,
  "duration": "2506.416667",
  "bit_rate": "4073900",
  "bits_per_raw_sample": "10",
  "nb_frames": "60154",
  "disposition": {
    "default": 1,
    "dub": 0,
    "original": 0,
    "comment": 0,
    "lyrics": 0,
    "karaoke": 0,
    "forced": 0,
    "hearing_impaired": 0,
    "visual_impaired": 0,
    "clean_effects": 0,
    "attached_pic": 0,
    "timed_thumbnails": 0
  },
  "tags": {
    "language": "eng",
    "handler_name": "VideoHandler"
  }
}
ffmpeg video-processing
2个回答
2
投票

其中一些元数据也可能在比特流中发出信号,但您可以对视频进行重新混合(复制视频位,不重新编码),并使用如下命令设置 mp4 容器元数据:

ffmpeg -i output.mp4 -c:v copy -color_primaries bt2020 -color_range tv -colorspace bt2020nc -color_trc smpte2084 output_updated.mp4

此设置与您的输入视频设置相匹配。

参考 FFMPEG 文档(搜索

color_trc
即可找到正确的部分)


0
投票

编辑 h264/h265 视频流元数据(正式称为“VUI”)的另一种方法(可能更一致,因为它更“直接”)是使用比特流过滤器。

例如对于你的情况:

ffmpeg -i input.mp4 -c copy -bsf:v h264_metadata=colour_primaries=9:transfer_characteristics=16:matrix_coefficients=9 out.mp4

您必须使用整数作为 bsf 的参数,整数表及其各自的名称可以在 ITU-T H.273 建议书中找到。

© www.soinside.com 2019 - 2024. All rights reserved.