diff --git a/src/video/video.c b/src/video/video.c index c815493b..6d893bf6 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -402,7 +402,11 @@ struct vc_ctx { }; /* Custom AVIO пишет в уже эксклюзивно открытый файл, без повторного открытия временного пути. */ +#if LIBAVFORMAT_VERSION_MAJOR >= 61 +static int vc_io_write(void* opaque, const uint8_t* bytes, int length) { +#else static int vc_io_write(void* opaque, uint8_t* bytes, int length) { +#endif struct vc_file* file = opaque; if (fwrite(bytes, 1, length, file->file) == (size_t)length) return length; int error = errno ? errno : EIO; @@ -528,12 +532,25 @@ static int vc_open_audio(struct vc_ctx* ctx) { if (!stream->encoder) return AVERROR(ENOMEM); AVCodecContext* encoder = stream->encoder; encoder->bit_rate = VIDEO_TARGET_AUDIO_BITRATE; encoder->sample_rate = decoder->sample_rate; - if (codec->supported_samplerates) { - encoder->sample_rate = codec->supported_samplerates[0]; - for (const int* rate = codec->supported_samplerates; *rate; rate++) + const int* rates; + const enum AVSampleFormat* formats; +#if LIBAVCODEC_VERSION_MAJOR >= 61 + const void* configurations; + int supported = avcodec_get_supported_config(encoder, codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0, &configurations, NULL); + if (supported < 0) return supported; + rates = configurations; + supported = avcodec_get_supported_config(encoder, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, &configurations, NULL); + if (supported < 0) return supported; + formats = configurations; +#else + rates = codec->supported_samplerates; formats = codec->sample_fmts; +#endif + if (rates) { + encoder->sample_rate = rates[0]; + for (const int* rate = rates; *rate; rate++) if (abs(*rate - decoder->sample_rate) < abs(encoder->sample_rate - decoder->sample_rate)) encoder->sample_rate = *rate; } - encoder->sample_fmt = codec->sample_fmts ? codec->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; + encoder->sample_fmt = formats ? formats[0] : AV_SAMPLE_FMT_FLTP; int error = av_channel_layout_copy(&encoder->ch_layout, &decoder->ch_layout); if (error < 0) return error; encoder->time_base = (AVRational){1, encoder->sample_rate};