-
Notifications
You must be signed in to change notification settings - Fork 63
Handle AVCodec fields deprecated in FFmpeg 7 #898
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
Dan-Flores
merged 6 commits into
meta-pytorch:main
from
Dan-Flores:fix_ch_layouts_ffmpeg7
Sep 18, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a17b466
use avcodec_get_supported_config
a7faca0
check LIBAVCODEC version
8f20a8f
add torch check when avcodec_get_supported_config fails
599556d
remove unused return
2c4863c
move ifdef into ffmpegcommon
8c63ece
use reinterpret_cast
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,21 +33,22 @@ torch::Tensor validateSamples(const torch::Tensor& samples) { | |
} | ||
|
||
void validateSampleRate(const AVCodec& avCodec, int sampleRate) { | ||
if (avCodec.supported_samplerates == nullptr) { | ||
const int* supportedSampleRates = getSupportedSampleRates(avCodec); | ||
if (supportedSampleRates == nullptr) { | ||
return; | ||
} | ||
|
||
for (auto i = 0; avCodec.supported_samplerates[i] != 0; ++i) { | ||
if (sampleRate == avCodec.supported_samplerates[i]) { | ||
for (auto i = 0; supportedSampleRates[i] != 0; ++i) { | ||
if (sampleRate == supportedSampleRates[i]) { | ||
return; | ||
} | ||
} | ||
std::stringstream supportedRates; | ||
for (auto i = 0; avCodec.supported_samplerates[i] != 0; ++i) { | ||
for (auto i = 0; supportedSampleRates[i] != 0; ++i) { | ||
if (i > 0) { | ||
supportedRates << ", "; | ||
} | ||
supportedRates << avCodec.supported_samplerates[i]; | ||
supportedRates << supportedSampleRates[i]; | ||
} | ||
|
||
TORCH_CHECK( | ||
|
@@ -73,27 +74,30 @@ static const std::vector<AVSampleFormat> preferredFormatsOrder = { | |
AV_SAMPLE_FMT_U8}; | ||
|
||
AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) { | ||
const AVSampleFormat* supportedSampleFormats = | ||
getSupportedOutputSampleFormats(avCodec); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here about creating a function in |
||
// Find a sample format that the encoder supports. We prefer using FLT[P], | ||
// since this is the format of the input samples. If FLTP isn't supported | ||
// then we'll need to convert the AVFrame's format. Our heuristic is to encode | ||
// into the format with the highest resolution. | ||
if (avCodec.sample_fmts == nullptr) { | ||
if (supportedSampleFormats == nullptr) { | ||
// Can't really validate anything in this case, best we can do is hope that | ||
// FLTP is supported by the encoder. If not, FFmpeg will raise. | ||
return AV_SAMPLE_FMT_FLTP; | ||
} | ||
|
||
for (AVSampleFormat preferredFormat : preferredFormatsOrder) { | ||
for (int i = 0; avCodec.sample_fmts[i] != -1; ++i) { | ||
if (avCodec.sample_fmts[i] == preferredFormat) { | ||
for (int i = 0; supportedSampleFormats[i] != -1; ++i) { | ||
if (supportedSampleFormats[i] == preferredFormat) { | ||
return preferredFormat; | ||
} | ||
} | ||
} | ||
// We should always find a match in preferredFormatsOrder, so we should always | ||
// return earlier. But in the event that a future FFmpeg version defines an | ||
// additional sample format that isn't in preferredFormatsOrder, we fallback: | ||
return avCodec.sample_fmts[0]; | ||
return supportedSampleFormats[0]; | ||
} | ||
|
||
} // namespace | ||
|
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been trying to keep FFmpeg version ifdef-ing out of the mainline logic, and keep it all in functions defined in
FFMPEGCommon
. I think we should defined there as something like: