Opened 3 years ago

Last modified 3 years ago

#9038 new defect

kmsgrab: the parsing of `format_modifier` is problematic

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

Description

The parsing of format_modifier from command line is problematic.

In the parsing of those option with AV_OPT_TYPE_INT64 type, the value is firstly parsed into a double. However in this case format_modifier is a bit mask. For example, with my Intel iGPU I need I915_FORMAT_MOD_X_TILED, which is effectively (1 << 56) | 1.

The value is $2{56} + 1$, but as all we know the precision of double is only 52 bits. So $2{56} + 1$ is truncated to $2{56}$, which is wrong.

How to reproduce:

Add one line of code to output drm_format_modifier:

av_log(avctx, AV_LOG_DEBUG, "format modifier = %ld\n", ctx->drm_format_m   odifier);

Build and run ffmpeg, to grab the screen:

% ffmpeg -f kmsgrab -format_modifier 72057594037927937 -i - -vf 'hwdownload,format=bgr0' output.mp4 -loglevel 114514 2>&1 | tee log

Inspect the log:

% grep modifier log
Reading option '-format_modifier' ... matched as AVOption 'format_modifier' with argument '72057594037927937'.
[kmsgrab @ 0x654b40] format modifier = 72057594037927936

Inspect the video:

ffplay output.mp4

The result is a broken video, because of the incorrect format_modifier value.

Change History (2)

comment:1 by xry111, 3 years ago

Fix a paragraph, to satisify the trac format:

The value is 256 + 1, but as all we know the precision of double is only 52 bits. So 256 + 1 is truncated to 256, which is wrong.

comment:2 by Carl Eugen Hoyos, 3 years ago

Keywords: kmsgrab added
Note: See TracTickets for help on using tickets.