intel / intel/media-driver

[Bug]: Cannot VAAPI encode 10-bit HEVC 4:2:2 on DG2 with constant bitrate from YUYV422 source

Open
#1,751 1 comment 0 reactions 1 assignee Assigned to @OttoYang View on GitHub
Encode HEVC
Dominant language
C
Stars
1.2k
Forks
383
Avg merge
8d 18h
Merged PRs (30d)
4

Description

### Which component impacted?

Encode

### Is it regression? Good in old configuration?

None

### What happened?

I'm trying to encode 10-bit HEVC 4:2:2 on DG2 from a YUYV422 source with CBR rate control. According to `vainfo -a` this should be possible:

```
$ vainfo -a
[…]
VAProfileHEVCMain422_10/VAEntrypointEncSliceLP
VAConfigAttribRTFormat : VA_RT_FORMAT_YUV420
VA_RT_FORMAT_YUV422
VA_RT_FORMAT_YUV444
VA_RT_FORMAT_YUV420_10
VA_RT_FORMAT_YUV422_10
VA_RT_FORMAT_YUV444_10
VA_RT_FORMAT_RGB32
VA_RT_FORMAT_RGB32_10
VA_RT_FORMAT_RGB32_10BPP
VA_RT_FORMAT_YUV420_10BPP
VAConfigAttribRateControl : VA_RC_CBR
VA_RC_VBR
VA_RC_VCM
VA_RC_CQP
VA_RC_ICQ
VA_RC_MB
VA_RC_QVBR
VA_RC_TCBRC
[…]
```

According to https://github.com/intel/media-driver/blob/master/docs/media_features.md#supported-encoding-input-format-and-max-resolution it seems the 10-bit HEVC encoder on DG2 can use the input pixel formats P010/Y210/Y410/RGB. So I will try to use `-vf 'hwupload,scale_vaapi=format=y210le'` with ffmpeg to convert from my source input YUYV422 to Y210LE in hardware.

Without any rate control settings ffmpeg defaults to ICQ and can do this successfully:

```
$ ffmpeg \
-v verbose \
-y \
-t 17ms \
-f rawvideo \
-pix_fmt yuyv422 \
-framerate 60 \
-video_size 1920x1080 \
-i ./input.yuyv422.rawvideo \
-vaapi_device /dev/dri/renderD128 \
-vf 'hwupload,scale_vaapi=format=y210le' \
-c:v hevc_vaapi \
/tmp/output.mkv
[AVHWDeviceContext @ 0x557a28192580] libva: VA-API version 1.20.0
[AVHWDeviceContext @ 0x557a28192580] libva: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x557a28192580] libva: Found init function __vaDriverInit_1_20
[AVHWDeviceContext @ 0x557a28192580] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x557a28192580] Initialised VAAPI connection: version 1.20
[AVHWDeviceContext @ 0x557a28192580] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 23.4.2 ().
[AVHWDeviceContext @ 0x557a28192580] Driver not found in known nonstandard list, using standard behaviour.
[rawvideo @ 0x557a28265880] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from './input.yuyv422.rawvideo':
Duration: 00:01:00.00, start: 0.000000, bitrate: 1990656 kb/s
Stream #0:0: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 1920x1080, 1990656 kb/s, 60 tbr, 60 tbn
[out#0/matroska @ 0x557a281c2480] No explicit maps, mapping streams automatically...
[vost#0:0/hevc_vaapi @ 0x557a28271700] Created video stream from input stream 0:0
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_vaapi))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0x557a28279540] w:1920 h:1080 pixfmt:yuyv422 tb:1/60 fr:60/1 sar:0/1
[hevc_vaapi @ 0x557a28271ac0] Using input frames context (format vaapi) with hevc_vaapi encoder.
[hevc_vaapi @ 0x557a28271ac0] Input surface format is y210le.
[hevc_vaapi @ 0x557a28271ac0] Using VAAPI profile VAProfileHEVCMain422_10 (24).
[hevc_vaapi @ 0x557a28271ac0] Using VAAPI entrypoint VAEntrypointEncSliceLP (8).
[hevc_vaapi @ 0x557a28271ac0] Using VAAPI render target format YUV422_10 (0x200).
[hevc_vaapi @ 0x557a28271ac0] Using CTU size 64x64, min CB size 8x8.
[hevc_vaapi @ 0x557a28271ac0] No quality level set; using default (25).
[hevc_vaapi @ 0x557a28271ac0] RC mode: ICQ.
[hevc_vaapi @ 0x557a28271ac0] RC quality: 25.
[hevc_vaapi @ 0x557a28271ac0] RC framerate: 60/1 (60.00 fps).
[hevc_vaapi @ 0x557a28271ac0] Driver does not support P-frames, replacing them with B-frames.
[hevc_vaapi @ 0x557a28271ac0] Using intra and B-frames (supported references: 3 / 3).
[hevc_vaapi @ 0x557a28271ac0] All wanted packed headers available (wanted 0xd, found 0x1f).
[hevc_vaapi @ 0x557a28271ac0] Using level 4.
Output #0, matroska, to '/tmp/output.mkv':
Metadata:
encoder : Lavf60.16.100
Stream #0:0: Video: hevc (Rext), 1 reference frame, vaapi(progressive), 1920x1080 (0x0), q=2-31, 60 fps, 1k tbn
Metadata:
encoder : Lavc60.31.102 hevc_vaapi
No more output streams to write to, finishing.=N/A bitrate=N/A speed=N/A
[vist#0:0/rawvideo @ 0x557a28270300] Decoder thread received EOF packet
[vist#0:0/rawvideo @ 0x557a28270300] Decoder returned EOF, finishing
[vist#0:0/rawvideo @ 0x557a28270300] Terminating decoder thread
[out#0/matroska @ 0x557a281c2480] All streams finished
[out#0/matroska @ 0x557a281c2480] Terminating muxer thread
[AVIOContext @ 0x557a28273e40] Statistics: 64527 bytes written, 0 seeks, 1 writeouts
[out#0/matroska @ 0x557a281c2480] Output file #0 (/tmp/output.mkv):
[out#0/matroska @ 0x557a281c2480] Output stream #0:0 (video): 1 frames encoded; 1 packets muxed (63808 bytes);
[out#0/matroska @ 0x557a281c2480] Total: 1 packets (63808 bytes) muxed
[out#0/matroska @ 0x557a281c2480] video:62kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.126818%
frame= 1 fps=0.0 q=-0.0 Lsize= 63kB time=00:00:00.00 bitrate=N/A speed= 0x
[in#0/rawvideo @ 0x557a281c0440] Terminating demuxer thread
[in#0/rawvideo @ 0x557a281c0440] Input file #0 (./input.yuyv422.rawvideo):
[in#0/rawvideo @ 0x557a281c0440] Input stream #0:0 (video): 4 packets read (16588800 bytes); 2 frames decoded; 0 decode errors;
[in#0/rawvideo @ 0x557a281c0440] Total: 4 packets (16588800 bytes) demuxed
[AVIOContext @ 0x557a281c0b40] Statistics: 16588800 bytes read, 0 seeks
```

I would like to use constant bitrate instead of ICQ, but as soon as I add the ffmpeg CBR parameters `-b:v 10M -maxrate 10M` to the above command I get this failure:

```
$ ffmpeg \
-v verbose \
-y \
-t 17ms \
-f rawvideo \
-pix_fmt yuyv422 \
-framerate 60 \
-video_size 1920x1080 \
-i ./input.yuyv422.rawvideo \
-vaapi_device /dev/dri/renderD128 \
-vf 'hwupload,scale_vaapi=format=y210le' \
-c:v hevc_vaapi \
-b:v 10M \
-maxrate 10M \
/tmp/output.mkv
[AVHWDeviceContext @ 0x5590d96c1640] libva: VA-API version 1.20.0
[AVHWDeviceContext @ 0x5590d96c1640] libva: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x5590d96c1640] libva: Found init function __vaDriverInit_1_20
[AVHWDeviceContext @ 0x5590d96c1640] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x5590d96c1640] Initialised VAAPI connection: version 1.20
[AVHWDeviceContext @ 0x5590d96c1640] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 23.4.2 ().
[AVHWDeviceContext @ 0x5590d96c1640] Driver not found in known nonstandard list, using standard behaviour.
[rawvideo @ 0x5590d96eff40] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from './input.yuyv422.rawvideo':
Duration: 00:01:00.00, start: 0.000000, bitrate: 1990656 kb/s
Stream #0:0: Video: rawvideo, 1 reference frame (YUY2 / 0x32595559), yuyv422, 1920x1080, 1990656 kb/s, 60 tbr, 60 tbn
[out#0/matroska @ 0x5590d979f980] No explicit maps, mapping streams automatically...
[vost#0:0/hevc_vaapi @ 0x5590d97a0a00] Created video stream from input stream 0:0
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> hevc (hevc_vaapi))
Press [q] to stop, [?] for help
[graph 0 input from stream 0:0 @ 0x5590d97a8900] w:1920 h:1080 pixfmt:yuyv422 tb:1/60 fr:60/1 sar:0/1
[hevc_vaapi @ 0x5590d97a0dc0] Using input frames context (format vaapi) with hevc_vaapi encoder.
[hevc_vaapi @ 0x5590d97a0dc0] Input surface format is y210le.
[hevc_vaapi @ 0x5590d97a0dc0] Using VAAPI profile VAProfileHEVCMain422_10 (24).
[hevc_vaapi @ 0x5590d97a0dc0] Using VAAPI entrypoint VAEntrypointEncSliceLP (8).
[hevc_vaapi @ 0x5590d97a0dc0] Using VAAPI render target format YUV422_10 (0x200).
[hevc_vaapi @ 0x5590d97a0dc0] Using CTU size 64x64, min CB size 8x8.
[hevc_vaapi @ 0x5590d97a0dc0] RC mode: CBR.
[hevc_vaapi @ 0x5590d97a0dc0] RC target: 100% of 10000000 bps over 1000 ms.
[hevc_vaapi @ 0x5590d97a0dc0] RC buffer: 10000000 bits, initial fullness 7500000 bits.
[hevc_vaapi @ 0x5590d97a0dc0] RC framerate: 60/1 (60.00 fps).
[hevc_vaapi @ 0x5590d97a0dc0] Driver does not support P-frames, replacing them with B-frames.
[hevc_vaapi @ 0x5590d97a0dc0] Using intra and B-frames (supported references: 3 / 3).
[hevc_vaapi @ 0x5590d97a0dc0] All wanted packed headers available (wanted 0xd, found 0x1f).
[hevc_vaapi @ 0x5590d97a0dc0] Failed to create encode pipeline configuration: 10 (attribute not supported).
[vost#0:0/hevc_vaapi @ 0x5590d97a0a00] Error while opening encoder - maybe incorrect parameters such as bit_rate, rate, width or height.
Error while filtering: Input/output error
[vist#0:0/rawvideo @ 0x5590d979f400] Decoder thread received EOF packet
[vist#0:0/rawvideo @ 0x5590d979f400] Decoder returned EOF, finishing
[vist#0:0/rawvideo @ 0x5590d979f400] Terminating decoder thread
[out#0/matroska @ 0x5590d979f980] Nothing was written into output file, because at least one of its streams received no packets.
frame= 0 fps=0.0 q=0.0 Lsize= 0kB time=N/A bitrate=N/A speed=N/A
[AVIOContext @ 0x5590d97a1f80] Statistics: 0 bytes written, 0 seeks, 0 writeouts
[in#0/rawvideo @ 0x5590d96ef480] Terminating demuxer thread
[in#0/rawvideo @ 0x5590d96ef480] Input file #0 (./input.yuyv422.rawvideo):
[in#0/rawvideo @ 0x5590d96ef480] Input stream #0:0 (video): 3 packets read (12441600 bytes); 1 frames decoded; 0 decode errors;
[in#0/rawvideo @ 0x5590d96ef480] Total: 3 packets (12441600 bytes) demuxed
[AVIOContext @ 0x5590d96ef8c0] Statistics: 12441600 bytes read, 0 seeks
Conversion failed!
```

Looking at the libva trace log I see this with the good (ICQ) command:

```
[65087.751680][ctx none]==========va_TraceCreateConfig
[65087.751680][ctx none] profile = 24, VAProfileHEVCMain422_10
[65087.751680][ctx none] entrypoint = 8, VAEntrypointEncSliceLP
[65087.751681][ctx none] num_attribs = 3
[65087.751684][ctx none] attrib_list[0].type = 0x00000000, VAConfigAttribRTFormat
[65087.751685][ctx none] attrib_list[0].value = 0x00000200
[65087.751685][ctx none] attrib_list[1].type = 0x00000005, VAConfigAttribRateControl
[65087.751686][ctx none] attrib_list[1].value = 0x00000040
[65087.751686][ctx none] attrib_list[2].type = 0x0000000a, VAConfigAttribEncPackedHeaders
[65087.751687][ctx none] attrib_list[2].value = 0x0000000d
[65087.751692][ctx none]=========vaCreateConfig ret = VA_STATUS_SUCCESS, success (no error)
```

and this with the bad (CBR) command:

```
[65061.546002][ctx none]==========va_TraceCreateConfig
[65061.546002][ctx none] profile = 24, VAProfileHEVCMain422_10
[65061.546002][ctx none] entrypoint = 8, VAEntrypointEncSliceLP
[65061.546003][ctx none] num_attribs = 3
[65061.546006][ctx none] attrib_list[0].type = 0x00000000, VAConfigAttribRTFormat
[65061.546006][ctx none] attrib_list[0].value = 0x00000200
[65061.546007][ctx none] attrib_list[1].type = 0x00000005, VAConfigAttribRateControl
[65061.546007][ctx none] attrib_list[1].value = 0x00000002
[65061.546008][ctx none] attrib_list[2].type = 0x0000000a, VAConfigAttribEncPackedHeaders
[65061.546008][ctx none] attrib_list[2].value = 0x0000000d
[65061.546013][ctx none]=========vaCreateConfig ret = VA_STATUS_ERROR_ATTR_NOT_SUPPORTED, attribute not supported
```

Full LIBVA_TRACE logs attached below.

Thanks!

### What's the usage scenario when you are seeing the problem?

Transcode for media delivery

### What impacted?

_No response_

### Debug Information

Debian unstable package versions:

`intel-gmmlib` `2.3.14+ds1-1`
`intel-media-va-driver-non-free` `23.4.2+ds1-1`
`libva-utils` `2.12.0+ds1-1`
`libva` `2.20.0-2`

GPU device:

`0c:00.0 VGA compatible controller [0300]: Intel Corporation DG2 [Arc A310] [8086:56a6] (rev 05)`

`vainfo -a` output:
[vainfo.log.txt](https://github.com/intel/media-driver/files/13756660/vainfo.log.txt)

"Good" LIBVA_TRACE log:
[libva_trace.GOOD.log.212311.thd-0x000666b0.txt](https://github.com/intel/media-driver/files/13756802/libva_trace.GOOD.log.212311.thd-0x000666b0.txt)

"Bad" LIBVA_TRACE log:
[libva_trace.BAD.log.212245.thd-0x00066695.txt](https://github.com/intel/media-driver/files/13756803/libva_trace.BAD.log.212245.thd-0x00066695.txt)

### Do you want to contribute a patch to fix the issue?

No.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.