File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ int getNumChannels(const UniqueAVFrame& avFrame) {
6767 // to allow successful initialization of SwrContext
6868 if (numChannels == 0 && avFrame->channels > 0 ) {
6969 avFrame->channel_layout = av_get_default_channel_layout (avFrame->channels );
70+ return avFrame->channels ;
7071 }
7172 return numChannels;
7273#endif
Original file line number Diff line number Diff line change @@ -1276,7 +1276,20 @@ void SingleStreamDecoder::convertAudioAVFrameToFrameOutputOnCPU(
12761276 int outSampleRate =
12771277 streamInfo.audioStreamOptions .sampleRate .value_or (srcSampleRate);
12781278
1279- int srcNumChannels = getNumChannels (streamInfo.codecContext );
1279+ int srcNumChannels = getNumChannels (srcAVFrame);
1280+ int srcNumChannelsFromCodec = getNumChannels (streamInfo.codecContext );
1281+ // Use number of channels from codec if 0 returned from frame
1282+ if (srcNumChannels == 0 && srcNumChannelsFromCodec > 0 ) {
1283+ srcNumChannels = srcNumChannelsFromCodec;
1284+ } else {
1285+ // Check if the number of channels from the frame matches the codec
1286+ TORCH_CHECK (
1287+ srcNumChannels == srcNumChannelsFromCodec,
1288+ " The frame has " ,
1289+ srcNumChannels,
1290+ " channels, expected " ,
1291+ srcNumChannelsFromCodec);
1292+ };
12801293 int outNumChannels =
12811294 streamInfo.audioStreamOptions .numChannels .value_or (srcNumChannels);
12821295
You can’t perform that action at this time.
0 commit comments