сб, 6 апр. 2024 г., 01:16 Andrew Randrianasulu <randrianas...@gmail.com>:
> so I was using this patch as guidance > > > https://github.com/HandBrake/HandBrake/pull/4451/commits/5e86b74d405f63ed020fa09eb076a65b7337bd4e > > apparently channels was replaced by ch_layout.nb_channels > > and channel_layout > by ch_layout.u.mask > > I'll try to put ifdef guards around those changes and make some patches ... > It compiles :) but not sure if it actually works .. note, it should compile even with our ffmpeg 6.1 , I hope? because api change was for 5.1, 7.0 just removed it as "long deprecated" . >
From ad9d27735686b5aa4256f0a46c338559337fa98a Mon Sep 17 00:00:00 2001 From: Andrew Randrianasulu <randrianas...@gmail.com> Date: Sat, 6 Apr 2024 13:18:11 +0300 Subject: [PATCH] Adapt to ffmpeg 7.0, drop ffmpeg pre 5.1 support --- cinelerra-5.1/cinelerra/bdwrite.C | 2 +- cinelerra-5.1/cinelerra/ffmpeg.C | 56 ++++++++++++++++--------- cinelerra-5.1/cinelerra/fileac3.C | 15 ++++--- cinelerra-5.1/cinelerra/fileffmpeg.C | 2 +- cinelerra-5.1/cinelerra/pluginfclient.C | 14 ++++--- 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C index 1b864bb9..1f7f027e 100644 --- a/cinelerra-5.1/cinelerra/bdwrite.C +++ b/cinelerra-5.1/cinelerra/bdwrite.C @@ -2675,7 +2675,7 @@ int media_info::scan() break; } case AVMEDIA_TYPE_AUDIO: { s->coding_type = bd_coding_type(codec_id); - s->format = bd_audio_format(st->codecpar->channels); + s->format = bd_audio_format(st->codecpar->ch_layout.nb_channels); s->rate = bd_audio_rate(st->codecpar->sample_rate); strcpy((char*)s->lang, "eng"); break; } diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C index bee5c690..8d9a762a 100644 --- a/cinelerra-5.1/cinelerra/ffmpeg.C +++ b/cinelerra-5.1/cinelerra/ffmpeg.C @@ -880,13 +880,17 @@ void FFAudioStream::init_swr(int ichs, int ifmt, int irate) swr_ichs = ichs; swr_ifmt = ifmt; swr_irate = irate; if( ichs == channels && ifmt == AV_SAMPLE_FMT_FLT && irate == sample_rate ) return; - uint64_t ilayout = av_get_default_channel_layout(ichs); - if( !ilayout ) ilayout = ((uint64_t)1<<ichs) - 1; - uint64_t olayout = av_get_default_channel_layout(channels); - if( !olayout ) olayout = ((uint64_t)1<<channels) - 1; - resample_context = swr_alloc_set_opts(NULL, - olayout, AV_SAMPLE_FMT_FLT, sample_rate, - ilayout, (AVSampleFormat)ifmt, irate, + //uint64_t ilayout = av_get_default_channel_layout(ichs); + AVChannelLayout ilayout, olayout; + av_channel_layout_default(&ilayout, ichs); + //if( !ilayout ) ilayout = ((uint64_t)1<<ichs) - 1; + //uint64_t olayout = av_get_default_channel_layout(channels); + av_channel_layout_default(&olayout, channels); + //if( !olayout ) olayout = ((uint64_t)1<<channels) - 1; + + swr_alloc_set_opts2(&resample_context, + &olayout, AV_SAMPLE_FMT_FLT, sample_rate, + &ilayout, (AVSampleFormat)ifmt, irate, 0, NULL); if( resample_context ) swr_init(resample_context); @@ -963,7 +967,11 @@ int FFAudioStream::encode_activate() int64_t FFAudioStream::load_buffer(double ** const sp, int len) { +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,3,100) + reserve(len+1, st->codecpar->ch_layout.nb_channels); +#else reserve(len+1, st->codecpar->channels); +#endif for( int ch=0; ch<nch; ++ch ) write(sp[ch], len, ch); return put_inp(len); @@ -983,7 +991,11 @@ int FFAudioStream::init_frame(AVFrame *frame) { frame->nb_samples = frame_sz; frame->format = avctx->sample_fmt; +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,3,100) + frame->ch_layout.u.mask = avctx->ch_layout.u.mask; +#else frame->channel_layout = avctx->channel_layout; +#endif frame->sample_rate = avctx->sample_rate; int ret = av_frame_get_buffer(frame, 0); if (ret < 0) @@ -1004,7 +1016,7 @@ int FFAudioStream::load(int64_t pos, int len) while( ret>=0 && !flushed && curr_pos<end_pos && --i>=0 ) { ret = read_frame(frame); if( ret > 0 && frame->nb_samples > 0 ) { - init_swr(frame->channels, frame->format, frame->sample_rate); + init_swr(frame->ch_layout.nb_channels, frame->format, frame->sample_rate); load_history(&frame->extended_data[0], frame->nb_samples); curr_pos += frame->nb_samples; } @@ -2780,14 +2792,14 @@ int FFMPEG::open_decoder() ret = vid->create_filter(opt_video_filter); break; } case AVMEDIA_TYPE_AUDIO: { - if( avpar->channels < 1 ) continue; + if( avpar->ch_layout.nb_channels < 1 ) continue; if( avpar->sample_rate < 1 ) continue; has_audio = 1; int aidx = ffaudio.size(); FFAudioStream *aud = new FFAudioStream(this, st, aidx, i); ffaudio.append(aud); aud->channel0 = astrm_index.size(); - aud->channels = avpar->channels; + aud->channels = avpar->ch_layout.nb_channels; for( int ch=0; ch<aud->channels; ++ch ) astrm_index.append(ffidx(aidx, ch)); aud->sample_rate = avpar->sample_rate; @@ -2943,10 +2955,12 @@ int FFMPEG::open_encoder(const char *type, const char *spec) FFAudioStream *aud = new FFAudioStream(this, st, aidx, fidx); aud->avctx = ctx; ffaudio.append(aud); fst = aud; aud->sample_rate = asset->sample_rate; - ctx->channels = aud->channels = asset->channels; + ctx->ch_layout.nb_channels = aud->channels = asset->channels; for( int ch=0; ch<aud->channels; ++ch ) astrm_index.append(ffidx(aidx, ch)); - ctx->channel_layout = av_get_default_channel_layout(ctx->channels); + AVChannelLayout ch_layout; + av_channel_layout_default(&ch_layout, ctx->ch_layout.nb_channels); + ctx->ch_layout.u.mask = ch_layout.u.mask; ctx->sample_rate = check_sample_rate(codec, asset->sample_rate); if( !ctx->sample_rate ) { eprintf(_("check_sample_rate failed %s\n"), filename); @@ -2958,10 +2972,12 @@ int FFMPEG::open_encoder(const char *type, const char *spec) if( sample_fmt == AV_SAMPLE_FMT_NONE ) sample_fmt = codec->sample_fmts ? codec->sample_fmts[0] : AV_SAMPLE_FMT_S16; ctx->sample_fmt = sample_fmt; - uint64_t layout = av_get_default_channel_layout(ctx->channels); - aud->resample_context = swr_alloc_set_opts(NULL, - layout, ctx->sample_fmt, aud->sample_rate, - layout, AV_SAMPLE_FMT_FLT, ctx->sample_rate, + //uint64_t layout = av_get_default_channel_layout(ctx->ch_layout.nb_channels); + AVChannelLayout layout; + av_channel_layout_default(&layout, ctx->ch_layout.nb_channels); + swr_alloc_set_opts2(&aud->resample_context, + &layout, ctx->sample_fmt, aud->sample_rate, + &layout, AV_SAMPLE_FMT_FLT, ctx->sample_rate, 0, NULL); swr_init(aud->resample_context); aud->writing = -1; @@ -3929,7 +3945,7 @@ int FFAudioStream::create_filter(const char *filter_spec) snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%jx", st->time_base.num, st->time_base.den, avpar->sample_rate, - av_get_sample_fmt_name(sample_fmt), avpar->channel_layout); + av_get_sample_fmt_name(sample_fmt), avpar->ch_layout.u.mask); if( ret >= 0 ) { filt_ctx = 0; ret = insert_filter("abuffer", args, "in"); @@ -3947,8 +3963,8 @@ int FFAudioStream::create_filter(const char *filter_spec) AV_OPT_SEARCH_CHILDREN); if( ret >= 0 ) ret = av_opt_set_bin(buffersink_ctx, "channel_layouts", - (uint8_t*)&avpar->channel_layout, - sizeof(avpar->channel_layout), AV_OPT_SEARCH_CHILDREN); + (uint8_t*)&avpar->ch_layout.u.mask, + sizeof(avpar->ch_layout.u.mask), AV_OPT_SEARCH_CHILDREN); if( ret >= 0 ) ret = av_opt_set_bin(buffersink_ctx, "sample_rates", (uint8_t*)&sample_rate, sizeof(sample_rate), @@ -4200,7 +4216,7 @@ printf("audio%d pad %jd %jd (%jd)\n", aud->idx, pos, aud->curr_pos, pos-aud->cur } while( (ret=aud->decode_frame(frame)) > 0 ) { //if( frame->channels != nch ) break; - aud->init_swr(frame->channels, frame->format, frame->sample_rate); + aud->init_swr(frame->ch_layout.nb_channels, frame->format, frame->sample_rate); float *samples; int len = aud->get_samples(samples, &frame->extended_data[0], frame->nb_samples); diff --git a/cinelerra-5.1/cinelerra/fileac3.C b/cinelerra-5.1/cinelerra/fileac3.C index dd3b4536..1f0083f0 100644 --- a/cinelerra-5.1/cinelerra/fileac3.C +++ b/cinelerra-5.1/cinelerra/fileac3.C @@ -142,17 +142,20 @@ int FileAC3::open_file(int rd, int wr) int channels = asset->channels; int sample_rate = asset->sample_rate; int64_t layout = get_channel_layout(channels); + AVChannelLayout ch_layout; + av_channel_layout_from_mask(&ch_layout, layout); int bitrate = asset->ac3_bitrate * 1000; av_init_packet(&avpkt); codec_context = avcodec_alloc_context3(codec); codec_context->bit_rate = bitrate; codec_context->sample_rate = sample_rate; - codec_context->channels = channels; - codec_context->channel_layout = layout; + codec_context->ch_layout.nb_channels = channels; + codec_context->ch_layout.u.mask = layout; codec_context->sample_fmt = codec->sample_fmts[0]; - resample_context = swr_alloc_set_opts(NULL, - layout, codec_context->sample_fmt, sample_rate, - layout, AV_SAMPLE_FMT_S16, sample_rate, + SwrContext *resample_context = NULL; + swr_alloc_set_opts2(&resample_context, + &ch_layout, codec_context->sample_fmt, sample_rate, + &ch_layout, AV_SAMPLE_FMT_S16, sample_rate, 0, NULL); swr_init(resample_context); if(avcodec_open2(codec_context, codec, 0)) @@ -314,7 +317,7 @@ int FileAC3::write_samples(double **buffer, int64_t len) AVFrame *frame = av_frame_alloc(); frame->nb_samples = frame_size; frame->format = avctx->sample_fmt; - frame->channel_layout = avctx->channel_layout; + frame->ch_layout.u.mask = avctx->ch_layout.u.mask; frame->sample_rate = avctx->sample_rate; ret = av_frame_get_buffer(frame, 0); if( ret >= 0 ) { diff --git a/cinelerra-5.1/cinelerra/fileffmpeg.C b/cinelerra-5.1/cinelerra/fileffmpeg.C index 2fbf6c86..abed22da 100644 --- a/cinelerra-5.1/cinelerra/fileffmpeg.C +++ b/cinelerra-5.1/cinelerra/fileffmpeg.C @@ -1493,7 +1493,7 @@ int FFOptions_Opt::types(char *rp) case AV_OPT_TYPE_SAMPLE_FMT: cp = N_("<sample_fmt>"); break; case AV_OPT_TYPE_DURATION: cp = N_("<duration>"); break; case AV_OPT_TYPE_COLOR: cp = N_("<color>"); break; - case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = N_("<channel_layout>"); break; + case AV_OPT_TYPE_CHLAYOUT: cp = N_("<channel_layout>"); break; case AV_OPT_TYPE_BOOL: cp = N_("<bool>"); break; default: cp = N_("<undef>"); break; } diff --git a/cinelerra-5.1/cinelerra/pluginfclient.C b/cinelerra-5.1/cinelerra/pluginfclient.C index 2d57743c..5d4fb659 100644 --- a/cinelerra-5.1/cinelerra/pluginfclient.C +++ b/cinelerra-5.1/cinelerra/pluginfclient.C @@ -453,7 +453,7 @@ int PluginFClient_Opt::types(char *rp) case AV_OPT_TYPE_SAMPLE_FMT: cp = "<sample_fmt>"; break; case AV_OPT_TYPE_DURATION: cp = "<duration>"; break; case AV_OPT_TYPE_COLOR: cp = "<color>"; break; - case AV_OPT_TYPE_CHANNEL_LAYOUT: cp = "<channel_layout>"; break; + case AV_OPT_TYPE_CHLAYOUT: cp = "<channel_layout>"; break; default: cp = "<undef>"; break; } return sprintf(rp, "%s", cp); @@ -664,7 +664,7 @@ PluginFClient::~PluginFClient() bool PluginFClient::is_audio(const AVFilter *fp) { if( !fp->outputs ) return 0; -#if LIBAVFILTER_VERSION_MINOR > 2 && LIBAVFILTER_VERSION_MAJOR > 7 +#if LIBAVFILTER_VERSION_MAJOR > 8 if( avfilter_filter_pad_count(fp, 1) > 1 ) return 0; #else if( avfilter_pad_count(fp->outputs) > 1 ) return 0; @@ -672,7 +672,7 @@ bool PluginFClient::is_audio(const AVFilter *fp) if( !avfilter_pad_get_name(fp->outputs, 0) ) return 0; if( avfilter_pad_get_type(fp->outputs, 0) != AVMEDIA_TYPE_AUDIO ) return 0; if( !fp->inputs ) return 1; -#if LIBAVFILTER_VERSION_MINOR > 2 && LIBAVFILTER_VERSION_MAJOR > 7 +#if LIBAVFILTER_VERSION_MAJOR > 8 if( avfilter_filter_pad_count(fp, 0) > 1 ) return 0; #else if( avfilter_pad_count(fp->inputs) > 1 ) return 0; @@ -684,7 +684,7 @@ bool PluginFClient::is_audio(const AVFilter *fp) bool PluginFClient::is_video(const AVFilter *fp) { if( !fp->outputs ) return 0; -#if LIBAVFILTER_VERSION_MINOR > 2 && LIBAVFILTER_VERSION_MAJOR > 7 +#if LIBAVFILTER_VERSION_MAJOR > 8 if( avfilter_filter_pad_count(fp, 1) > 1 ) return 0; #else if( avfilter_pad_count(fp->outputs) > 1 ) return 0; @@ -692,7 +692,7 @@ bool PluginFClient::is_video(const AVFilter *fp) if( !avfilter_pad_get_name(fp->outputs, 0) ) return 0; if( avfilter_pad_get_type(fp->outputs, 0) != AVMEDIA_TYPE_VIDEO ) return 0; if( !fp->inputs ) return 1; -#if LIBAVFILTER_VERSION_MINOR > 2 && LIBAVFILTER_VERSION_MAJOR > 7 +#if LIBAVFILTER_VERSION_MAJOR > 8 if( avfilter_filter_pad_count(fp, 0) > 1 ) return 0; #else if( avfilter_pad_count(fp->inputs) > 1 ) return 0; @@ -992,7 +992,11 @@ int PluginFAClient::process_buffer(int64_t size, Samples **buffer, int64_t start out_channels = get_outchannels(); frame->nb_samples = size; frame->format = AV_SAMPLE_FMT_FLTP; +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61,3,100) + frame->ch_layout.u.mask = (1<<in_channels)-1; +#else frame->channel_layout = (1<<in_channels)-1; +#endif frame->sample_rate = sample_rate; frame->pts = filter_position; } -- 2.44.0
-- Cin mailing list Cin@lists.cinelerra-gg.org https://lists.cinelerra-gg.org/mailman/listinfo/cin