feat(videodec2): decode H.264 with FFmpeg #42

Merged
Pacuka merged 4 commits from upstream-pr/42 into main 2026-09-30 14:48:33 +00:00
Pacuka commented 2026-09-27 19:52:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-09-27T19:52:21Z.


What

This adds libSceVideodec2 with real H.264 decoding through FFmpeg (libavcodec, libavutil, libswscale). FFmpeg is built from source as a submodule.

  • FFmpeg n9.0.2 is the pinned, shallow submodule 3rdparty/FFmpeg. ExternalProject_Add runs FFmpeg's own configure and make. Only avcodec, avutil and swscale are built, and the H.264 decoder is the only component (--disable-everything --enable-decoder=h264 --disable-autodetect). They are static PIC archives linked into libSceVideodec2.prx with --exclude-libs,ALL, so the prx has no FFmpeg runtime dependency and exports no FFmpeg symbols. Without nasm, the x86 assembly is disabled.
  • Access units go to FFmpeg's H.264 decoder. Annex B input is passed through unchanged; length-prefixed (AVCC) input is rewritten to Annex B first.
  • Pictures are written into the title's frame buffer as NV12: 256-byte pitch, with the interleaved chroma plane right after the visible luma rows (framePitch * frameHeight). Titles read it there, so a 1080-row movie has its chroma at row 1080, not 1088.
  • Decode hands out at most one picture per call, and isAccepted / isValid say whether the buffer was used. Flush drains the reordered pictures one per call. Reset clears the decoder.
  • pts, dts and attached data travel with each picture. GetPictureInfo reports them together with the IDR flag, profile and level.
  • Each decoder has its own lock, so two movies don't serialize on each other.
  • With -DANYPS5_ENABLE_FFMPEG=OFF, or without sh/make (plain MinGW), the module still builds. Decoders then return black NV12 pictures that carry the timestamps, so players still advance through a movie. This fallback and the non-H.264 codecs are listed under silent stubs in TechnicalDebt.md.

Limitations: H.264 only (HEVC and other codec types get the black-picture behaviour); decoding runs on the CPU with FFmpeg slice threads.

Tested

Linux (CachyOS, GCC), clean build directory.

  • New guest_videodec2 test. It decodes an embedded 64x40 High-profile stream with 2 B-frames, once as Annex B and once as length-prefixed. For every picture it checks the geometry, the display order, the timestamps and attached data, and the IDR/profile flags, and it compares a hash of the NV12 against the reference from the ffmpeg CLI. Passes with the submodule build. I checked that the test fails when the chroma plane is moved to the aligned height.
  • Full build plus libs; ctest passes 57/57. FFmpeg's configure and build take about 20 s. -DANYPS5_ENABLE_FFMPEG=OFF also builds.
  • Outside the tree, I compared 320x240 and 1920x1080 streams (up to 3 B-frames) byte for byte with the ffmpeg CLI output. All pictures match.
  • The intro cinematic of The Smurfs Dreams (1920x1080, Main profile) plays with correct colors (checked on a local branch with #5's driver, before #5 was merged).
  • Windows: not tested. It needs sh and make (MSYS2) for FFmpeg's configure; without them the fallback is used.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4656345179 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-09-27T19:52:21Z. --- ### What This adds libSceVideodec2 with real H.264 decoding through FFmpeg (libavcodec, libavutil, libswscale). FFmpeg is built from source as a submodule. - FFmpeg n9.0.2 is the pinned, shallow submodule `3rdparty/FFmpeg`. `ExternalProject_Add` runs FFmpeg's own `configure` and `make`. Only avcodec, avutil and swscale are built, and the H.264 decoder is the only component (`--disable-everything --enable-decoder=h264 --disable-autodetect`). They are static PIC archives linked into `libSceVideodec2.prx` with `--exclude-libs,ALL`, so the prx has no FFmpeg runtime dependency and exports no FFmpeg symbols. Without nasm, the x86 assembly is disabled. - Access units go to FFmpeg's H.264 decoder. Annex B input is passed through unchanged; length-prefixed (AVCC) input is rewritten to Annex B first. - Pictures are written into the title's frame buffer as NV12: 256-byte pitch, with the interleaved chroma plane right after the visible luma rows (`framePitch * frameHeight`). Titles read it there, so a 1080-row movie has its chroma at row 1080, not 1088. - Decode hands out at most one picture per call, and `isAccepted` / `isValid` say whether the buffer was used. Flush drains the reordered pictures one per call. Reset clears the decoder. - pts, dts and attached data travel with each picture. GetPictureInfo reports them together with the IDR flag, profile and level. - Each decoder has its own lock, so two movies don't serialize on each other. - With `-DANYPS5_ENABLE_FFMPEG=OFF`, or without `sh`/`make` (plain MinGW), the module still builds. Decoders then return black NV12 pictures that carry the timestamps, so players still advance through a movie. This fallback and the non-H.264 codecs are listed under silent stubs in TechnicalDebt.md. Limitations: H.264 only (HEVC and other codec types get the black-picture behaviour); decoding runs on the CPU with FFmpeg slice threads. ### Tested Linux (CachyOS, GCC), clean build directory. - New `guest_videodec2` test. It decodes an embedded 64x40 High-profile stream with 2 B-frames, once as Annex B and once as length-prefixed. For every picture it checks the geometry, the display order, the timestamps and attached data, and the IDR/profile flags, and it compares a hash of the NV12 against the reference from the ffmpeg CLI. Passes with the submodule build. I checked that the test fails when the chroma plane is moved to the aligned height. - Full build plus `libs`; ctest passes 57/57. FFmpeg's configure and build take about 20 s. `-DANYPS5_ENABLE_FFMPEG=OFF` also builds. - Outside the tree, I compared 320x240 and 1920x1080 streams (up to 3 B-frames) byte for byte with the ffmpeg CLI output. All pictures match. - The intro cinematic of The Smurfs Dreams (1920x1080, Main profile) plays with correct colors (checked on a local branch with #5's driver, before #5 was merged). - Windows: not tested. It needs `sh` and `make` (MSYS2) for FFmpeg's configure; without them the fallback is used. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
boykopovar commented 2026-09-27 21:27:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-27T21:27:22Z.


Is it possible to use ffmpeg from source instead of the system version? As a new submodule. And if we compile from source, I don't think the whole ffmpeg is needed, just avcodec, avutil, swscale and H.264. But the problem is that FFmpeg is not a CMake project.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5859977032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5859977032). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-09-27T21:27:22Z. --- Is it possible to use ffmpeg from source instead of the system version? As a new submodule. And if we compile from source, I don't think the whole ffmpeg is needed, just avcodec, avutil, swscale and H.264. But the problem is that FFmpeg is not a CMake project.
julienlgy commented 2026-09-28 12:09:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by julienlgy on 2026-09-28T12:09:24Z.


Add FFmpeg as a pinned submodule and build only the required H.264 decoder, avcodec, avutil and swscale with CMake’s ExternalProject_Add, which can run FFmpeg’s own configure and Make build without requiring FFmpeg to support CMake.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5869539077 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5869539077). Originally posted by [julienlgy](https://github.com/julienlgy) on 2026-09-28T12:09:24Z. --- Add FFmpeg as a pinned submodule and build only the required H.264 decoder, avcodec, avutil and swscale with CMake’s ExternalProject_Add, which can run FFmpeg’s own configure and Make build without requiring FFmpeg to support CMake.
Pacuka commented 2026-09-28 19:05:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-09-28T19:05:11Z.


Done: FFmpeg n9.0.2 is now a pinned shallow submodule in 3rdparty/FFmpeg, built with ExternalProject_Add through its own configure/make (thanks @julienlgy). Only avcodec, avutil and swscale are built, with the H.264 decoder as the single component, as static archives linked into the prx. The system FFmpeg is no longer used. Also rebased onto main. Details are in the updated description.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5876616688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5876616688). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-09-28T19:05:11Z. --- Done: FFmpeg n9.0.2 is now a pinned shallow submodule in `3rdparty/FFmpeg`, built with `ExternalProject_Add` through its own configure/make (thanks @julienlgy). Only avcodec, avutil and swscale are built, with the H.264 decoder as the single component, as static archives linked into the prx. The system FFmpeg is no longer used. Also rebased onto main. Details are in the updated description.
github-actions[bot] commented 2026-09-28 19:05:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-09-28T19:05:19Z.


Progress report (fc05962 → 1e1f056)

📈 System libraries: 74.71% (+0.08%, +10 implemented functions)

✅ 10 implemented
Library Name
libSceVideodec2 sceVideodec2AllocateComputeQueue_nid_postfix
libSceVideodec2 sceVideodec2CreateDecoder_nid_postfix
libSceVideodec2 sceVideodec2Decode_nid_postfix
libSceVideodec2 sceVideodec2DeleteDecoder_nid_postfix
libSceVideodec2 sceVideodec2Flush_nid_postfix
libSceVideodec2 sceVideodec2GetPictureInfo_nid_postfix
libSceVideodec2 sceVideodec2QueryComputeMemoryInfo_nid_postfix
libSceVideodec2 sceVideodec2QueryDecoderMemoryInfo_nid_postfix
libSceVideodec2 sceVideodec2ReleaseComputeQueue_nid_postfix
libSceVideodec2 sceVideodec2Reset_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5876618712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5876618712). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-09-28T19:05:19Z. --- <!-- progress-report --> ### Progress report (fc05962 → 1e1f056) 📈 **System libraries**: 74.71% (+0.08%, +10 implemented functions) <details> <summary>✅ 10 implemented</summary> | Library | Name | | - | - | | libSceVideodec2 | `sceVideodec2AllocateComputeQueue_nid_postfix` | | libSceVideodec2 | `sceVideodec2CreateDecoder_nid_postfix` | | libSceVideodec2 | `sceVideodec2Decode_nid_postfix` | | libSceVideodec2 | `sceVideodec2DeleteDecoder_nid_postfix` | | libSceVideodec2 | `sceVideodec2Flush_nid_postfix` | | libSceVideodec2 | `sceVideodec2GetPictureInfo_nid_postfix` | | libSceVideodec2 | `sceVideodec2QueryComputeMemoryInfo_nid_postfix` | | libSceVideodec2 | `sceVideodec2QueryDecoderMemoryInfo_nid_postfix` | | libSceVideodec2 | `sceVideodec2ReleaseComputeQueue_nid_postfix` | | libSceVideodec2 | `sceVideodec2Reset_nid_postfix` | </details>
boykopovar commented 2026-09-28 22:28:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-28T22:28:50Z.


Can you resolve conflicts? I'll test it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5879889924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5879889924). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-09-28T22:28:50Z. --- Can you resolve conflicts? I'll test it.
Pacuka commented 2026-09-29 15:41:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-09-29T15:41:24Z.


Rebased onto current main and resolved the conflicts (.gitmodules, TechnicalDebt.md moved to docs/dev). Build and ctest (61/61) pass on Linux. Ready for testing.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5893555913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5893555913). Originally posted by [Pacuka](https://github.com/Pacuka) on 2026-09-29T15:41:24Z. --- Rebased onto current main and resolved the conflicts (.gitmodules, TechnicalDebt.md moved to docs/dev). Build and ctest (61/61) pass on Linux. Ready for testing.
boykopovar commented 2026-09-30 08:44:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-30T08:44:15Z.


STL1te proposed a more lightweight approach in #153. It eliminates the need to rely on the system ffmpeg and build it from source. The submodule is already added and used in main. Please adapt your changes to this.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5907555498 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5907555498). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-09-30T08:44:15Z. --- STL1te proposed a more lightweight approach in #153. It eliminates the need to rely on the system ffmpeg and build it from source. The submodule is already added and used in main. Please adapt your changes to this.
boykopovar commented 2026-09-30 14:43:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-30T14:43:31Z.


I've switched to using the ffmpeg-core submodule and removed the black frame fallback. If anything is wrong, please open a new PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5913595610 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/42#issuecomment-5913595610). Originally posted by [boykopovar](https://github.com/boykopovar) on 2026-09-30T14:43:31Z. --- I've switched to using the ffmpeg-core submodule and removed the black frame fallback. If anything is wrong, please open a new PR.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!42
No description provided.