Opened 7 months ago

Last modified 4 months ago

#9146 open defect

ATC SEI of HLG (18) should overwrite color_trc from VUI in mp4, just like in ts and mkv

Reported by: a1q123456 Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: hevc
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

If a ts file contains an alternative_transfer_characteristics SEI, it seems like ffmpeg will sets color_trc to value provided by ATC-SEI rather than vui_parameters.transfer_characteristics. But if the file is mp4 format, color_trc is the value provided by vui_parameters. Maybe
ffmpeg should give same color_trc whether the file is mp4 or ts?

How to reproduce:

% ffmpeg -i <whatever-video.mp4> -color_trc bt2020-10 -color_primaries bt2020 -colorspace bt2020nc -vf "format=yuv420p10le" -t 00:00:01 -c:v hevc -x265-params "atc-sei=18" hevc-hdr.mp4

% ffmpeg -i hevc-hdr.mp4 -c copy hevc-hdr.ts

% ffmpeg -i hevc-hdr.ts
  ...
      Stream #0:0[0x100]: Video: hevc (Main 10) (HEVC / 0x43564548), yuv420p10le(tv, bt2020nc/bt2020/arib-std-b67), 1920x1080, 29.97 fps, 29.97 tbr, 90k tbn, 29.97 tbc
                                                                                                     ^^^^^^^^^^^^^
  ...


% ffmpeg -i hevc-hdr.mp4
  ...
  Duration: 00:00:01.00, start: 0.000000, bitrate: 4115 kb/s
    Stream #0:0(und): Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv, bt2020nc/bt2020/bt2020-10, progressive), 1920x1080, 4087 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
                                                                                                 ^^^^^^^^^
  ...
% mediainfo hevc-hdr.ts
...
Transfer characteristics                 : HLG / BT.2020 (10-bit)
...
ffmpeg version: 4.3.1

Attachments (2)

hevc-hdr.mp4 (502.9 KB ) - added by a1q123456 7 months ago.
hevc-hdr.ts (520.1 KB ) - added by a1q123456 7 months ago.

Download all attachments as: .zip

Change History (11)

by a1q123456, 7 months ago

Attachment: hevc-hdr.mp4 added

by a1q123456, 7 months ago

Attachment: hevc-hdr.ts added

comment:1 by Balling, 7 months ago

Are we even conformant to ETSI TS 101 154, v2.5.1 (2019-01) that does this magic stuff?

"For other broadcasts systems, an EOTF VUI value of 14, as per ETSI TS 101 154, v2.5.1 (2019-01) (and optionally 1, 6, or 15) may provide the best base-layer SDR backward-compatible HLG signaling when used with the alternative_transfer_characteristic SEI message, at every random access point, with the preferred_transfer_function set to 18, as per ETSI TS 101 154, v2.5.1 (2019-01). Note that BT Report 2390 defines a bridge point for translation of PQ and HLG at a luminance of 1,000 cd/m2. The recommended chroma sample location type VUI is 0 (center-left)"

Last edited 7 months ago by Balling (previous) (diff)

comment:2 by Carl Eugen Hoyos, 7 months ago

Keywords: hlg color_trc removed
Version: 4.2unspecified

Are you reporting an issue with the mpegts muxer?

in reply to:  2 comment:3 by Balling, 7 months ago

Replying to cehoyos:

Are you reporting an issue with the mpegts muxer?

That is not TS issue per se. That is VUI problem, but it's FUTURE as of now... Together with ambient light SEI. See ITU-T H.274.

https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-H.274-202008-I!!PDF-E&type=items

Last edited 7 months ago by Balling (previous) (diff)

in reply to:  2 comment:4 by a1q123456, 7 months ago

Replying to cehoyos:

Are you reporting an issue with the mpegts muxer?

I don't think it is an issue with mpegts muxer, the code overrides avctx->color_trc is from function export_stream_params(HEVCContext *s, const HEVCSPS *sps) in hevcdec.c. Maybe just remove the following codes from hevcdec.c?

     if (s->sei.alternative_transfer.present &&
        av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
        s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
        avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
    }
Last edited 7 months ago by a1q123456 (previous) (diff)

comment:5 by Balling, 5 months ago

Status: newopen

the code overrides avctx->color_trc is from function

You must override it. HLG is signalled in ATC, VUI signals SDR, because HLG has SDR layer that should be used to present SDR. That is the point. Also ATC SEI is really only allowed in TS, i.e. in DVB-X2 applications.

You do understand that -color_trc bt2020-10 is SDR, the same as in BT.709 OETF? That means BT.1886 EOTF must be used to present it.

One need to check whether HLG ATC SEI is even present in mp4 file. Will do.

Also SEI_rbsp_stop_one_bit : Missing is very bad, it means that ffmpeg is not comformant when writing zero bytes in SEI. WTF.

Last edited 5 months ago by Balling (previous) (diff)

comment:6 by Balling, 5 months ago

Summary: ffmpeg gives different value of color_trc if video stream contains an atc sei for mp4 and ts fileATC SEI of HLG (18) should overwrite color_trc from VUI in mp4, just like in ts and mkv

And this was just a bug in Mediainfo!!! HAHA.
SEI_rbsp_stop_one_bit on hevc-hdr.ts is only printed on android, WTF. Also, mp4 has ATC SEI.

mpv nevertheless recognizes both as HLG, so no problem there. Nice.

Also I see a problem in mkv too, but that is a common problem that transfer_characteristics_Original is used somehow by ffmpeg, why BTW?

Last edited 4 months ago by Balling (previous) (diff)

in reply to:  6 comment:7 by a1q123456, 5 months ago

Replying to Balling:

And this was just a bug in Mediainfo!!! HAHA.
SEI_rbsp_stop_one_bit on hevc-hdr.mp4 is only printed on android, WTF. Also, mp4 has ATC SEI.

mpv nevertheless recognizes both as HLG, so no problem there. Nice.

Also I see a problem in mkv too, but that is a common problem that transfer_characteristics_Original is used somehow by ffmpeg, why BTW?

Oh, I see, if we override the color_trc by ATC, we'll have no chance to find out the original value, and if we don't override the color_trc by ATC, it'll break some rule. So I think maybe add a new field to AVCodecContext to indicate the original value can solve this problem?

in reply to:  6 comment:8 by a1q123456, 5 months ago

.

Last edited 5 months ago by a1q123456 (previous) (diff)

comment:9 by Balling, 4 months ago

Issue #8610 is related. Apparenly that was not enough for mp4 and mkv.

Last edited 4 months ago by Balling (previous) (diff)
Note: See TracTickets for help on using tickets.