Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting RC_Quality has no effect when encoding VP9 with RC_MODE ICQ on DG2 #776

Open
danielsmakandra opened this issue Nov 30, 2023 · 2 comments

Comments

@danielsmakandra
Copy link

danielsmakandra commented Nov 30, 2023

I try to encode videos to the VP9 codec while using the ICQ rc_mode with ffmpeg and vaapi directly.

Hardware

Intel Arc A380 on Archlinux VM

Software

  • ffmpeg 2:6.1-1
  • libva 2.20.0
  • Intel iHD driver 23.3.5

Problem

The RC quality setting isn't respected by libva

Running
sudo ffmpeg -an -v verbose -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i ~/videos/V2023CW0079.mp4 -c:v vp9_vaapi -global_quality 100 /tmp/V2023CW0079_icq_100.webm
Sets the RC_Quality setting correctly as indicated by ffmpeg's output

Running with quality setting 1 also sets the RC_Quality correctly:
sudo ffmpeg -an -v verbose -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i ~/videos/V2023CW0079.mp4 -c:v vp9_vaapi -global_quality 1 /tmp/V2023CW0079_icq_1.webm

But both commands produce output files with almost the same filesize and similar quality:

4,0M	/tmp/V2023CW0079_icq_100.webm
4,1M	/tmp/V2023CW0079_icq_1.webm

As a check to see if I got the ffmpeg parameters wrong I tried the same command with the h264 encoder. With RC_Quality set to 1 and 100. It produces files with vastly different filesizes:

3,5M	/tmp/V2023CW0079_icq_100.mp4
81M	/tmp/V2023CW0079_icq_1.mp4

Because of this I suspect that the Bug is within libva.

Logs

with ffmpeg -global_quality 100:

ffmpeg version n6.1 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 13.2.1 (GCC) 20230801
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
  libavutil      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
[h264 @ 0x55822cfa8f80] Reinit context to 1920x1088, pix_fmt: yuv420p
Selecting decoder 'h264' because of requested hwaccel method vaapi
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/daniel/videos/V2023CW0079.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2023-09-04T15:21:56.000000Z
  Duration: 00:01:05.68, start: 0.000000, bitrate: 14616 kb/s
  Stream #0:0[0x1](eng): Video: h264 (Main), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, progressive, left), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 14291 kb/s, 25 fps, 25 tbr, 25k tbn (default)
    Metadata:
      creation_time   : 2023-09-04T15:21:56.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2023-09-04T15:21:56.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      vendor_id       : [0][0][0][0]
[out#0/webm @ 0x55822cfab300] No explicit maps, mapping streams automatically...
[vost#0:0/vp9_vaapi @ 0x55822cfcf800] Created video stream from input stream 0:0
[AVHWDeviceContext @ 0x55822d1322c0] libva: VA-API version 1.20.0
[AVHWDeviceContext @ 0x55822d1322c0] libva: Trying to open /usr/lib/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x55822d1322c0] libva: Found init function __vaDriverInit_1_20
[AVHWDeviceContext @ 0x55822d1322c0] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x55822d1322c0] Initialised VAAPI connection: version 1.20
[AVHWDeviceContext @ 0x55822d1322c0] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 23.3.5 ().
[AVHWDeviceContext @ 0x55822d1322c0] Driver not found in known nonstandard list, using standard behaviour.
File '/tmp/V2023CW0079_icq_100.webm' already exists. Overwrite? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> vp9 (vp9_vaapi))
Press [q] to stop, [?] for help
[h264 @ 0x55822d121340] Reinit context to 1920x1088, pix_fmt: vaapi
[graph 0 input from stream 0:0 @ 0x55822d33fb80] w:1920 h:1080 pixfmt:vaapi tb:1/25000 fr:25/1 sar:1/1
[vp9_vaapi @ 0x55822cffdf40] Using input frames context (format vaapi) with vp9_vaapi encoder.
[vp9_vaapi @ 0x55822cffdf40] Input surface format is nv12.
[vp9_vaapi @ 0x55822cffdf40] Using VAAPI profile VAProfileVP9Profile0 (19).
[vp9_vaapi @ 0x55822cffdf40] Using VAAPI entrypoint VAEntrypointEncSliceLP (8).
[vp9_vaapi @ 0x55822cffdf40] Using VAAPI render target format YUV420 (0x1).
[vp9_vaapi @ 0x55822cffdf40] RC mode: ICQ.
[vp9_vaapi @ 0x55822cffdf40] RC quality: 100.
[vp9_vaapi @ 0x55822cffdf40] RC framerate: 25/1 (25.00 fps).
[vp9_vaapi @ 0x55822cffdf40] Driver does not report any additional prediction constraints.
[vp9_vaapi @ 0x55822cffdf40] Using intra and P-frames (supported references: 3 / 0).
[vp9_vaapi @ 0x55822cffdf40] All wanted packed headers available (wanted 0, found 0x10).
Output #0, webm, to '/tmp/V2023CW0079_icq_100.webm':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    encoder         : Lavf60.16.100
  Stream #0:0(eng): Video: vp9 (Profile 0), 1 reference frame, vaapi(tv, bt709, progressive, left), 1920x1080 (0x0) [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 1k tbn (default)
    Metadata:
      creation_time   : 2023-09-04T15:21:56.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : Lavc60.31.102 vp9_vaapi
Automatically inserted bitstream filter 'vp9_superframe'; args=''eed=N/A    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x55822cfa8040] EOF while reading input7.9kbits/s speed=6.75x    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x55822cfa8040] Terminating demuxer thread
[vist#0:0/h264 @ 0x55822cfaabc0] Decoder thread received EOF packet
[vist#0:0/h264 @ 0x55822cfaabc0] Decoder returned EOF, finishing
[vist#0:0/h264 @ 0x55822cfaabc0] Terminating decoder thread
No more output streams to write to, finishing.
[out#0/webm @ 0x55822cfab300] All streams finished
[out#0/webm @ 0x55822cfab300] Terminating muxer thread
[AVIOContext @ 0x55822d0b9fc0] Statistics: 4174581 bytes written, 2 seeks, 17 writeouts
[out#0/webm @ 0x55822cfab300] Output file #0 (/tmp/V2023CW0079_icq_100.webm):
[out#0/webm @ 0x55822cfab300]   Output stream #0:0 (video): 1642 frames encoded; 1642 packets muxed (4161507 bytes); 
[out#0/webm @ 0x55822cfab300]   Total: 1642 packets (4161507 bytes) muxed
[out#0/webm @ 0x55822cfab300] video:4064kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.299315%
frame= 1642 fps=169 q=-0.0 Lsize=    4076kB time=00:01:05.64 bitrate= 508.7kbits/s speed=6.77x    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x55822cfa8040] Input file #0 (/home/daniel/videos/V2023CW0079.mp4):
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x55822cfa8040]   Input stream #0:0 (video): 1642 packets read (117336895 bytes); 1642 frames decoded; 0 decode errors; 
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x55822cfa8040]   Total: 1642 packets (117336895 bytes) demuxed
[AVIOContext @ 0x55822cfb0840] Statistics: 120004418 bytes read, 0 seeks

With ffmpeg -global_quality 1:

ffmpeg version n6.1 Copyright (c) 2000-2023 the FFmpeg developers
 built with gcc 13.2.1 (GCC) 20230801
 configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
 libavutil      58. 29.100 / 58. 29.100
 libavcodec     60. 31.102 / 60. 31.102
 libavformat    60. 16.100 / 60. 16.100
 libavdevice    60.  3.100 / 60.  3.100
 libavfilter     9. 12.100 /  9. 12.100
 libswscale      7.  5.100 /  7.  5.100
 libswresample   4. 12.100 /  4. 12.100
 libpostproc    57.  3.100 / 57.  3.100
[h264 @ 0x561b429b4f80] Reinit context to 1920x1088, pix_fmt: yuv420p
Selecting decoder 'h264' because of requested hwaccel method vaapi
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/daniel/videos/V2023CW0079.mp4':
 Metadata:
   major_brand     : mp42
   minor_version   : 0
   compatible_brands: mp42mp41
   creation_time   : 2023-09-04T15:21:56.000000Z
 Duration: 00:01:05.68, start: 0.000000, bitrate: 14616 kb/s
 Stream #0:0[0x1](eng): Video: h264 (Main), 1 reference frame (avc1 / 0x31637661), yuv420p(tv, bt709, progressive, left), 1920x1080 (1920x1088) [SAR 1:1 DAR 16:9], 14291 kb/s, 25 fps, 25 tbr, 25k tbn (default)
   Metadata:
     creation_time   : 2023-09-04T15:21:56.000000Z
     handler_name    : ?Mainconcept Video Media Handler
     vendor_id       : [0][0][0][0]
     encoder         : AVC Coding
 Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
   Metadata:
     creation_time   : 2023-09-04T15:21:56.000000Z
     handler_name    : #Mainconcept MP4 Sound Media Handler
     vendor_id       : [0][0][0][0]
[out#0/webm @ 0x561b429b7300] No explicit maps, mapping streams automatically...
[vost#0:0/vp9_vaapi @ 0x561b429db800] Created video stream from input stream 0:0
[AVHWDeviceContext @ 0x561b42b3e2c0] libva: VA-API version 1.20.0
[AVHWDeviceContext @ 0x561b42b3e2c0] libva: Trying to open /usr/lib/dri/iHD_drv_video.so
[AVHWDeviceContext @ 0x561b42b3e2c0] libva: Found init function __vaDriverInit_1_20
[AVHWDeviceContext @ 0x561b42b3e2c0] libva: va_openDriver() returns 0
[AVHWDeviceContext @ 0x561b42b3e2c0] Initialised VAAPI connection: version 1.20
[AVHWDeviceContext @ 0x561b42b3e2c0] VAAPI driver: Intel iHD driver for Intel(R) Gen Graphics - 23.3.5 ().
[AVHWDeviceContext @ 0x561b42b3e2c0] Driver not found in known nonstandard list, using standard behaviour.
File '/tmp/V2023CW0079_icq_1.webm' already exists. Overwrite? [y/N] y
Stream mapping:
 Stream #0:0 -> #0:0 (h264 (native) -> vp9 (vp9_vaapi))
Press [q] to stop, [?] for help
[h264 @ 0x561b42b2d340] Reinit context to 1920x1088, pix_fmt: vaapi
[graph 0 input from stream 0:0 @ 0x561b42d4bb80] w:1920 h:1080 pixfmt:vaapi tb:1/25000 fr:25/1 sar:1/1
[vp9_vaapi @ 0x561b42a09f40] Using input frames context (format vaapi) with vp9_vaapi encoder.
[vp9_vaapi @ 0x561b42a09f40] Input surface format is nv12.
[vp9_vaapi @ 0x561b42a09f40] Using VAAPI profile VAProfileVP9Profile0 (19).
[vp9_vaapi @ 0x561b42a09f40] Using VAAPI entrypoint VAEntrypointEncSliceLP (8).
[vp9_vaapi @ 0x561b42a09f40] Using VAAPI render target format YUV420 (0x1).
[vp9_vaapi @ 0x561b42a09f40] RC mode: ICQ.
[vp9_vaapi @ 0x561b42a09f40] RC quality: 1.
[vp9_vaapi @ 0x561b42a09f40] RC framerate: 25/1 (25.00 fps).
[vp9_vaapi @ 0x561b42a09f40] Driver does not report any additional prediction constraints.
[vp9_vaapi @ 0x561b42a09f40] Using intra and P-frames (supported references: 3 / 0).
[vp9_vaapi @ 0x561b42a09f40] All wanted packed headers available (wanted 0, found 0x10).
Output #0, webm, to '/tmp/V2023CW0079_icq_1.webm':
 Metadata:
   major_brand     : mp42
   minor_version   : 0
   compatible_brands: mp42mp41
   encoder         : Lavf60.16.100
 Stream #0:0(eng): Video: vp9 (Profile 0), 1 reference frame, vaapi(tv, bt709, progressive, left), 1920x1080 (0x0) [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 1k tbn (default)
   Metadata:
     creation_time   : 2023-09-04T15:21:56.000000Z
     handler_name    : ?Mainconcept Video Media Handler
     vendor_id       : [0][0][0][0]
     encoder         : Lavc60.31.102 vp9_vaapi
Automatically inserted bitstream filter 'vp9_superframe'; args=''eed=N/A    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x561b429b4040] EOF while reading input7.9kbits/s speed=6.75x    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x561b429b4040] Terminating demuxer thread
[vist#0:0/h264 @ 0x561b429b6bc0] Decoder thread received EOF packet
[vist#0:0/h264 @ 0x561b429b6bc0] Decoder returned EOF, finishing
[vist#0:0/h264 @ 0x561b429b6bc0] Terminating decoder thread
No more output streams to write to, finishing.
[out#0/webm @ 0x561b429b7300] All streams finished
[out#0/webm @ 0x561b429b7300] Terminating muxer thread
[AVIOContext @ 0x561b42ac5fc0] Statistics: 4218012 bytes written, 2 seeks, 18 writeouts
[out#0/webm @ 0x561b429b7300] Output file #0 (/tmp/V2023CW0079_icq_1.webm):
[out#0/webm @ 0x561b429b7300]   Output stream #0:0 (video): 1642 frames encoded; 1642 packets muxed (4204938 bytes); 
[out#0/webm @ 0x561b429b7300]   Total: 1642 packets (4204938 bytes) muxed
[out#0/webm @ 0x561b429b7300] video:4106kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.296223%
frame= 1642 fps=169 q=-0.0 Lsize=    4119kB time=00:01:05.64 bitrate= 514.0kbits/s speed=6.76x    
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x561b429b4040] Input file #0 (/home/daniel/videos/V2023CW0079.mp4):
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x561b429b4040]   Input stream #0:0 (video): 1642 packets read (117336895 bytes); 1642 frames decoded; 0 decode errors; 
[in#0/mov,mp4,m4a,3gp,3g2,mj2 @ 0x561b429b4040]   Total: 1642 packets (117336895 bytes) demuxed
[AVIOContext @ 0x561b429bc840] Statistics: 120004418 bytes read, 0 seeks
@XinfengZhang
Copy link
Contributor

it should related driver BRC algorithm, and from the comments in the driver issue, it is a feature request , and not fully implemented.

@danielsmakandra
Copy link
Author

it should related driver BRC algorithm, and from the comments in the driver issue, it is a feature request , and not fully implemented.

Thanks for your reply, could you point me to the mentioned issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants