Skip to content

Commit b31d8f1

Browse files
dimitry-ishenkoJulusian
authored andcommitted
feat: support FFmpeg 8 (#1715)
Inspired by e4f69cb @nxtedition/casparcg
1 parent 6d89bd0 commit b31d8f1

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

src/modules/ffmpeg/consumer/ffmpeg_consumer.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ struct Stream
207207
}
208208

209209
if (codec->type == AVMEDIA_TYPE_VIDEO) {
210-
FF(avfilter_graph_create_filter(
211-
&sink, avfilter_get_by_name("buffersink"), "out", nullptr, nullptr, graph.get()));
210+
sink = FFMEM(avfilter_graph_alloc_filter(graph.get(), avfilter_get_by_name("buffersink"), "out"));
212211

213212
#ifdef _MSC_VER
214213
#pragma warning(push)
@@ -217,20 +216,49 @@ struct Stream
217216
// TODO codec->profiles
218217
// TODO FF(av_opt_set_int_list(sink, "framerates", codec->supported_framerates, { 0, 0 },
219218
// AV_OPT_SEARCH_CHILDREN));
219+
#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg 8
220+
const void* pix_fmts;
221+
int nb_pix_fmts = 0;
222+
FF(avcodec_get_supported_config(nullptr, codec, AV_CODEC_CONFIG_PIX_FORMAT, 0, &pix_fmts, &nb_pix_fmts));
223+
224+
FF(av_opt_set_array(sink, "pixel_formats", AV_OPT_SEARCH_CHILDREN | AV_OPT_ARRAY_REPLACE,
225+
0, nb_pix_fmts, AV_OPT_TYPE_PIXEL_FMT, pix_fmts)
226+
);
227+
#else
220228
FF(av_opt_set_int_list(sink, "pix_fmts", codec->pix_fmts, -1, AV_OPT_SEARCH_CHILDREN));
229+
#endif
230+
221231
#ifdef _MSC_VER
222232
#pragma warning(pop)
223233
#endif
224234
} else if (codec->type == AVMEDIA_TYPE_AUDIO) {
225-
FF(avfilter_graph_create_filter(
226-
&sink, avfilter_get_by_name("abuffersink"), "out", nullptr, nullptr, graph.get()));
235+
sink = FFMEM(avfilter_graph_alloc_filter(graph.get(), avfilter_get_by_name("abuffersink"), "out"));
227236
#ifdef _MSC_VER
228237
#pragma warning(push)
229238
#pragma warning(disable : 4245)
230239
#endif
231240
// TODO codec->profiles
241+
242+
#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg 8
243+
const void* sample_fmts;
244+
int nb_sample_fmts = 0;
245+
FF(avcodec_get_supported_config(nullptr, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, &sample_fmts, &nb_sample_fmts));
246+
247+
FF(av_opt_set_array(sink, "sample_formats", AV_OPT_SEARCH_CHILDREN | AV_OPT_ARRAY_REPLACE,
248+
0, nb_sample_fmts, AV_OPT_TYPE_SAMPLE_FMT, sample_fmts)
249+
);
250+
251+
const void* sample_rates;
252+
int nb_sample_rates = 0;
253+
FF(avcodec_get_supported_config(nullptr, codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0, &sample_rates, &nb_sample_rates));
254+
255+
FF(av_opt_set_array(sink, "samplerates", AV_OPT_SEARCH_CHILDREN | AV_OPT_ARRAY_REPLACE,
256+
0, nb_sample_rates, AV_OPT_TYPE_INT, sample_rates)
257+
);
258+
#else
232259
FF(av_opt_set_int_list(sink, "sample_fmts", codec->sample_fmts, -1, AV_OPT_SEARCH_CHILDREN));
233260
FF(av_opt_set_int_list(sink, "sample_rates", codec->supported_samplerates, 0, AV_OPT_SEARCH_CHILDREN));
261+
#endif
234262

235263
#if FFMPEG_NEW_CHANNEL_LAYOUT
236264
// TODO: need to translate codec->ch_layouts into something that can be passed via av_opt_set_*
@@ -247,6 +275,8 @@ struct Stream
247275
<< boost::errinfo_errno(EINVAL) << msg_info_t("invalid output media type"));
248276
}
249277

278+
FF(avfilter_init_str(sink, nullptr));
279+
250280
{
251281
const auto cur = outputs;
252282

src/modules/ffmpeg/producer/av_producer.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,7 @@ struct Filter
581581
}
582582

583583
if (media_type == AVMEDIA_TYPE_VIDEO) {
584-
FF(avfilter_graph_create_filter(
585-
&sink, avfilter_get_by_name("buffersink"), "out", nullptr, nullptr, graph.get()));
584+
sink = FFMEM(avfilter_graph_alloc_filter(graph.get(), avfilter_get_by_name("buffersink"), "out"));
586585

587586
#ifdef _MSC_VER
588587
#pragma warning(push)
@@ -616,24 +615,39 @@ struct Filter
616615
AV_PIX_FMT_GBRAP,
617616
AV_PIX_FMT_GBRAP16,
618617
AV_PIX_FMT_NONE};
618+
#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg 8
619+
FF(av_opt_set_array(sink, "pixel_formats", AV_OPT_SEARCH_CHILDREN | AV_OPT_ARRAY_REPLACE,
620+
0, FF_ARRAY_ELEMS(pix_fmts) - 1, AV_OPT_TYPE_PIXEL_FMT, pix_fmts)
621+
);
622+
#else
619623
FF(av_opt_set_int_list(sink, "pix_fmts", pix_fmts, -1, AV_OPT_SEARCH_CHILDREN));
624+
#endif
620625
#ifdef _MSC_VER
621626
#pragma warning(pop)
622627
#endif
623628
} else if (media_type == AVMEDIA_TYPE_AUDIO) {
624-
FF(avfilter_graph_create_filter(
625-
&sink, avfilter_get_by_name("abuffersink"), "out", nullptr, nullptr, graph.get()));
629+
sink = FFMEM(avfilter_graph_alloc_filter(graph.get(), avfilter_get_by_name("abuffersink"), "out"));
630+
626631
#ifdef _MSC_VER
627632
#pragma warning(push)
628633
#pragma warning(disable : 4245)
629634
#endif
630635
const AVSampleFormat sample_fmts[] = {AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE};
631-
FF(av_opt_set_int_list(sink, "sample_fmts", sample_fmts, -1, AV_OPT_SEARCH_CHILDREN));
636+
const int sample_rates[] = {format_desc.audio_sample_rate, -1};
632637

633638
FF(av_opt_set_int(sink, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN));
634639

635-
const int sample_rates[] = {format_desc.audio_sample_rate, -1};
640+
#if LIBAVUTIL_VERSION_MAJOR >= 60 // FFmpeg 8
641+
FF(av_opt_set_array(sink, "sample_formats", AV_OPT_SEARCH_CHILDREN | AV_OPT_ARRAY_REPLACE,
642+
0, FF_ARRAY_ELEMS(sample_fmts) - 1, AV_OPT_TYPE_SAMPLE_FMT, sample_fmts)
643+
);
644+
FF(av_opt_set_array(sink, "samplerates", AV_OPT_SEARCH_CHILDREN | AV_OPT_ARRAY_REPLACE,
645+
0, FF_ARRAY_ELEMS(sample_rates) - 1, AV_OPT_TYPE_INT, sample_rates)
646+
);
647+
#else
648+
FF(av_opt_set_int_list(sink, "sample_fmts", sample_fmts, -1, AV_OPT_SEARCH_CHILDREN));
636649
FF(av_opt_set_int_list(sink, "sample_rates", sample_rates, -1, AV_OPT_SEARCH_CHILDREN));
650+
#endif
637651
#ifdef _MSC_VER
638652
#pragma warning(pop)
639653
#endif
@@ -642,6 +656,8 @@ struct Filter
642656
<< boost::errinfo_errno(EINVAL) << msg_info_t("invalid output media type"));
643657
}
644658

659+
FF(avfilter_init_str(sink, nullptr));
660+
645661
// output
646662
{
647663
const auto cur = outputs;

0 commit comments

Comments
 (0)