Skip to content

fix: swr_init failure dude to FFmpeg 7 channel layout changes#148

Merged
anilbeesetti merged 1 commit intoanilbeesetti:mainfrom
mikooomich:fix-ffmpeg-7-channel-layout
Mar 20, 2026
Merged

fix: swr_init failure dude to FFmpeg 7 channel layout changes#148
anilbeesetti merged 1 commit intoanilbeesetti:mainfrom
mikooomich:fix-ffmpeg-7-channel-layout

Conversation

@mikooomich
Copy link
Copy Markdown
Contributor

Hello. This should fix swr_init on ffmpeg 7.x versions. Tested this on ffmpeg 7.1.1 with my own app, but haven't tested directly with nextlib.

Possibly #142 is the same issue

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the native audio resampling setup to accommodate FFmpeg 7.x channel layout API/option changes, aiming to prevent swr_init failures seen with some AAC streams.

Changes:

  • Switches from using ch_layout.u.mask (bitmask) to passing an AVChannelLayout.
  • Updates swresample option setting from in_channel_layout/out_channel_layout to in_chlayout/out_chlayout via av_opt_set_chlayout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 155 to 159
resampleContext = swr_alloc();
av_opt_set_int(resampleContext, "in_channel_layout", channelLayout, 0);
av_opt_set_int(resampleContext, "out_channel_layout", channelLayout, 0);
av_opt_set_chlayout(resampleContext, "in_chlayout", &channelLayout, 0);
av_opt_set_chlayout(resampleContext, "out_chlayout", &channelLayout, 0);
av_opt_set_int(resampleContext, "in_sample_rate", sampleRate, 0);
av_opt_set_int(resampleContext, "out_sample_rate", sampleRate, 0);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swr_alloc() and all av_opt_set_* calls return error codes (and swr_alloc() can return nullptr), but none of these are checked here. If in_chlayout/out_chlayout isn’t recognized by the linked FFmpeg build, the option set will silently fail and swr_init will still error (or you could dereference a null resampleContext). Please check return values, log a useful error, and ensure any partially-created SwrContext is freed on failure to avoid leaks/crashes.

Copilot uses AI. Check for mistakes.
@anilbeesetti anilbeesetti merged commit 6707bbd into anilbeesetti:main Mar 20, 2026
4 checks passed
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.

3 participants