@@ -1365,10 +1365,20 @@ void VideoDecoder::convertAudioAVFrameToFrameOutputOnCPU(
13651365 static_cast <AVSampleFormat>(avFrameStream.avFrame ->format );
13661366 AVSampleFormat desiredSampleFormat = AV_SAMPLE_FMT_FLTP;
13671367
1368+ int sourceSampleRate = avFrameStream.avFrame ->sample_rate ;
1369+ int desiredSampleRate =
1370+ streamInfos_[activeStreamIndex_].audioStreamOptions .sampleRate .value_or (
1371+ sourceSampleRate);
1372+
13681373 UniqueAVFrame convertedAVFrame;
1369- if (sourceSampleFormat != desiredSampleFormat) {
1370- convertedAVFrame = convertAudioAVFrameSampleFormat (
1371- avFrameStream.avFrame , sourceSampleFormat, desiredSampleFormat);
1374+ if (sourceSampleFormat != desiredSampleFormat ||
1375+ sourceSampleRate != desiredSampleRate) {
1376+ convertedAVFrame = convertAudioAVFrameSampleFormatAndSampleRate (
1377+ avFrameStream.avFrame ,
1378+ sourceSampleFormat,
1379+ desiredSampleFormat,
1380+ sourceSampleRate,
1381+ desiredSampleRate);
13721382 }
13731383 const UniqueAVFrame& avFrame = (sourceSampleFormat != desiredSampleFormat)
13741384 ? convertedAVFrame
@@ -1398,12 +1408,12 @@ void VideoDecoder::convertAudioAVFrameToFrameOutputOnCPU(
13981408 frameOutput.data = outputData;
13991409}
14001410
1401- UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormat (
1411+ UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormatAndSampleRate (
14021412 const UniqueAVFrame& avFrame,
14031413 AVSampleFormat sourceSampleFormat,
1404- AVSampleFormat desiredSampleFormat
1405-
1406- ) {
1414+ AVSampleFormat desiredSampleFormat,
1415+ int sourceSampleRate,
1416+ int desiredSampleRate ) {
14071417 auto & streamInfo = streamInfos_[activeStreamIndex_];
14081418 const auto & streamMetadata =
14091419 containerMetadata_.allStreamMetadata [activeStreamIndex_];
0 commit comments