mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Screenshot With JPEG XL Format Results in 16 Bit Depth Even the Original Video is 10 Bit Depth

Open Jiang10086 opened this issue 7 months ago • 16 comments

mpv Information

mpv v0.40.0-119-g1d1535ff9 Copyright © 2000-2025 mpv/MPlayer/mplayer2 projects
 built on May 23 2025 00:13:48
libplacebo version: v7.351.0 (v7.351.0-dirty)
FFmpeg version: N-119684-g670089304
FFmpeg library versions:
   libavcodec      62.3.101
   libavdevice     62.0.100
   libavfilter     11.0.100
   libavformat     62.0.102
   libavutil       60.3.100
   libswresample   6.0.100
   libswscale      9.0.100

Other Information

- Windows version:Windows 11 24H2 (10.0.26100.1150)
- Source of mpv:[https://sourceforge.net/projects/mpv-player-windows/files/64bit-v3/](https://sourceforge.net/projects/mpv-player-windows/files/64bit-v3/)

Reproduction Steps

Set screenshot format to JPEG XL (screenshot-format=jxl in mpv.conf) and then screenshot a 10 bit video with the ‘s’ key

Expected Behavior

Screenshot image is 10 bit depth.

Actual Behavior

Screenshot image is 16 bit depth.

Log File

output.txt

Sample Files

[Nekomoe kissaten&LoliHouse] Zatsu Tabi - 08 [WebRip 1080p HEVC-10bit AAC ASSx2].mkv @00_00_04.jxl.zip

I carefully read all instruction and confirm that I did the following:

  • [x] I tested with the latest mpv version to validate that the issue is not already fixed.
  • [x] I provided all required information including system and mpv version.
  • [x] I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • [x] I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • [x] I attached the full, untruncated log file.
  • [x] I attached the backtrace in the case of a crash.

Jiang10086 avatar May 30 '25 05:05 Jiang10086

I guess #16161 should have fixed exactly this. @Traneptora any idea?

sfan5 avatar May 30 '25 09:05 sfan5

But he didn't enable screenshot-sw ?

hooke007 avatar May 30 '25 10:05 hooke007

I guess #16161 should have fixed exactly this. @Traneptora any idea?

I try to download the binary you mentioned and run .\mpv "video_path.mkv" --screenshot-format=jxl, then press "s", it shows can't take screenshot in JPEG XL format:

● Video  --vid=1                   (hevc 1920x1080 23.976 fps) [default]
● Audio  --aid=1  --alang=ja       'Stereo' (aac 2ch 44100 Hz) [default]
● Subs   --sid=1  --slang=zh-Hans  '简体中文' (ass) [default]
○ Subs   --sid=2  --slang=zh-Hant  '繁體中文' (ass)
AO: [wasapi] 48000Hz stereo 2ch float
VO: [gpu] 1920x1080 yuv420p10
Audio device underrun detected.
[screenshot] Could not open libavcodec encoder for saving images
[screenshot] Error writing file 'mpv-shot0001.jxl'!
Error writing screenshot!
[screenshot] Could not open libavcodec encoder for saving images
[screenshot] Error writing file 'mpv-shot0002.jxl'!
Error writing screenshot!
(Paused) AV: 00:06:28 / 00:23:40 (27%) A-V:  0.000 Dropped: 2
Exiting... (Quit)

Jiang10086 avatar May 30 '25 10:05 Jiang10086

But he didn't enable screenshot-sw ?

I have try set "screenshot-sw=yes" in mpv.conf after your reply, but the screenshot remains 16 bits.

Jiang10086 avatar May 30 '25 10:05 Jiang10086

I try to download the binary you mentioned and run [...]

Our CI builds do not come with libjxl. But there's no need to test this either way since you are on revision 1d1535ff9, which already includes this fix.

sfan5 avatar May 30 '25 10:05 sfan5

But he didn't enable screenshot-sw ?

I have try set "screenshot-sw=yes" in mpv.conf after your reply, but the screenshot remains 16 bits.

How are you determining that the screenshot is 16-bit?

Traneptora avatar Jun 02 '25 13:06 Traneptora

I guess #16161 should have fixed exactly this. @Traneptora any idea?

My best guess is they're on libjxl 0.7 which doesn't include the bit depth header API. FFmpeg has it guarded by an #ifdef . They also need to be on at least ffmpeg/ffmpeg@fb823161a8e3dfc864a7bd83a9b968f4912c5b1d for that functionality to be in avcodec.

Traneptora avatar Jun 02 '25 13:06 Traneptora

https://github.com/shinchiro/mpv-winbuild-cmake/blob/master/packages/libjxl.cmake

Shin's build is always latest.

hooke007 avatar Jun 02 '25 13:06 hooke007

May be a regression, #16161 was supposed to fix exactly this. I'll investigate after work today. It isn't an issue with JPEG XL however as PNG also supports bit depth (via sBIT).

Traneptora avatar Jun 02 '25 14:06 Traneptora

But he didn't enable screenshot-sw ?

I have try set "screenshot-sw=yes" in mpv.conf after your reply, but the screenshot remains 16 bits.

How are you determining that the screenshot is 16-bit?

I have installed ImageMagick and run magick identify "Path\To\That\Image.jxl" and it shows JXL 1920x1080 1920x1080+0+0 16-bit sRGB 175106B 0.001u 0:00.001

Jiang10086 avatar Jun 03 '25 15:06 Jiang10086

I don't know if ImageMagick reads the bit depth header. You can try jxlinfo -v and it'll tell you, although I think it is actually 16-bit. I'll investigate when I get a bit more time.

Traneptora avatar Jun 03 '25 15:06 Traneptora

I don't know if ImageMagick reads the bit depth header. You can try jxlinfo -v and it'll tell you, although I think it is actually 16-bit. I'll investigate when I get a bit more time.

I have run it and it shows:

box: type: "JXL " size: 12, contents size: 4
JPEG XL file format container (ISO/IEC 18181-2)
box: type: "ftyp" size: 20, contents size: 12
box: type: "jxll" size: 9, contents size: 1
box: type: "jxlc" size: 175065, contents size: 175057
JPEG XL image, 1920x1080, lossy, 16-bit RGB+Alpha
num_color_channels: 3
num_extra_channels: 1
extra channel 0:
  type: Alpha
  bits_per_sample: 16
  alpha_premultiplied: 0 (Non-premultiplied)
have_preview: 0
have_animation: 0
Intrinsic dimensions: 1920x1080
Orientation: 1 (Normal)
Color space: RGB, D65, sRGB primaries, sRGB transfer function, rendering intent: Relative

And the alpha channel is unnecessary.

Jiang10086 avatar Jun 03 '25 16:06 Jiang10086

I don't know if ImageMagick reads the bit depth header. You can try jxlinfo -v and it'll tell you, although I think it is actually 16-bit. I'll investigate when I get a bit more time.

Another issue is that I have set screenshot-jxl-distance=0.0, which according to the manual means lossless compression, but jxlinfo shows the screenshot is lossy. Seems like there are lots to do with MPV’s screenshot with JPEG XL format.

Jiang10086 avatar Jun 03 '25 16:06 Jiang10086

Last time I checked, there's no actual 10bit support (gbrp10le) in FFmpeg libjxl ~(And there's no RGB30 in FFmpeg! It's libjxl wrapper currently only supports packed formats not planar, if this pattern is to be followed there must be a RGB30 format to begin with.)~ OK there's x2rgb10?? What's that? https://github.com/FFmpeg/FFmpeg/blob/167e343bbe75515a80db8ee72ffa0c607c944a00/libavcodec/libjxlenc.c#L690-L698

L4cache avatar Jun 04 '25 07:06 L4cache

I don't know if ImageMagick reads the bit depth header. You can try jxlinfo -v and it'll tell you, although I think it is actually 16-bit. I'll investigate when I get a bit more time.

Another issue is that I have set screenshot-jxl-distance=0.0, which according to the manual means lossless compression, but jxlinfo shows the screenshot is lossy. Seems like there are lots to do with MPV’s screenshot with JPEG XL format.

I can reproduce the 16-bit issue, but not the lossy issue. When I try I use mpv --no-config --screenshot-format=jxl --screenshot-jxl-distance=0.0 --screenshot-sw=yes test.mkv. What did you try?

Traneptora avatar Jun 04 '25 16:06 Traneptora

I don't know if ImageMagick reads the bit depth header. You can try jxlinfo -v and it'll tell you, although I think it is actually 16-bit. I'll investigate when I get a bit more time.

Another issue is that I have set screenshot-jxl-distance=0.0, which according to the manual means lossless compression, but jxlinfo shows the screenshot is lossy. Seems like there are lots to do with MPV’s screenshot with JPEG XL format.

I can reproduce the 16-bit issue, but not the lossy issue. When I try I use mpv --no-config --screenshot-format=jxl --screenshot-jxl-distance=0.0 --screenshot-sw=yes test.mkv. What did you try?

I am sorry that I try screenshot again and it turns out a lossless compression, maybe the picture I used in jxlinfo is taken before I set screenshot-jxl-distance=0.0. Just forget about the lossy part.

Jiang10086 avatar Jun 04 '25 18:06 Jiang10086