Skip to content

Correct FFmpeg frame sizes, timestamps and EOF handling - #202

Closed
Recluse wants to merge 1 commit into
KD-lab-Open-Source:mainfrom
Recluse:pr/media-decoding
Closed

Recluse wants to merge 1 commit into
KD-lab-Open-Source:mainfrom
Recluse:pr/media-decoding

Conversation

@Recluse

@Recluse Recluse commented Oct 21, 2026

Copy link
Copy Markdown

Audio copies included alignment padding, planar audio handling did not support more than eight channels, and decoder/filter output could be lost at EOF. The wrapper now copies the actual samples, preserves audio timestamps and drains pending output. Video scaling uses the decoded frame's format and dimensions.

@IonAgorria

Copy link
Copy Markdown
Collaborator

Hello,

Can you give more details about "handling more than eight channels", you mean the movie being played or your computer having 8 channels audio setup?

@Recluse

Recluse commented Oct 21, 2026

Copy link
Copy Markdown
Author

This refers to the channel count of the audio frame being copied in AVWrapperFrame::copyBuffer(), not the computer’s speaker setup.

For planar audio, each channel has its own data pointer. The old code indexed AVFrame::data[pi], but that array has only eight entries, so a frame with more than eight channels would cause an out-of-bounds access. The change uses AVFrame::extended_data[pi], which provides pointers for all channels.

This was checked with a synthetic 10-channel planar frame under ASan/UBSan, not with a game movie containing that many channels. The wording in the description could have been clearer.

@Recluse

Recluse commented Oct 21, 2026

Copy link
Copy Markdown
Author

The decoder regression test also passes on Windows with GCC 15.2 and FFmpeg 8.1: packed and planar audio including 10-channel frames, odd-width video, timestamps and end-of-stream draining. The test produced the expected 30 video frames and 192000 audio bytes.

I also tested movie playback in the Windows build containing these PRs; the videos I checked played correctly.

@IonAgorria

IonAgorria commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Why are you testing cases that not even occur in the real game for real players? this is not a movie player app this is a game, we dont need to support every possible movie/audio input... just the ones game assets contain...

Please stop wasting time with synthetic and madeup circumstances that don't occur for real users and limit the changes to actual necessary fixes or i will have to close the PR, what bugs are you seeing that does this PR actually fix?

@Recluse

Recluse commented Oct 23, 2026

Copy link
Copy Markdown
Author

You're right. These changes came out of debugging movie playback on macOS, and I didn't check whether they were needed before opening the PR.

I've now tested Perimeter and Emperor's Testament on macOS with the original decoder and player, keeping the FFmpeg dependency selection fix from #200 and the other macOS changes. All tested movies play correctly without #202 or #203. The synthetic tests didn't demonstrate a problem with the game's movies.

I'll close this PR. Sorry for the unnecessary review work, and thank you for pushing back.

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

Successfully merging this pull request may close these issues.

2 participants