Skip to content

Move sample rate and sample format conversion utils into FFMPEGCommon.cpp #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 11, 2025

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Apr 9, 2025

This PR moves the sample rate and sample format conversions utils from SingleStreamDecoder into FFMPEGCommon. Sample format conversion is needed for encoding too, so we need to make them common.

Specifically:

  • SingleStreamDecoder::createSwrContext is removed and its logic is not part of FFMPEGCommon's allocateSwrContext, which was renamed into createSwrContext
  • SingleStreamDecoder::convertAudioAVFrameSampleFormatAndSampleRate is moved too

Inputs are slightly modified to account for the fact that there's no streamInfo_ anymore. Other than that, this is just copy/pasting code.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 9, 2025
return swrContext;
}

UniqueAVFrame convertAudioAVFrameSampleFormatAndSampleRate(
const UniqueSwrContext& swrContext,
const UniqueAVFrame& srcAVFrame,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we should be consistent about src and source. I have a preference for src, as it's a universal abbreviation, particularly when paired with dst. But if we say source in a lot of other places, we should stick with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Double nit, and I recognize this name already existed: convertAudioAVFrameSampleFormatAndSampleRate() is very long, and I feel like we're encoding parameter names that modify the operation into the name. I feel like it's clearer as just convertAudioAVFrame().

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, I'll merge as-is and follow-up with a PR to address these

@NicolasHug NicolasHug merged commit 12cdaa8 into pytorch:main Apr 11, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants