diff --git a/src/libtorio/ffmpeg/filter_graph.cpp b/src/libtorio/ffmpeg/filter_graph.cpp index 51c8084f07e..3136f0f1403 100644 --- a/src/libtorio/ffmpeg/filter_graph.cpp +++ b/src/libtorio/ffmpeg/filter_graph.cpp @@ -22,17 +22,17 @@ std::string get_audio_src_args( AVSampleFormat format, AVRational time_base, int sample_rate, - uint64_t channel_layout) { + int nb_channels) { char args[512]; std::snprintf( args, sizeof(args), - "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%" PRIx64, + "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=%dc", time_base.num, time_base.den, sample_rate, av_get_sample_fmt_name(format), - channel_layout); + nb_channels); return std::string(args); } @@ -66,10 +66,10 @@ void FilterGraph::add_audio_src( AVSampleFormat format, AVRational time_base, int sample_rate, - uint64_t channel_layout) { + int nb_channels) { add_src( avfilter_get_by_name("abuffer"), - get_audio_src_args(format, time_base, sample_rate, channel_layout)); + get_audio_src_args(format, time_base, sample_rate, nb_channels)); } void FilterGraph::add_video_src( diff --git a/src/libtorio/ffmpeg/filter_graph.h b/src/libtorio/ffmpeg/filter_graph.h index 2495c2d240f..3bb36ec7cfb 100644 --- a/src/libtorio/ffmpeg/filter_graph.h +++ b/src/libtorio/ffmpeg/filter_graph.h @@ -47,7 +47,7 @@ class FilterGraph { AVSampleFormat format, AVRational time_base, int sample_rate, - uint64_t channel_layout); + int nb_channels); void add_video_src( AVPixelFormat format, diff --git a/src/libtorio/ffmpeg/stream_reader/post_process.cpp b/src/libtorio/ffmpeg/stream_reader/post_process.cpp index e92a6bbee2a..8268804e782 100644 --- a/src/libtorio/ffmpeg/stream_reader/post_process.cpp +++ b/src/libtorio/ffmpeg/stream_reader/post_process.cpp @@ -19,10 +19,15 @@ FilterGraphFactory get_audio_factory( return [fmt = codec_ctx->sample_fmt, time_base, rate = codec_ctx->sample_rate, - channel_layout = codec_ctx->channel_layout]( - const std::string& filter_desc) -> FilterGraph { + nb_channels = +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 2, 100) + codec_ctx->ch_layout.nb_channels +#else + codec_ctx->channels +#endif + ](const std::string& filter_desc) -> FilterGraph { FilterGraph f; - f.add_audio_src(fmt, time_base, rate, channel_layout); + f.add_audio_src(fmt, time_base, rate, nb_channels); f.add_audio_sink(); f.add_process(filter_desc); f.create_filter(); diff --git a/src/libtorio/ffmpeg/stream_reader/stream_processor.cpp b/src/libtorio/ffmpeg/stream_reader/stream_processor.cpp index 49f87bf5da8..aff7131834e 100644 --- a/src/libtorio/ffmpeg/stream_reader/stream_processor.cpp +++ b/src/libtorio/ffmpeg/stream_reader/stream_processor.cpp @@ -140,11 +140,6 @@ void open_codec( av_dict_set(&opts, "threads", "1", 0); } - if (!codec_ctx->channel_layout) { - codec_ctx->channel_layout = - av_get_default_channel_layout(codec_ctx->channels); - } - int ret = avcodec_open2(codec_ctx, codec_ctx->codec, &opts); clean_up_dict(opts); TORCH_CHECK(