@@ -58,7 +58,7 @@ int64_t getDuration(const UniqueAVFrame& avFrame) {
58
58
59
59
const int * getSupportedSampleRates (const AVCodec& avCodec) {
60
60
const int * supportedSampleRates = nullptr ;
61
- #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100)
61
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // FFmpeg >= 7.1
62
62
int numSampleRates = 0 ;
63
63
int ret = avcodec_get_supported_config (
64
64
nullptr ,
@@ -68,7 +68,8 @@ const int* getSupportedSampleRates(const AVCodec& avCodec) {
68
68
reinterpret_cast <const void **>(&supportedSampleRates),
69
69
&numSampleRates);
70
70
if (ret < 0 || supportedSampleRates == nullptr ) {
71
- TORCH_CHECK (false , " Couldn't get supported sample rates from encoder." );
71
+ // Return nullptr to skip validation in validateSampleRate.
72
+ return nullptr ;
72
73
}
73
74
#else
74
75
supportedSampleRates = avCodec.supported_samplerates ;
@@ -78,7 +79,7 @@ const int* getSupportedSampleRates(const AVCodec& avCodec) {
78
79
79
80
const AVSampleFormat* getSupportedOutputSampleFormats (const AVCodec& avCodec) {
80
81
const AVSampleFormat* supportedSampleFormats = nullptr ;
81
- #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // FFmpeg >= 7
82
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // FFmpeg >= 7.1
82
83
int numSampleFormats = 0 ;
83
84
int ret = avcodec_get_supported_config (
84
85
nullptr ,
@@ -88,7 +89,9 @@ const AVSampleFormat* getSupportedOutputSampleFormats(const AVCodec& avCodec) {
88
89
reinterpret_cast <const void **>(&supportedSampleFormats),
89
90
&numSampleFormats);
90
91
if (ret < 0 || supportedSampleFormats == nullptr ) {
91
- TORCH_CHECK (false , " Couldn't get supported sample formats from encoder." );
92
+ // Return nullptr to use default output format in
93
+ // findBestOutputSampleFormat.
94
+ return nullptr ;
92
95
}
93
96
#else
94
97
supportedSampleFormats = avCodec.sample_fmts ;
@@ -149,27 +152,28 @@ void setDefaultChannelLayout(UniqueAVFrame& avFrame, int numChannels) {
149
152
}
150
153
151
154
void validateNumChannels (const AVCodec& avCodec, int numChannels) {
152
- #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // FFmpeg >= 7
155
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 13, 100) // FFmpeg >= 7.1
153
156
std::stringstream supportedNumChannels;
154
- const AVChannelLayout* supported_layouts = nullptr ;
155
- int num_layouts = 0 ;
157
+ const AVChannelLayout* supportedLayouts = nullptr ;
158
+ int numLayouts = 0 ;
156
159
int ret = avcodec_get_supported_config (
157
160
nullptr ,
158
161
&avCodec,
159
162
AV_CODEC_CONFIG_CHANNEL_LAYOUT,
160
163
0 ,
161
- reinterpret_cast <const void **>(&supported_layouts),
162
- &num_layouts);
163
- if (ret < 0 || supported_layouts == nullptr ) {
164
- TORCH_CHECK (false , " Couldn't get supported channel layouts from encoder." );
164
+ reinterpret_cast <const void **>(&supportedLayouts),
165
+ &numLayouts);
166
+ if (ret < 0 || supportedLayouts == nullptr ) {
167
+ // If we can't validate, we must assume it'll be fine. If not, FFmpeg will
168
+ // eventually raise.
165
169
return ;
166
170
}
167
- for (int i = 0 ; supported_layouts[i]. nb_channels != 0 ; ++i) {
171
+ for (int i = 0 ; i < numLayouts ; ++i) {
168
172
if (i > 0 ) {
169
173
supportedNumChannels << " , " ;
170
174
}
171
- supportedNumChannels << supported_layouts [i].nb_channels ;
172
- if (numChannels == supported_layouts [i].nb_channels ) {
175
+ supportedNumChannels << supportedLayouts [i].nb_channels ;
176
+ if (numChannels == supportedLayouts [i].nb_channels ) {
173
177
return ;
174
178
}
175
179
}
0 commit comments