ppy / osu-framework

A game framework written with osu! in mind.
MIT License
1.67k stars 419 forks source link

Prefer HDTV / Rec. 709 colorspace for videos with HD resolution and unspecified colorspace #6403

Open frenzibyte opened 4 weeks ago

frenzibyte commented 4 weeks ago

This can be reproduced on any video with HD resolution (width >= 704 or height >= 576 precisely if comparing with QuickTime Player) and no colorspace tag specified.

Turns out, when a colorspace tag is unspecified, regular media players like VLC and QuickTime Player pick a colorspace based on the dimensions of the video. In the case of VLC, if the height is higher than 576, then it picks the HD / BT.709 colorspace, otherwise it picks the SD / BT.601. QuickTime Player (upon trial and error) does the same with the addition that it also considers any width higher than 704 as well. I've arbitrarily rolled with QuickTime Player's conditions, as it is a default built-in media player.

As an off-topic note, QuickTime Player also interestingly uses a unique colorspace for videos with the specific resolution 704x576, I'm not sure what that is and I don't think it's worth caring about at all.

master: CleanShot 2024-10-29 at 00 31 01

PR: CleanShot 2024-10-29 at 00 30 36

The first row represents the actual videos rendered with o!f, the second row represents the expected color output using reference screenshots.

Screenshots taken with QuickTime Player (specifically by right-clicking the video and pressing "Copy Image", then pasted to GIMP and exported).

The sample HD video was produced using FFmpeg with the following command line:

ffmpeg -i h264.mp4 -s 1024x576 -c:a copy h264-hd.mp4
frenzibyte commented 4 weeks ago

Further testing with Windows (on Media Player, mpv, and VLC) shows that this might actually be a macOS-specific behaviour...not sure if it marks this PR as invalid.

Susko3 commented 4 weeks ago

From your testing, what color space do programs on windows use?

frenzibyte commented 4 weeks ago

On all the programs mentioned above for Windows, they use the SDTV / Rec. 601 colorspace regardless of the video resolution (confirmed it by recreating the video with a colorspace specified, one with rec601 and one with rec709, and then cross-comparing in Windows alongside the colorspace-unspecified videos we have already).

In fact, Windows Media Player for some very odd reason literally uses the opposite colorspace for each given colorspace (displays bright green for rec709 and dimmed green for rec601, opposite to all other media players in Windows and macOS). When the video has unspecified colorspace, it always renders the video with bright green regardless of resolution, that matches how it renders any video with rec709 colorspace, but the actual colours its using matches that of rec601 colorspace......I don't know.