GPU VMAF: decode the AV1 test encode on the A580 too #6

Merged
khyretos merged 1 commit from perf/gpu-vmaf-decode into main 2026-11-02 07:15:09 +01:00
Owner

Requested by Kees

What

With GPU VMAF and the qsv encoder, the AV1 test encode is decoded by the A580 (av1_qsv, hwdownload to p010le) before libvmaf_sycl, instead of dav1d on the CPU. The lossless reference stays a CPU read (cheap), and the one-time CPU self-check keeps CPU decoding, so a GPU decode difference would be caught.

Tests

  • Unit tests green (new: QSV decode only on the GPU command, first input only).
  • 20 s 1080p samples, 8-bit and 10-bit, two quality levels: identical scores to the last digit, 14-15.5 s CPU instead of 17.4-18.6 s.
  • Full quality search on a real 10-bit HEVC episode: identical trials, q24, ratio 0.336; CPU 542 -> 468 s; self-check gpu 98.630833 = cpu 98.630833.

🤖 Generated with Claude Code

<!-- claude-projects-attribution: {"github_login":"Khyretos"} --> _Requested by **Kees**_ ## What With GPU VMAF and the qsv encoder, the AV1 test encode is decoded by the A580 (av1_qsv, hwdownload to p010le) before libvmaf_sycl, instead of dav1d on the CPU. The lossless reference stays a CPU read (cheap), and the one-time CPU self-check keeps CPU decoding, so a GPU decode difference would be caught. ## Tests - Unit tests green (new: QSV decode only on the GPU command, first input only). - 20 s 1080p samples, 8-bit and 10-bit, two quality levels: identical scores to the last digit, 14-15.5 s CPU instead of 17.4-18.6 s. - Full quality search on a real 10-bit HEVC episode: identical trials, q24, ratio 0.336; CPU 542 -> 468 s; self-check gpu 98.630833 = cpu 98.630833. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Real episode (10-bit HEVC 1080p): identical trials, q24, ratio 0.336; CPU per
quality search 542 -> 468 s. The CPU self-check keeps decoding on the CPU.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Collaborator

Title

GPU VMAF: decode the AV1 test encode on the A580 too


PR Type

Enhancement


Description

  • Enable QSV GPU decoding for AV1 test encodes in VMAF checks.

  • Achieve identical scores with ~20% less CPU per quality search.

  • Add unit tests to verify QSV decode flags and CPU fallback.


Diagram Walkthrough

flowchart LR
  A["Quality Search"] -->|"AV1 Encode"| B["VMAF Check"]
  B -->|"GPU Available"| C["QSV Decode + Score"]
  B -->|"No GPU"| D["CPU Decode + Score"]
  C -.->|"Identical Score"| D

File Walkthrough

Relevant files
Enhancement
rx_media.py
Add QSV device support and hardware decode flags to VMAF command
builder

app/rx_media.py

  • Added qsv_device parameter to vmaf_cmd function.
  • Modified FFmpeg filter graph to include QSV hardware download for the
    encoded stream when specified.
  • Updated command arguments to initialize QSV device and use QSV
    hardware acceleration for decoding.
+8/-2     
rx_search.py
Integrate QSV device selection into GPU VMAF scoring logic

app/rx_search.py

  • Pass qsv_device configuration to vmaf_cmd when using GPU scoring.
  • Determine QSV device path based on encoder type (qsv) and hardware
    decode setting.
+2/-1     
Tests
test_gpu_vmaf.py
Add unit tests for QSV decode command generation and CPU fallback

tests/test_gpu_vmaf.py

  • Added test_cmd_qsv_decode to verify QSV-specific flags are present in
    the command.
  • Confirmed that CPU-only mode excludes hardware acceleration flags.
+8/-0     
Documentation
CHANGELOG.md
Update changelog with QSV decode feature and performance metrics

CHANGELOG.md

  • Documented the new QSV decoding feature for AV1 test encodes.
  • Highlighted performance improvement of approximately 20% less CPU
    usage.
+2/-0     

## Title <!-- pr-agent:describe:persistent --> GPU VMAF: decode the AV1 test encode on the A580 too ___ ### **PR Type** Enhancement ___ ### **Description** - Enable QSV GPU decoding for AV1 test encodes in VMAF checks. - Achieve identical scores with ~20% less CPU per quality search. - Add unit tests to verify QSV decode flags and CPU fallback. ___ ### Diagram Walkthrough ```mermaid flowchart LR A["Quality Search"] -->|"AV1 Encode"| B["VMAF Check"] B -->|"GPU Available"| C["QSV Decode + Score"] B -->|"No GPU"| D["CPU Decode + Score"] C -.->|"Identical Score"| D ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>rx_media.py</strong><dd><code>Add QSV device support and hardware decode flags to VMAF command </code><br><code>builder</code></dd></summary> <hr> app/rx_media.py <ul><li>Added <code>qsv_device</code> parameter to <code>vmaf_cmd</code> function.<br> <li> Modified FFmpeg filter graph to include QSV hardware download for the <br>encoded stream when specified.<br> <li> Updated command arguments to initialize QSV device and use QSV <br>hardware acceleration for decoding.</ul> </details> </td> <td><a href="https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/app/rx_media.py">+8/-2</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>rx_search.py</strong><dd><code>Integrate QSV device selection into GPU VMAF scoring logic</code></dd></summary> <hr> app/rx_search.py <ul><li>Pass <code>qsv_device</code> configuration to <code>vmaf_cmd</code> when using GPU scoring.<br> <li> Determine QSV device path based on encoder type (<code>qsv</code>) and hardware <br>decode setting.</ul> </details> </td> <td><a href="https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/app/rx_search.py">+2/-1</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>test_gpu_vmaf.py</strong><dd><code>Add unit tests for QSV decode command generation and CPU fallback</code></dd></summary> <hr> tests/test_gpu_vmaf.py <ul><li>Added <code>test_cmd_qsv_decode</code> to verify QSV-specific flags are present in <br>the command.<br> <li> Confirmed that CPU-only mode excludes hardware acceleration flags.</ul> </details> </td> <td><a href="https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/tests/test_gpu_vmaf.py">+8/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Documentation</strong></td><td><table> <tr> <td> <details> <summary><strong>CHANGELOG.md</strong><dd><code>Update changelog with QSV decode feature and performance metrics</code></dd></summary> <hr> CHANGELOG.md <ul><li>Documented the new QSV decoding feature for AV1 test encodes.<br> <li> Highlighted performance improvement of approximately 20% less CPU <br>usage.</ul> </details> </td> <td><a href="https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/CHANGELOG.md">+2/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
kompas-review left a comment

3 finding(s) as line comments; the review comment lists all of them.

3 finding(s) as line comments; the review comment lists all of them.
@ -445,6 +449,8 @@ def vmaf_cmd(encoded: str, ref: str, threads: int, log: Optional[str] = None, he
VMAF_GPU_FFMPEG if gpu else "ffmpeg",
"-nostdin",
"-nostats", # the score is logged at info level; progress lines only buried the real error
] + (["-init_hw_device", f"qsv=hw:{qsv_device}", "-hwaccel", "qsv", "-hwaccel_output_format", "qsv",
Collaborator

Incorrect FFmpeg Argument Order · KK-e57fe08f18 · low

The added arguments for QSV hardware acceleration (-init_hw_device, -hwaccel, etc.) are inserted before the first input file (-i). While this is generally correct for hwaccel, the test at line 54 of tests/test_gpu_vmaf.py asserts that the index of -hwaccel is less than -i. However, the actual command construction adds these flags after the vmaf_cmd function call arguments but before the inputs. The logic seems sound for the first input, but if multiple inputs were ever passed, only the first would be affected by the hwaccel chain defined here, potentially causing issues with the reference stream if it were also expected to be hardware decoded (though the diff shows it is not).

Reply not an issue, false positive or won't fix to dismiss it; it is then not reported again.

**Incorrect FFmpeg Argument Order** · `KK-e57fe08f18` · low The added arguments for QSV hardware acceleration (-init_hw_device, -hwaccel, etc.) are inserted before the first input file (-i). While this is generally correct for hwaccel, the test at line 54 of tests/test_gpu_vmaf.py asserts that the index of -hwaccel is less than -i. However, the actual command construction adds these flags after the vmaf_cmd function call arguments but before the inputs. The logic seems sound for the first input, but if multiple inputs were ever passed, only the first would be affected by the hwaccel chain defined here, potentially causing issues with the reference stream if it were also expected to be hardware decoded (though the diff shows it is not). <sub>Reply `not an issue`, `false positive` or `won't fix` to dismiss it; it is then not reported again.</sub> <!-- kk-finding:e57fe08f18 -->
@ -225,3 +225,3 @@
if (cfg.get("vmaf_gpu", "auto") != "off" and _gpu_vmaf["ok"] is not False and (height or 0) >= GPU_MIN_HEIGHT
and os.path.exists(rx_media.VMAF_GPU_FFMPEG)):
rc, _, err = run(rx_media.vmaf_cmd(enc, ref, threads, log, height, gpu=True))
qsv = cfg.get("device") if cfg.get("encoder") == "qsv" and cfg.get("hw_decode", True) else None
Collaborator

Logic Error in QSV Device Selection · KK-42ec94f1e3 · medium

The code checks if the encoder is "qsv" to decide whether to use QSV for decoding. However, the PR description and tests specifically target AV1 encoding ("av1_qsv"). If a user configures a different qsv encoder (e.g., h264_qsv), this logic would incorrectly attempt to decode that stream using QSV hardware acceleration, which may not be supported or intended for all codecs.

Reply not an issue, false positive or won't fix to dismiss it; it is then not reported again.

**Logic Error in QSV Device Selection** · `KK-42ec94f1e3` · medium The code checks if the encoder is "qsv" to decide whether to use QSV for decoding. However, the PR description and tests specifically target AV1 encoding ("av1_qsv"). If a user configures a different qsv encoder (e.g., h264_qsv), this logic would incorrectly attempt to decode that stream using QSV hardware acceleration, which may not be supported or intended for all codecs. <sub>Reply `not an issue`, `false positive` or `won't fix` to dismiss it; it is then not reported again.</sub> <!-- kk-finding:42ec94f1e3 -->
@ -51,1 +51,4 @@
def test_cmd_qsv_decode(self):
c = rx_media.vmaf_cmd("/w/e.mkv", "/w/r.mkv", 3, None, 1080, gpu=True, qsv_device="/dev/dri/renderD128")
self.assertLess(c.index("-hwaccel"), c.index("-i")) # only the encode (first input) is decoded on the GPU
Collaborator

Test Assertion Reliability · KK-4e0d72164a · low

The test at line 54 asserts that the index of "-hwaccel" is less than the index of "-i". This relies on the specific order of arguments generated by vmaf_cmd. If future changes alter the argument insertion point or if the ffmpeg version behaves differently regarding argument parsing order, this assertion might fail even if the functionality works correctly. It is better to verify the presence of the flags relative to the specific input stream they are meant to affect rather than global index comparison.

Reply not an issue, false positive or won't fix to dismiss it; it is then not reported again.

**Test Assertion Reliability** · `KK-4e0d72164a` · low The test at line 54 asserts that the index of "-hwaccel" is less than the index of "-i". This relies on the specific order of arguments generated by vmaf_cmd. If future changes alter the argument insertion point or if the ffmpeg version behaves differently regarding argument parsing order, this assertion might fail even if the functionality works correctly. It is better to verify the presence of the flags relative to the specific input stream they are meant to affect rather than global index comparison. <sub>Reply `not an issue`, `false positive` or `won't fix` to dismiss it; it is then not reported again.</sub> <!-- kk-finding:4e0d72164a -->
Collaborator

PR Reviewer Guide 🔍

📋 Focus areas: 🔴 3 open · ✅ 0 handled. Every push re-checks them; a handled area moves to Resolved findings at the bottom.

🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Error in QSV Device Selection

The code checks if the encoder is "qsv" to decide whether to use QSV for decoding. However, the PR description and tests specifically target AV1 encoding ("av1_qsv"). If a user configures a different qsv encoder (e.g., h264_qsv), this logic would incorrectly attempt to decode that stream using QSV hardware acceleration, which may not be supported or intended for all codecs.

qsv = cfg.get("device") if cfg.get("encoder") == "qsv" and cfg.get("hw_decode", True) else None
Incorrect FFmpeg Argument Order

The added arguments for QSV hardware acceleration (-init_hw_device, -hwaccel, etc.) are inserted before the first input file (-i). While this is generally correct for hwaccel, the test at line 54 of tests/test_gpu_vmaf.py asserts that the index of -hwaccel is less than -i. However, the actual command construction adds these flags after the vmaf_cmd function call arguments but before the inputs. The logic seems sound for the first input, but if multiple inputs were ever passed, only the first would be affected by the hwaccel chain defined here, potentially causing issues with the reference stream if it were also expected to be hardware decoded (though the diff shows it is not).

] + (["-init_hw_device", f"qsv=hw:{qsv_device}", "-hwaccel", "qsv", "-hwaccel_output_format", "qsv",
      "-c:v", "av1_qsv"] if hw_in else []) + [
Test Assertion Reliability

The test at line 54 asserts that the index of "-hwaccel" is less than the index of "-i". This relies on the specific order of arguments generated by vmaf_cmd. If future changes alter the argument insertion point or if the ffmpeg version behaves differently regarding argument parsing order, this assertion might fail even if the functionality works correctly. It is better to verify the presence of the flags relative to the specific input stream they are meant to affect rather than global index comparison.

self.assertLess(c.index("-hwaccel"), c.index("-i"))  # only the encode (first input) is decoded on the GPU

🗂️ Finding ids (reply with the id and not an issue, false positive or won't fix to dismiss one; it is then not reported again):

  • KK-42ec94f1e3 app/rx_search.py:227
  • KK-e57fe08f18 app/rx_media.py:452
  • KK-4e0d72164a tests/test_gpu_vmaf.py:54
## PR Reviewer Guide 🔍 <!-- pr-agent:review:full --> 📋 **Focus areas:** 🔴 3 open · ✅ 0 handled. Every push re-checks them; a handled area moves to *Resolved findings* at the bottom. <table> <tr><td>🧪&nbsp;<strong>No relevant tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/app/rx_search.py#L227-L227'><strong>Logic Error in QSV Device Selection</strong></a> The code checks if the encoder is "qsv" to decide whether to use QSV for decoding. However, the PR description and tests specifically target AV1 encoding ("av1_qsv"). If a user configures a different qsv encoder (e.g., h264_qsv), this logic would incorrectly attempt to decode that stream using QSV hardware acceleration, which may not be supported or intended for all codecs. </summary> ```python qsv = cfg.get("device") if cfg.get("encoder") == "qsv" and cfg.get("hw_decode", True) else None ``` </details> <details><summary><a href='https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/app/rx_media.py#L452-L453'><strong>Incorrect FFmpeg Argument Order</strong></a> The added arguments for QSV hardware acceleration (-init_hw_device, -hwaccel, etc.) are inserted before the first input file (-i). While this is generally correct for hwaccel, the test at line 54 of tests/test_gpu_vmaf.py asserts that the index of -hwaccel is less than -i. However, the actual command construction adds these flags after the vmaf_cmd function call arguments but before the inputs. The logic seems sound for the first input, but if multiple inputs were ever passed, only the first would be affected by the hwaccel chain defined here, potentially causing issues with the reference stream if it were also expected to be hardware decoded (though the diff shows it is not). </summary> ```python ] + (["-init_hw_device", f"qsv=hw:{qsv_device}", "-hwaccel", "qsv", "-hwaccel_output_format", "qsv", "-c:v", "av1_qsv"] if hw_in else []) + [ ``` </details> <details><summary><a href='https://git.kreative-kompas.com/khyretos/kk-reencoder/src/branch/perf/gpu-vmaf-decode/tests/test_gpu_vmaf.py#L54-L54'><strong>Test Assertion Reliability</strong></a> The test at line 54 asserts that the index of "-hwaccel" is less than the index of "-i". This relies on the specific order of arguments generated by vmaf_cmd. If future changes alter the argument insertion point or if the ffmpeg version behaves differently regarding argument parsing order, this assertion might fail even if the functionality works correctly. It is better to verify the presence of the flags relative to the specific input stream they are meant to affect rather than global index comparison. </summary> ```python self.assertLess(c.index("-hwaccel"), c.index("-i")) # only the encode (first input) is decoded on the GPU ``` </details> </td></tr> </table> <hr> 🗂️ **Finding ids** (reply with the id and `not an issue`, `false positive` or `won't fix` to dismiss one; it is then not reported again): - `KK-42ec94f1e3` `app/rx_search.py:227` - `KK-e57fe08f18` `app/rx_media.py:452` - `KK-4e0d72164a` `tests/test_gpu_vmaf.py:54` <!-- pr-agent-review-state:v1 {"findings":[{"body":"**Test Assertion Reliability**\n\nThe test at line 54 asserts that the index of \"-hwaccel\" is less than the index of \"-i\". This relies on the specific order of arguments generated by vmaf_cmd. If future changes alter the argument insertion point or if the ffmpeg version behaves differently regarding argument parsing order, this assertion might fail even if the functionality works correctly. It is better to verify the presence of the flags relative to the specific input stream they are meant to affect rather than global index comparison.","finding_id":"99f6130cd441","first_seen":"2026-11-02T06:16:25.262834Z","last_seen":"2026-11-02T06:16:25.262834Z","last_seen_head_sha":"27212bfe88080ff5b6faf73c100544d83852eca1","line_end":54,"line_start":54,"path":"tests/test_gpu_vmaf.py","state":"ACTIVE"},{"body":"**Logic Error in QSV Device Selection**\n\nThe code checks if the encoder is \"qsv\" to decide whether to use QSV for decoding. However, the PR description and tests specifically target AV1 encoding (\"av1_qsv\"). If a user configures a different qsv encoder (e.g., h264_qsv), this logic would incorrectly attempt to decode that stream using QSV hardware acceleration, which may not be supported or intended for all codecs.","finding_id":"9fa1e227b329","first_seen":"2026-11-02T06:16:25.262834Z","last_seen":"2026-11-02T06:16:25.262834Z","last_seen_head_sha":"27212bfe88080ff5b6faf73c100544d83852eca1","line_end":227,"line_start":227,"path":"app/rx_search.py","state":"ACTIVE"},{"body":"**Incorrect FFmpeg Argument Order**\n\nThe added arguments for QSV hardware acceleration (-init_hw_device, -hwaccel, etc.) are inserted before the first input file (-i). While this is generally correct for hwaccel, the test at line 54 of tests/test_gpu_vmaf.py asserts that the index of -hwaccel is less than -i. However, the actual command construction adds these flags after the vmaf_cmd function call arguments but before the inputs. The logic seems sound for the first input, but if multiple inputs were ever passed, only the first would be affected by the hwaccel chain defined here, potentially causing issues with the reference stream if it were also expected to be hardware decoded (though the diff shows it is not).","finding_id":"b96dc2b9a3ff","first_seen":"2026-11-02T06:16:25.262834Z","last_seen":"2026-11-02T06:16:25.262834Z","last_seen_head_sha":"27212bfe88080ff5b6faf73c100544d83852eca1","line_end":453,"line_start":452,"path":"app/rx_media.py","state":"ACTIVE"}],"last_run":{"complete":true,"excluded_files":[],"head_sha":"27212bfe88080ff5b6faf73c100544d83852eca1","kind":"full","run_id":"https://git.kreative-kompas.com/khyretos/kk-reencoder/commit/27212bfe88080ff5b6faf73c100544d83852eca1"},"schema_version":1} -->
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
khyretos/kk-reencoder!6
No description provided.