Movie Bit Depth, Color range, Color Space Triplets, bitrates

Started by wywh, November 12, 2024, 12:46:28 PM

Previous topic - Next topic

wywh

I am trying to learn the dark art of movie (.mp4, .m4v, .mov) color management and encoding details. Different nomenclature in different apps does not make it easier. I understand that exiftool might not read track or stream metadata and apps like MediaInfo and Invisor (my favorite in macOS) are targeted for different uses. Some questions:

-> Q1: Is it possible to display movie bit depth with exiftool because it displays both 8bit and 10bit movies as:

[Track1]        BitDepth                        : 24
MediaInfo can display both 8bit and 10bit as well as Chroma subsampling which would be nice to see also in exiftool:

MediaInfo:
Bit depth                                : 8 bits
Bit depth                                : 10 bits
Chroma subsampling                       : 4:2:0

-> Q2: Could exiftool display VideoFullRangeFlag the same way as MediaInfo which displays "Color range" as "Limited or Full" (maybe without -n option)?

exiftool displays them as "VideoFullRangeFlag" = "0 or 1".

ffprobe displays them as "tv, mpeg" or "pc, jpeg".

Color Range "Limited" is ffmpeg option '-color_range 1', [tv, mpeg, (219*2^(n-8))]). It has more contrast than Color Range "Full" but might clip highlights (Limited 16-235 vs Full 0-255). BTW ffmpeg defaults to Color Range "Limited" with a warning "Color range not set for yuv420p. Using MPEG range".

Color Range "Full" is ffmpeg option '-color_range 2', [pc, jpeg, (2^n-1)]).

exiftool -a -G1 -s movie.mp4
[Track1]        VideoFullRangeFlag              : 0
[Track1]        VideoFullRangeFlag              : 1

MediaInfo:
Color range                              : Limited
Color range                              : Full

-> Q3: Could exiftool display those "Color Space Triplets" the same way as QuickTime Player which neatly reports them as "Code Points 5-1-6". For example PAL .dv re-encoded to .mp4 has deeper reds with "5-1-6" vs "Untagged".

QuickTime_triplets.png

FWIW it seems ffmpeg can losslessly write those triplets to an old movie so QuickTime Player displays and respects them. exiftool and MediaInfo display them (somehow MediaInfo displays also the old colour_primaries and matrix_coeffients as *_Original). But somehow ffprobe7 displays only the non-updated info.

exiftool and MediaInfo display those triplets about the same way:

exiftool -a -G1 -s movie.mp4
[Track1]        ColorPrimaries                  : BT.470 System B, G (historical)
[Track1]        TransferCharacteristics         : BT.709
[Track1]        MatrixCoefficients              : BT.601

MediaInfo:
Color primaries                          : BT.601 PAL
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.601

Check 'ffmpeg -h full' and there -color_primaries etc for details.

Q4: Could exiftool report separate average bitrates for video and audio like MediaInfo? It seems exiftool calculates Composite:AvgBitrate and that might be misleading if the audio is using some bloated codec like PCM and the user like me is considering whether to re-encode video or audio or both to some smaller codec.

exiftool:
[Composite]     AvgBitrate                      : 1.66 Mbps

MediaInfo:
General
Overall bit rate                         : 1 666 kb/s
Video
Bit rate                                 : 250 kb/s
Audio
Bit rate                                 : 1 411.2 kb/s
Format                                   : PCM
Format settings                          : Big / Signed
Codec ID                                 : twos

-> Q5: I have a few .mp4 movies where exiftool incorrectly displays AudioSampleRate in lpcm PCM audio as 1. With other PCM like sowt (little endian) and twos (big endian) and DV PCM audio it is displayed correctly. MediaInfo displays lpcm correctly and well as endianness:

[Track2]        AudioFormat                     : lpcm
[Track2]        AudioSampleRate                 : 1

[Track2]        AudioFormat                     : sowt
[Track2]        AudioSampleRate                 : 48000
[DV]            AudioSampleRate                 : 48000

MediaInfo:
Codec ID                                 : lpcm
Sampling rate                            : 48.0 kHz
Format                                   : PCM
Format settings                          : Little / Signed

- Matti

StarGeek

You might want to try and get some samples ready if Phil needs to see them.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Hi Matti,

Quote from: wywh on November 12, 2024, 12:46:28 PM-> Q1: Is it possible to display movie bit depth with exiftool because it displays both 8bit and 10bit movies as:

ExifTool is extracting the bit depth from the VisualSampleEntry structure of the video track.  I don't know where else this is stored.

Quote-> Q2: Could exiftool display VideoFullRangeFlag the same way as MediaInfo which displays "Color range" as "Limited or Full" (maybe without -n option)?

I will do this in 13.03.

Quote-> Q3: Could exiftool display those "Color Space Triplets" the same way as QuickTime Player

This could be done via a Composite tag, but I think you are the only one who would ever use this so I suggest you create a UserDefined tag for this.

QuoteQ4: Could exiftool report separate average bitrates for video and audio like MediaInfo? It seems exiftool calculates Composite:AvgBitrate and that might be misleading if the audio is using some bloated codec like PCM and the user like me is considering whether to re-encode video or audio or both to some smaller codec.

Calculating bitrates is a pain, and actually beyond the scope of ExifTool.  I have done it for a couple of formats and it brings me nothing but headaches because it is only an approximation.  Anything that decodes the media stream will always do better than ExifTool at this.

Quote-> Q5: I have a few .mp4 movies where exiftool incorrectly displays AudioSampleRate in lpcm PCM audio as 1. With other PCM like sowt (little endian) and twos (big endian) and DV PCM audio it is displayed correctly.

ExifTool displays the metadata that is written.  Unfortunately this isn't always accurate.  Again, anything parsing the media stream will be better for this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

wywh

Thanks for the reply. If it helps any attached are:

10bit_limited_5-1-6.mp4. 10-bit, Color Range Limited, 5-1-6, timecode.
08bit_full_1-1-1.mp4. 8-bit, Color Range Full, 1-1-1, timecode.

After some study it seems 8bit vs 10bit input does not matter because it is best to encode both as 10bit H.265 anyway. Even with 8bit input 10bit output has less banding in some difficult footage and the file sizes are about the same.

Also all my input seems to be better handled with Color Range Limited (only few input had Color Range Full but re-encoding them as Limited was better and somehow displayed the same as the original while using Full lost contrast).

...I was prompted to study these things when testing Apple's hevc_videotoolbox HW encoder which is 6-16x faster than the libx265 software encoder (both tested on Intel Mac mini 2018). The corresponding Apple audiotoolbox aac_at should be the best AAC encoder including libfdk-aac.

hevc_videotoolbox output compression options are more limited than libx265 so I might not re-do old libx265 output after all because its '-crf 18 -preset slow' compressed different input more efficiently (but VERY slowly) than bluntly applying '-c:v hevc_videotoolbox -b:v 5500K' (or more for better quality) to all input.

Those sample movies were encoded with:

ffmpeg7 -i input.mov -c:v hevc_videotoolbox -b:v 5500K -pix_fmt p010le -profile:v main10 -color_range 1 -color_primaries:v bt470bg -color_trc:v bt709 -colorspace:v smpte170m -timecode 00:00:00:00 -tag:v hvc1 -c:a aac_at -b:a 160k 10bit_limited_5-1-6.mp4
ffmpeg7 -i input.mov -c:v hevc_videotoolbox -b:v 5500K -pix_fmt yuv420p -profile:v main -color_range 2 -color_primaries:v bt709 -color_trc:v bt709 -colorspace:v bt709 -timecode 00:00:00:00 -tag:v hvc1 -c:a aac_at -b:a 160k 08bit_full_1-1-1.mp4
 
- Matti

wywh

Quote from: Phil Harvey on November 12, 2024, 02:02:45 PM
Quote-> Q2: Could exiftool display VideoFullRangeFlag the same way as MediaInfo which displays "Color range" as "Limited or Full" (maybe without -n option)?

I will do this in 13.03.

Wow that was fast, thanks.

exiftool -a -G1 -s -VideoFullRangeFlag .
======== ./08bit_full_1-1-1.mp4
[Track1]        VideoFullRangeFlag              : Full
======== ./10bit_limited_5-1-6.mp4
[Track1]        VideoFullRangeFlag              : Limited

exiftool -a -G1 -s -n -VideoFullRangeFlag .
======== ./08bit_full_1-1-1.mp4
[Track1]        VideoFullRangeFlag              : 1
======== ./10bit_limited_5-1-6.mp4
[Track1]        VideoFullRangeFlag              : 0

- Matti