Expose libswresample options in AudioResampler#2296
Open
WyattBlue wants to merge 1 commit into
Open
Conversation
closes #2262 Add an `options` parameter to `AudioResampler` so callers can pass `libswresample` options (e.g. `resampler`, `filter_size`, `phase_shift`, `cutoff`, `precision`) through to the underlying resampler. When options are supplied, the conversion is performed by an explicit `aresample` filter (which owns the SwrContext) instead of the one FFmpeg auto-inserts before `aformat`. Options are forwarded as filter options, which search child contexts and reach the SwrContext. No new C bindings are required.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2262
Summary
Adds an
optionsparameter toav.AudioResamplerso callers can passlibswresampleoptions through to the underlying resampler:How it works
AudioResamplerbuilds a small filter graph (abuffer → aformat → abuffersink). Theaformatfilter is metadata-only — the actual resampling is done by anaresamplefilter, which owns theSwrContextand exposes every swr option as a childAVOption.When
optionsis supplied, an explicitaresamplefilter is inserted into the chain:instead of relying on the one FFmpeg auto-inserts. Options flow through
avfilter_init_dict, which searches child contexts, so they land on theSwrContext. No new C/Cython bindings are required — this stays within the existing filter API.Notes
ValueError: unused config: <name>rather than being silently ignored.resampler=soxradditionally requires FFmpeg to be built--enable-libsoxr; on builds without it, FFmpeg raisesInvalid argument(a build-time decision, unrelated to this API). The native swr knobs (filter_size,phase_shift,cutoff, etc.) work on any build.Tests
test_swr_options— verifies options pass through and output params are correct.test_swr_options_invalid— verifies an unknown option raises a clear error.Existing resampler tests and mypy are green.