@@ -1409,7 +1409,11 @@ UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormat(
14091409 convertedAVFrame,
14101410 " Could not allocate frame for sample format conversion." );
14111411
1412+ #if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
14121413 convertedAVFrame->ch_layout = avFrame->ch_layout ;
1414+ #else
1415+ convertedAVFrame->channel_layout = avFrame->channel_layout ;
1416+ #endif
14131417 convertedAVFrame->sample_rate = avFrame->sample_rate ;
14141418 convertedAVFrame->nb_samples = avFrame->nb_samples ;
14151419 convertedAVFrame->format = desiredSampleFormat;
@@ -1672,11 +1676,12 @@ void VideoDecoder::createSwrContext(
16721676 int sampleRate,
16731677 AVSampleFormat sourceSampleFormat,
16741678 AVSampleFormat desiredSampleFormat) {
1675- SwrContext* swrContext = NULL ;
1679+ SwrContext* swrContext = nullptr ;
16761680
1681+ int status = AVSUCCESS;
1682+ #if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
16771683 AVChannelLayout layout = streamInfo.codecContext ->ch_layout ;
1678-
1679- auto status = swr_alloc_set_opts2 (
1684+ status = swr_alloc_set_opts2 (
16801685 &swrContext,
16811686 &layout,
16821687 desiredSampleFormat,
@@ -1685,12 +1690,26 @@ void VideoDecoder::createSwrContext(
16851690 sourceSampleFormat,
16861691 sampleRate,
16871692 0 ,
1688- NULL );
1693+ nullptr );
16891694
16901695 TORCH_CHECK (
16911696 status == AVSUCCESS,
16921697 " Couldn't create SwrContext: " ,
16931698 getFFMPEGErrorStringFromErrorCode (status));
1699+ #else
1700+ int64_t layout =
1701+ static_cast <int64_t >(streamInfo.codecContext ->channel_layout );
1702+ swrContext = swr_alloc_set_opts (
1703+ nullptr ,
1704+ layout,
1705+ desiredSampleFormat,
1706+ sampleRate,
1707+ layout,
1708+ sourceSampleFormat,
1709+ sampleRate,
1710+ 0 ,
1711+ nullptr );
1712+ #endif
16941713
16951714 status = swr_init (swrContext);
16961715 TORCH_CHECK (
0 commit comments