Index: audio/aqualung/patches/patch-src_decoder_dec_lavc_c
===================================================================
RCS file: audio/aqualung/patches/patch-src_decoder_dec_lavc_c
diff -N audio/aqualung/patches/patch-src_decoder_dec_lavc_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/aqualung/patches/patch-src_decoder_dec_lavc_c	1 Sep 2025 22:05:23 -0000
@@ -0,0 +1,15 @@
+Index: src/decoder/dec_lavc.c
+--- src/decoder/dec_lavc.c.orig
++++ src/decoder/dec_lavc.c
+@@ -360,7 +360,11 @@ lavc_decoder_close(decoder_t * dec) {
+ 
+ 	lavc_pdata_t * pd = (lavc_pdata_t *)dec->pdata;
+ 
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 	avcodec_close(pd->avCodecCtx);
++#else
++	avcodec_free_context(&pd->avCodecCtx);
++#endif
+ 
+ 	avformat_close_input(&pd->avFormatCtx);
+ 
Index: audio/chromaprint/patches/patch-src_audio_ffmpeg_audio_reader_h
===================================================================
RCS file: audio/chromaprint/patches/patch-src_audio_ffmpeg_audio_reader_h
diff -N audio/chromaprint/patches/patch-src_audio_ffmpeg_audio_reader_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/chromaprint/patches/patch-src_audio_ffmpeg_audio_reader_h	1 Sep 2025 19:28:30 -0000
@@ -0,0 +1,15 @@
+Index: src/audio/ffmpeg_audio_reader.h
+--- src/audio/ffmpeg_audio_reader.h.orig
++++ src/audio/ffmpeg_audio_reader.h
+@@ -220,7 +220,11 @@ inline void FFmpegAudioReader::Close() {
+ 	m_stream_index = -1;
+ 
+ 	if (m_codec_ctx) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 		avcodec_close(m_codec_ctx);
++#else
++		avcodec_free_context(&m_codec_ctx);
++#endif
+ 		m_codec_ctx = nullptr;
+ 	}
+ 
Index: audio/cmus/patches/patch-ip_ffmpeg_c
===================================================================
RCS file: audio/cmus/patches/patch-ip_ffmpeg_c
diff -N audio/cmus/patches/patch-ip_ffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/cmus/patches/patch-ip_ffmpeg_c	1 Sep 2025 19:22:02 -0000
@@ -0,0 +1,23 @@
+Index: ip/ffmpeg.c
+--- ip/ffmpeg.c.orig
++++ ip/ffmpeg.c
+@@ -226,7 +226,9 @@ static int ffmpeg_open(struct input_plugin_data *ip_da
+ 	priv->codec = codec;
+ 	priv->input = ffmpeg_input_create();
+ 	if (priv->input == NULL) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 		avcodec_close(cc);
++#endif
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
+ 		avcodec_free_context(&cc);
+ #endif
+@@ -289,7 +291,9 @@ static int ffmpeg_close(struct input_plugin_data *ip_d
+ {
+ 	struct ffmpeg_private *priv = ip_data->private;
+ 
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 	avcodec_close(priv->codec_context);
++#endif
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
+ 	avcodec_free_context(&priv->codec_context);
+ #endif
Index: audio/deadbeef/patches/patch-plugins_ffmpeg_ffmpeg_c
===================================================================
RCS file: audio/deadbeef/patches/patch-plugins_ffmpeg_ffmpeg_c
diff -N audio/deadbeef/patches/patch-plugins_ffmpeg_ffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/deadbeef/patches/patch-plugins_ffmpeg_ffmpeg_c	10 Sep 2025 20:04:45 -0000
@@ -0,0 +1,168 @@
+https://github.com/DeaDBeeF-Player/deadbeef/commit/d4cca5605447122cd080691f43e46047a6039359
+
+Index: plugins/ffmpeg/ffmpeg.c
+--- plugins/ffmpeg/ffmpeg.c.orig
++++ plugins/ffmpeg/ffmpeg.c
+@@ -62,7 +62,7 @@ static int enable_dop = 0;
+ 
+ typedef struct {
+     DB_fileinfo_t info;
+-    AVCodec *codec;
++    const AVCodec *codec;
+     AVCodecContext *codec_context;
+     int need_to_free_codec_context;
+     AVFormatContext *format_context;
+@@ -115,12 +115,20 @@ int is_codec_dsd(enum AVCodecID codec_id) {
+ // ensure that the buffer can contain entire frame of frame_size bytes per channel
+ static int
+ ensure_buffer (ffmpeg_info_t *info, size_t frame_size) {
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++    if (!info->buffer || info->buffer_size < frame_size * info->codec_context->ch_layout.nb_channels) {
++#else
+     if (!info->buffer || info->buffer_size < frame_size * info->codec_context->channels) {
++#endif
+         if (info->buffer) {
+             free (info->buffer);
+             info->buffer = NULL;
+         }
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++        info->buffer_size = frame_size*info->codec_context->ch_layout.nb_channels;
++#else
+         info->buffer_size = frame_size*info->codec_context->channels;
++#endif
+         info->left_in_buffer = 0;
+         int err = posix_memalign ((void **)&info->buffer, 16, info->buffer_size);
+         if (err) {
+@@ -137,7 +145,7 @@ _get_audio_codec_from_stream(AVFormatContext *format_c
+     if (format_context->streams[stream_index]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
+         return 0;
+     }
+-    AVCodec *codec = avcodec_find_decoder(format_context->streams[stream_index]->codecpar->codec_id);
++    const AVCodec *codec = avcodec_find_decoder(format_context->streams[stream_index]->codecpar->codec_id);
+     if (codec == NULL) {
+         return 0;
+     }
+@@ -154,7 +162,7 @@ _get_audio_codec_from_stream(AVFormatContext *format_c
+     if (ctx == NULL) {
+         return 0;
+     }
+-    AVCodec *codec = avcodec_find_decoder (ctx->codec_id);
++    const AVCodec *codec = avcodec_find_decoder (ctx->codec_id);
+     if (codec == NULL) {
+         return 0;
+     }
+@@ -231,7 +239,11 @@ ffmpeg_init (DB_fileinfo_t *_info, DB_playItem_t *it) 
+     int bps = av_get_bytes_per_sample (info->codec_context->sample_fmt)*8;
+     int samplerate = info->codec_context->sample_rate;
+ 
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++    if (bps <= 0 || info->codec_context->ch_layout.nb_channels <= 0 || samplerate <= 0) {
++#else
+     if (bps <= 0 || info->codec_context->channels <= 0 || samplerate <= 0) {
++#endif
+         return -1;
+     }
+ 
+@@ -248,7 +260,11 @@ ffmpeg_init (DB_fileinfo_t *_info, DB_playItem_t *it) 
+     _info->plugin = &plugin.decoder;
+     _info->readpos = 0;
+     _info->fmt.bps = bps;
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++    _info->fmt.channels = info->codec_context->ch_layout.nb_channels;
++#else
+     _info->fmt.channels = info->codec_context->channels;
++#endif
+     _info->fmt.samplerate = samplerate;
+     if (info->codec_context->sample_fmt == AV_SAMPLE_FMT_FLT || info->codec_context->sample_fmt == AV_SAMPLE_FMT_FLTP) {
+         _info->fmt.is_float = 1;
+@@ -296,7 +312,9 @@ _free_info_data(ffmpeg_info_t *info) {
+         av_packet_unref (&info->pkt);
+     }
+     if (info->codec_context) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 0, 0)
+         avcodec_close (info->codec_context);
++#endif
+ 
+         // The ctx is owned by AVFormatContext in legacy mode
+         if (info->need_to_free_codec_context) {
+@@ -396,7 +414,11 @@ ffmpeg_read (DB_fileinfo_t *_info, char *bytes, int si
+                         return -1;
+                     }
+ 
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++                    int chCnt = info->codec_context->ch_layout.nb_channels;
++#else
+                     int chCnt = info->codec_context->channels;
++#endif
+                     int chSize = info->pkt.size / chCnt;
+                     uint32_t *pOut = (uint32_t *)info->buffer;
+                     uint8_t  marker = 0x05;
+@@ -462,25 +484,30 @@ ffmpeg_read (DB_fileinfo_t *_info, char *bytes, int si
+                         return -1;
+                     }
+                     if (av_sample_fmt_is_planar(info->codec_context->sample_fmt)) {
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++                        int chCnt = info->codec_context->ch_layout.nb_channels;
++#else
++                        int chCnt = info->codec_context->channels;
++#endif
+                         out_size = 0;
+-                        for (int c = 0; c < info->codec_context->channels; c++) {
++                        for (int c = 0; c < chCnt; c++) {
+                             for (int i = 0; i < info->frame->nb_samples; i++) {
+                                 if (_info->fmt.bps == 8) {
+-                                    info->buffer[i*info->codec_context->channels+c] = ((int8_t *)info->frame->extended_data[c])[i];
++                                    info->buffer[i*chCnt+c] = ((int8_t *)info->frame->extended_data[c])[i];
+                                     out_size++;
+                                 }
+                                 else if (_info->fmt.bps == 16) {
+                                     int16_t outsample = ((int16_t *)info->frame->extended_data[c])[i];
+-                                    ((int16_t*)info->buffer)[i*info->codec_context->channels+c] = outsample;
++                                    ((int16_t*)info->buffer)[i*chCnt+c] = outsample;
+                                     out_size += 2;
+                                 }
+                                 else if (_info->fmt.bps == 24) {
+-                                    memcpy (&info->buffer[(i*info->codec_context->channels+c)*3], &((int8_t*)info->frame->extended_data[c])[i*3], 3);
++                                    memcpy (&info->buffer[(i*chCnt+c)*3], &((int8_t*)info->frame->extended_data[c])[i*3], 3);
+                                     out_size += 3;
+                                 }
+                                 else if (_info->fmt.bps == 32) {
+                                     int32_t sample = ((int32_t *)info->frame->extended_data[c])[i];
+-                                    ((int32_t*)info->buffer)[i*info->codec_context->channels+c] = sample;
++                                    ((int32_t*)info->buffer)[i*chCnt+c] = sample;
+                                     out_size += 4;
+                                 }
+                             }
+@@ -784,7 +811,11 @@ ffmpeg_insert (ddb_playlist_t *plt, DB_playItem_t *aft
+     trace ("ffmpeg: samplerate is %d\n", samplerate);
+     trace ("ffmpeg: duration is %f\n", duration);
+ 
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++    if (bps <= 0 || info.codec_context->ch_layout.nb_channels <= 0 || samplerate <= 0) {
++#else
+     if (bps <= 0 || info.codec_context->channels <= 0 || samplerate <= 0) {
++#endif
+         goto error;
+     }
+ 
+@@ -819,7 +850,11 @@ ffmpeg_insert (ddb_playlist_t *plt, DB_playItem_t *aft
+         deadbeef->pl_add_meta (it, ":FILE_SIZE", s);
+         snprintf (s, sizeof (s), "%d", bps);
+         deadbeef->pl_add_meta (it, ":BPS", s);
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 0, 0)
++        snprintf (s, sizeof (s), "%d", info.codec_context->ch_layout.nb_channels);
++#else
+         snprintf (s, sizeof (s), "%d", info.codec_context->channels);
++#endif
+         deadbeef->pl_add_meta (it, ":CHANNELS", s);
+         if (is_codec_dsd(info.codec_context->codec_id)) {
+             snprintf (s, sizeof (s), "%d", samplerate * 8);
+@@ -904,7 +939,7 @@ ffmpeg_init_exts (void) {
+         n = add_new_exts (n, new_exts, ';');
+     }
+ 	else {
+-        AVInputFormat *ifmt  = NULL;
++        const AVInputFormat *ifmt  = NULL;
+         /*
+           * It's quite complicated to enumerate all supported extensions in
+          * ffmpeg. If a decoder defines extensions in ffmpeg, the probing
Index: audio/musikcube/patches/patch-src_plugins_ffmpegdecoder_FfmpegDecoder_cpp
===================================================================
RCS file: audio/musikcube/patches/patch-src_plugins_ffmpegdecoder_FfmpegDecoder_cpp
diff -N audio/musikcube/patches/patch-src_plugins_ffmpegdecoder_FfmpegDecoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/musikcube/patches/patch-src_plugins_ffmpegdecoder_FfmpegDecoder_cpp	1 Sep 2025 21:59:12 -0000
@@ -0,0 +1,15 @@
+Index: src/plugins/ffmpegdecoder/FfmpegDecoder.cpp
+--- src/plugins/ffmpegdecoder/FfmpegDecoder.cpp.orig
++++ src/plugins/ffmpegdecoder/FfmpegDecoder.cpp
+@@ -267,7 +267,11 @@ void FfmpegDecoder::Reset() {
+         // avcodec_flush_buffers(this->codecContext);
+         auto stream = this->formatContext->streams[this->streamId];
+         if (stream != nullptr) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+             avcodec_close(this->codecContext);
++#else
++            avcodec_free_context(&this->codecContext);
++#endif
+         }
+ 
+         this->codecContext = nullptr;
Index: audio/pianobar/patches/patch-src_player_c
===================================================================
RCS file: audio/pianobar/patches/patch-src_player_c
diff -N audio/pianobar/patches/patch-src_player_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/pianobar/patches/patch-src_player_c	12 Sep 2025 21:22:51 -0000
@@ -0,0 +1,40 @@
+Index: src/player.c
+--- src/player.c.orig
++++ src/player.c
+@@ -286,7 +286,7 @@ static bool openFilter (player_t * const player) {
+ 			"time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%"PRIx64, 
+ 			time_base.num, time_base.den, cp->sample_rate,
+ 			av_get_sample_fmt_name (player->cctx->sample_fmt),
+-			cp->channel_layout);
++			cp->ch_layout.u.mask);
+ 	if ((ret = avfilter_graph_create_filter (&player->fabuf,
+ 			avfilter_get_by_name ("abuffer"), "source", strbuf, NULL,
+ 			player->fgraph)) < 0) {
+@@ -340,7 +340,7 @@ static bool openDevice (player_t * const player) {
+ 	memset (&aoFmt, 0, sizeof (aoFmt));
+ 	aoFmt.bits = av_get_bytes_per_sample (avformat) * 8;
+ 	assert (aoFmt.bits > 0);
+-	aoFmt.channels = cp->channels;
++	aoFmt.channels = cp->ch_layout.nb_channels;
+ 	aoFmt.rate = getSampleRate (player);
+ 	aoFmt.byte_format = AO_FMT_NATIVE;
+ 
+@@ -508,7 +508,7 @@ static void finish (player_t * const player) {
+ 		player->fgraph = NULL;
+ 	}
+ 	if (player->cctx != NULL) {
+-		avcodec_close (player->cctx);
++		avcodec_free_context (&player->cctx);
+ 		player->cctx = NULL;
+ 	}
+ 	if (player->fctx != NULL) {
+@@ -583,8 +583,7 @@ void *BarAoPlayThread (void *data) {
+ 		}
+ 		pthread_mutex_unlock (&player->aoplayLock);
+ 
+-		const int numChannels = av_get_channel_layout_nb_channels (
+-				filteredFrame->channel_layout);
++		const int numChannels = filteredFrame->ch_layout.nb_channels;
+ 		const int bps = av_get_bytes_per_sample (filteredFrame->format);
+ 		ao_play (player->aoDev, (char *) filteredFrame->data[0],
+ 				filteredFrame->nb_samples * numChannels * bps);
Index: audio/xmms2/patches/patch-src_plugins_avcodec_avcodec_c
===================================================================
RCS file: audio/xmms2/patches/patch-src_plugins_avcodec_avcodec_c
diff -N audio/xmms2/patches/patch-src_plugins_avcodec_avcodec_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ audio/xmms2/patches/patch-src_plugins_avcodec_avcodec_c	2 Sep 2025 07:55:36 -0000
@@ -0,0 +1,39 @@
+Index: src/plugins/avcodec/avcodec.c
+--- src/plugins/avcodec/avcodec.c.orig
++++ src/plugins/avcodec/avcodec.c
+@@ -130,7 +130,11 @@ xmms_avcodec_destroy (xmms_xform_t *xform)
+ 	data = xmms_xform_private_data_get (xform);
+ 	g_return_if_fail (data);
+ 
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 	avcodec_close (data->codecctx);
++#else
++	avcodec_free_context (&data->codecctx);
++#endif
+ 	av_free (data->codecctx);
+ 	av_frame_free (&data->read_out_frame);
+ 
+@@ -251,7 +255,11 @@ xmms_avcodec_init (xmms_xform_t *xform)
+ 			g_string_insert_len (data->outbuf, 0, buf, ret);
+ 		} else {
+ 			XMMS_DBG ("First read failed, codec is not working...");
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 			avcodec_close (data->codecctx);
++#else
++			avcodec_free_context (&data->codecctx);
++#endif
+ 			goto err;
+ 		}
+ 	}
+@@ -260,7 +268,11 @@ xmms_avcodec_init (xmms_xform_t *xform)
+ 	data->channels = XMMS2_AVCODEC_CHANNEL_FIELD(data->codecctx);
+ 	data->sampleformat = xmms_avcodec_translate_sample_format (data->codecctx->sample_fmt);
+ 	if (data->sampleformat == XMMS_SAMPLE_FORMAT_UNKNOWN) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 		avcodec_close (data->codecctx);
++#else
++		avcodec_free_context (&data->codecctx);
++#endif
+ 		goto err;
+ 	}
+ 
Index: emulators/citra/patches/patch-src_citra_qt_dumping_option_set_dialog_cpp
===================================================================
RCS file: emulators/citra/patches/patch-src_citra_qt_dumping_option_set_dialog_cpp
diff -N emulators/citra/patches/patch-src_citra_qt_dumping_option_set_dialog_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ emulators/citra/patches/patch-src_citra_qt_dumping_option_set_dialog_cpp	9 Sep 2025 11:22:53 -0000
@@ -0,0 +1,27 @@
+Index: src/citra_qt/dumping/option_set_dialog.cpp
+--- src/citra_qt/dumping/option_set_dialog.cpp.orig
++++ src/citra_qt/dumping/option_set_dialog.cpp
+@@ -27,7 +27,11 @@ static const std::unordered_map<AVOptionType, const ch
+     {AV_OPT_TYPE_STRING, QT_TR_NOOP("string")},
+     {AV_OPT_TYPE_DICT, QT_TR_NOOP("dictionary")},
+     {AV_OPT_TYPE_VIDEO_RATE, QT_TR_NOOP("video rate")},
++#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 57, 24, 100 )
++    {AV_OPT_TYPE_CHLAYOUT, QT_TR_NOOP("channel layout")},
++#else
+     {AV_OPT_TYPE_CHANNEL_LAYOUT, QT_TR_NOOP("channel layout")},
++#endif
+ }};
+ 
+ static const std::unordered_map<AVOptionType, const char*> TypeDescriptionMap{{
+@@ -39,7 +43,11 @@ static const std::unordered_map<AVOptionType, const ch
+     {AV_OPT_TYPE_DICT,
+      QT_TR_NOOP("Comma-splitted list of &lt;key>=&lt;value>. Do not put spaces.")},
+     {AV_OPT_TYPE_VIDEO_RATE, QT_TR_NOOP("&lt;num>/&lt;den>, or preset values like 'pal'.")},
++#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 57, 24, 100 )
++    {AV_OPT_TYPE_CHLAYOUT, QT_TR_NOOP("Hexadecimal channel layout mask starting with '0x'.")},
++#else
+     {AV_OPT_TYPE_CHANNEL_LAYOUT, QT_TR_NOOP("Hexadecimal channel layout mask starting with '0x'.")},
++#endif
+ }};
+ 
+ /// Get the preset values of an option. returns {display value, real value}
Index: emulators/citra/patches/patch-src_core_dumping_ffmpeg_backend_cpp
===================================================================
RCS file: emulators/citra/patches/patch-src_core_dumping_ffmpeg_backend_cpp
diff -N emulators/citra/patches/patch-src_core_dumping_ffmpeg_backend_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ emulators/citra/patches/patch-src_core_dumping_ffmpeg_backend_cpp	5 Sep 2025 13:55:51 -0000
@@ -0,0 +1,15 @@
+Index: src/core/dumping/ffmpeg_backend.cpp
+--- src/core/dumping/ffmpeg_backend.cpp.orig
++++ src/core/dumping/ffmpeg_backend.cpp
+@@ -956,7 +956,11 @@ std::string FormatDefaultValue(const AVOption* option,
+     case AV_OPT_TYPE_VIDEO_RATE: {
+         return ToStdString(option->default_val.str);
+     }
++#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 57, 24, 100 )
++    case AV_OPT_TYPE_CHLAYOUT: {
++#else
+     case AV_OPT_TYPE_CHANNEL_LAYOUT: {
++#endif
+         return fmt::format("{:#x}", option->default_val.i64);
+     }
+     default:
Index: emulators/dosbox-x/patches/patch-src_hardware_hardware_cpp
===================================================================
RCS file: emulators/dosbox-x/patches/patch-src_hardware_hardware_cpp
diff -N emulators/dosbox-x/patches/patch-src_hardware_hardware_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ emulators/dosbox-x/patches/patch-src_hardware_hardware_cpp	5 Sep 2025 15:18:17 -0000
@@ -0,0 +1,97 @@
+https://github.com/joncampbell123/dosbox-x/commit/d1a6e4d79857455ffee77ed9ac48bff516504f8d
+
+Index: src/hardware/hardware.cpp
+--- src/hardware/hardware.cpp.orig
++++ src/hardware/hardware.cpp
+@@ -58,6 +58,7 @@ extern "C" {
+ #include <libavcodec/avcodec.h>
+ #include <libavformat/avformat.h>
+ #include <libavformat/avio.h>
++#include <libavutil/opt.h>
+ }
+ 
+ /* This code now requires FFMPEG 4 or higher */
+@@ -123,20 +124,18 @@ void ffmpeg_closeall() {
+ 			ffmpeg_avformat_began = false;
+ 		}
+ 		avio_close(ffmpeg_fmt_ctx->pb);
+-		if (ffmpeg_vid_ctx != NULL) avcodec_close(ffmpeg_vid_ctx);
+-		if (ffmpeg_aud_ctx != NULL) avcodec_close(ffmpeg_aud_ctx);
++		if (ffmpeg_vid_ctx != NULL) avcodec_free_context(&ffmpeg_vid_ctx);
++		if (ffmpeg_aud_ctx != NULL) avcodec_free_context(&ffmpeg_aud_ctx);
+ 		avformat_free_context(ffmpeg_fmt_ctx);
+ 		ffmpeg_fmt_ctx = NULL;
+ 		ffmpeg_vid_ctx = NULL; // NTS: avformat_free_context() freed this for us, don't free again
+ 		ffmpeg_aud_ctx = NULL; // NTS: avformat_free_context() freed this for us, don't free again
+ 	}
+ 	if (ffmpeg_vid_ctx != NULL) {
+-		avcodec_close(ffmpeg_vid_ctx);
+ 		avcodec_free_context(&ffmpeg_vid_ctx);
+ 		ffmpeg_vid_ctx = NULL;
+ 	}
+ 	if (ffmpeg_aud_ctx != NULL) {
+-		avcodec_close(ffmpeg_aud_ctx);
+ 		avcodec_free_context(&ffmpeg_aud_ctx);
+ 		ffmpeg_aud_ctx = NULL;
+ 	}
+@@ -171,7 +170,6 @@ void ffmpeg_audio_frame_send() {
+ 
+ 	if (!pkt) E_Exit("Error: Unable to alloc packet");
+ 
+-	ffmpeg_aud_frame->key_frame = 1;
+ 	ffmpeg_aud_frame->pts = (int64_t)ffmpeg_audio_sample_counter;
+ 	r=avcodec_send_frame(ffmpeg_aud_ctx,ffmpeg_aud_frame);
+ 	if (r < 0 && r != AVERROR(EAGAIN))
+@@ -426,7 +424,6 @@ int ffmpeg_bpp_pick_rgb_format(int bpp) {
+ 
+ void ffmpeg_reopen_video(double fps,const int bpp) {
+ 	if (ffmpeg_vid_ctx != NULL) {
+-		avcodec_close(ffmpeg_vid_ctx);
+ 		avcodec_free_context(&ffmpeg_vid_ctx);
+ 		ffmpeg_vid_ctx = NULL;
+ 	}
+@@ -1271,7 +1268,7 @@ skip_shot:
+ 			ffmpeg_aud_ctx->sample_rate = (int)capture.video.audiorate;
+ 			ffmpeg_aud_ctx->flags = 0; // do not use global headers
+ 			ffmpeg_aud_ctx->bit_rate = 320000;
+-			ffmpeg_aud_ctx->profile = FF_PROFILE_AAC_LOW;
++			// ffmpeg_aud_ctx->profile = FF_PROFILE_AAC_LOW;
+ 
+ 			#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59,24,100)
+ 			ffmpeg_aud_ctx->channels = 2;
+@@ -1531,7 +1528,7 @@ skip_shot:
+ 
+ 				// encode it
+ 				ffmpeg_vid_frame->pts = (int64_t)capture.video.frames; // or else libx264 complains about non-monotonic timestamps
+-				ffmpeg_vid_frame->key_frame = ((capture.video.frames % 15) == 0)?1:0;
++                av_opt_set_int(ffmpeg_vid_ctx->priv_data, "g", 15, 0); // GOP size 15
+ 
+ 				r=avcodec_send_frame(ffmpeg_vid_ctx,ffmpeg_vid_frame);
+ 				if (r < 0 && r != AVERROR(EAGAIN))
+@@ -1768,7 +1765,7 @@ skip_mt_wav:
+ }
+ 
+ #pragma pack(push,1)
+-typedef struct pcap_hdr_struct_t {
++typedef struct {
+ 	uint32_t magic_number;   /* magic number */
+ 	uint16_t version_major;  /* major version number */
+ 	uint16_t version_minor;  /* minor version number */
+@@ -1776,14 +1773,14 @@ typedef struct pcap_hdr_struct_t {
+ 	uint32_t sigfigs;        /* accuracy of timestamps */
+ 	uint32_t snaplen;        /* max length of captured packets, in octets */
+ 	uint32_t network;        /* data link type */
+-};
++} pcap_hdr_struct_t;
+ 
+-typedef struct pcaprec_hdr_struct_t {
++typedef struct  {
+ 	uint32_t ts_sec;         /* timestamp seconds */
+ 	uint32_t ts_usec;        /* timestamp microseconds */
+ 	uint32_t incl_len;       /* number of octets of packet saved in file */
+ 	uint32_t orig_len;       /* actual length of packet */
+-};
++} pcaprec_hdr_struct_t;
+ #pragma pack(pop)
+ 
+ void Capture_WritePacket(bool /*send*/,const unsigned char *buf,size_t len) {
Index: emulators/ppsspp/patches/patch-Core_HLE_sceMpeg_cpp
===================================================================
RCS file: /home/cvs/ports/emulators/ppsspp/patches/patch-Core_HLE_sceMpeg_cpp,v
diff -u -p -r1.8 patch-Core_HLE_sceMpeg_cpp
--- emulators/ppsspp/patches/patch-Core_HLE_sceMpeg_cpp	8 Sep 2025 11:37:16 -0000	1.8
+++ emulators/ppsspp/patches/patch-Core_HLE_sceMpeg_cpp	14 Sep 2025 11:34:56 -0000
@@ -12,3 +12,12 @@ Index: Core/HLE/sceMpeg.cpp
  	if (pmp_Codec == NULL){
  		ERROR_LOG(Log::Mpeg, "Can not find H264 codec, please update ffmpeg");
  		return false;
+@@ -928,7 +928,7 @@ static bool decodePmpVideo(PSPPointer<SceMpegRingBuffe
+ 			avcodec_send_packet(pCodecCtx, &packet);
+ 		int len = avcodec_receive_frame(pCodecCtx, pFrame);
+ 		if (len == 0) {
+-			len = pFrame->pkt_size;
++			len = packet.size;
+ 			got_picture = 1;
+ 		} else if (len == AVERROR(EAGAIN)) {
+ 			len = 0;
Index: emulators/ppsspp/patches/patch-Core_HW_MediaEngine_cpp
===================================================================
RCS file: /home/cvs/ports/emulators/ppsspp/patches/patch-Core_HW_MediaEngine_cpp,v
diff -u -p -r1.11 patch-Core_HW_MediaEngine_cpp
--- emulators/ppsspp/patches/patch-Core_HW_MediaEngine_cpp	8 Sep 2025 11:37:16 -0000	1.11
+++ emulators/ppsspp/patches/patch-Core_HW_MediaEngine_cpp	14 Sep 2025 11:34:56 -0000
@@ -3,6 +3,15 @@ Build with newer FFmpeg
 Index: Core/HW/MediaEngine.cpp
 --- Core/HW/MediaEngine.cpp.orig
 +++ Core/HW/MediaEngine.cpp
+@@ -365,7 +365,7 @@ void MediaEngine::closeContext() {
+ 	m_pCodecCtxs.clear();
+ 	// These are streams allocated from avformat_new_stream.
+ 	for (auto &it : m_codecsToClose) {
+-		avcodec_close(it);
++		avcodec_free_context(&it);
+ 	}
+ 	m_codecsToClose.clear();
+ 	if (m_pFormatCtx)
 @@ -406,7 +406,7 @@ bool MediaEngine::addVideoStream(int streamNum, int st
  		// no need to add an existing stream.
  		if ((u32)streamNum < m_pFormatCtx->nb_streams)
@@ -30,3 +39,12 @@ Index: Core/HW/MediaEngine.cpp
  		if (!pCodec) {
  			WARN_LOG_REPORT(Log::ME, "Could not find decoder for %d", (int)stream->codecpar->codec_id);
  			return false;
+@@ -683,7 +683,7 @@ bool MediaEngine::stepVideo(int videoPixelMode, bool s
+ 				avcodec_send_packet(m_pCodecCtx, &packet);
+ 			int result = avcodec_receive_frame(m_pCodecCtx, m_pFrame);
+ 			if (result == 0) {
+-				result = m_pFrame->pkt_size;
++				result = packet.size;
+ 				frameFinished = 1;
+ 			} else if (result == AVERROR(EAGAIN)) {
+ 				result = 0;
Index: emulators/ppsspp/patches/patch-Core_HW_SimpleAudioDec_cpp
===================================================================
RCS file: /home/cvs/ports/emulators/ppsspp/patches/patch-Core_HW_SimpleAudioDec_cpp,v
diff -u -p -r1.7 patch-Core_HW_SimpleAudioDec_cpp
--- emulators/ppsspp/patches/patch-Core_HW_SimpleAudioDec_cpp	8 Sep 2025 11:37:16 -0000	1.7
+++ emulators/ppsspp/patches/patch-Core_HW_SimpleAudioDec_cpp	14 Sep 2025 11:34:56 -0000
@@ -12,3 +12,30 @@ Index: Core/HW/SimpleAudioDec.cpp
  	AVCodecContext  *codecCtx_ = nullptr;
  	SwrContext      *swrCtx_ = nullptr;
  
+@@ -286,7 +286,7 @@ FFmpegAudioDecoder::~FFmpegAudioDecoder() {
+ 	avcodec_free_context(&codecCtx_);
+ #else
+ 	// Future versions may add other things to free, but avcodec_free_context didn't exist yet here.
+-	avcodec_close(codecCtx_);
++	avcodec_free_context(&codecCtx_);
+ 	av_freep(&codecCtx_->extradata);
+ 	av_freep(&codecCtx_->subtitle_header);
+ 	av_freep(&codecCtx_);
+@@ -327,7 +327,7 @@ bool FFmpegAudioDecoder::Decode(const uint8_t *inbuf, 
+ 	int err = avcodec_receive_frame(codecCtx_, frame_);
+ 	int len = 0;
+ 	if (err >= 0) {
+-		len = frame_->pkt_size;
++		len = packet.size;
+ 		got_frame = 1;
+ 	} else if (err != AVERROR(EAGAIN)) {
+ 		len = err;
+@@ -392,7 +392,7 @@ bool FFmpegAudioDecoder::Decode(const uint8_t *inbuf, 
+ 
+ 			if (!swrCtx_ || swr_init(swrCtx_) < 0) {
+ 				ERROR_LOG(Log::ME, "swr_init: Failed to initialize the resampling context");
+-				avcodec_close(codecCtx_);
++				avcodec_free_context(&codecCtx_);
+ 				codec_ = 0;
+ 				return false;
+ 			}
Index: emulators/retroarch/patches/patch-cores_libretro-ffmpeg_ffmpeg_core_c
===================================================================
RCS file: emulators/retroarch/patches/patch-cores_libretro-ffmpeg_ffmpeg_core_c
diff -N emulators/retroarch/patches/patch-cores_libretro-ffmpeg_ffmpeg_core_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ emulators/retroarch/patches/patch-cores_libretro-ffmpeg_ffmpeg_core_c	19 Sep 2025 19:39:18 -0000
@@ -0,0 +1,44 @@
+https://github.com/libretro/RetroArch/commit/21776a2e59f5f5899ff2198c0df25a95b5020012
+
+Index: cores/libretro-ffmpeg/ffmpeg_core.c
+--- cores/libretro-ffmpeg/ffmpeg_core.c.orig
++++ cores/libretro-ffmpeg/ffmpeg_core.c
+@@ -106,6 +106,9 @@ static bool hw_decoding_enabled;
+ static enum AVPixelFormat pix_fmt;
+ static bool force_sw_decoder;
+ #endif
++#ifndef FFMPEG8
++#define FFMPEG8 (LIBAVCODEC_VERSION_MAJOR >= 62)
++#endif
+ 
+ #define MAX_STREAMS 8
+ static AVCodecContext *actx[MAX_STREAMS];
+@@ -2088,17 +2091,28 @@ void CORE_PREFIX(retro_unload_game)(void)
+ 
+    for (i = 0; i < MAX_STREAMS; i++)
+    {
++#if FFMPEG8
+       if (sctx[i])
++         avcodec_free_context(&sctx[i]);
++      if (actx[i])
++         avcodec_free_context(&actx[i]);
++#else
++      if (sctx[i])
+          avcodec_close(sctx[i]);
+       if (actx[i])
+          avcodec_close(actx[i]);
++#endif
+       sctx[i] = NULL;
+       actx[i] = NULL;
+    }
+ 
+    if (vctx)
+    {
++#if FFMPEG8
++      avcodec_free_context(&vctx);
++#else
+       avcodec_close(vctx);
++#endif
+       vctx = NULL;
+    }
+ 
Index: emulators/retroarch/patches/patch-record_drivers_record_ffmpeg_c
===================================================================
RCS file: emulators/retroarch/patches/patch-record_drivers_record_ffmpeg_c
diff -N emulators/retroarch/patches/patch-record_drivers_record_ffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ emulators/retroarch/patches/patch-record_drivers_record_ffmpeg_c	19 Sep 2025 19:39:22 -0000
@@ -0,0 +1,45 @@
+https://github.com/libretro/RetroArch/commit/21776a2e59f5f5899ff2198c0df25a95b5020012
+
+Index: record/drivers/record_ffmpeg.c
+--- record/drivers/record_ffmpeg.c.orig
++++ record/drivers/record_ffmpeg.c
+@@ -72,6 +72,15 @@ extern "C" {
+ #ifndef FFMPEG3
+ #define FFMPEG3 (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100))
+ #endif
++
++#ifndef FFMPEG8
++#define FFMPEG8 (LIBAVCODEC_VERSION_MAJOR >= 62)
++#endif
++
++#ifndef AV_INPUT_BUFFER_MIN_SIZE
++#define AV_INPUT_BUFFER_MIN_SIZE 16384
++#endif
++
+ #define HAVE_CH_LAYOUT (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
+ 
+ struct ff_video_info
+@@ -951,7 +960,11 @@ static void ffmpeg_free(void *data)
+ 
+    if (handle->audio.codec)
+    {
++#if FFMPEG8
++      avcodec_free_context(&handle->audio.codec);
++#else
+       avcodec_close(handle->audio.codec);
++#endif
+       av_free(handle->audio.codec);
+    }
+ 
+@@ -959,7 +972,11 @@ static void ffmpeg_free(void *data)
+ 
+    if (handle->video.codec)
+    {
++#if FFMPEG8
++      avcodec_free_context(&handle->video.codec);
++#else
+       avcodec_close(handle->video.codec);
++#endif
+       av_free(handle->video.codec);
+    }
+ 
Index: games/chiaki/patches/patch-lib_src_ffmpegdecoder_c
===================================================================
RCS file: games/chiaki/patches/patch-lib_src_ffmpegdecoder_c
diff -N games/chiaki/patches/patch-lib_src_ffmpegdecoder_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/chiaki/patches/patch-lib_src_ffmpegdecoder_c	5 Sep 2025 16:20:30 -0000
@@ -0,0 +1,13 @@
+Index: lib/src/ffmpegdecoder.c
+--- lib/src/ffmpegdecoder.c.orig
++++ lib/src/ffmpegdecoder.c
+@@ -99,7 +99,9 @@ error_mutex:
+ 
+ CHIAKI_EXPORT void chiaki_ffmpeg_decoder_fini(ChiakiFfmpegDecoder *decoder)
+ {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 	avcodec_close(decoder->codec_context);
++#endif
+ 	avcodec_free_context(&decoder->codec_context);
+ 	if(decoder->hw_device_ctx)
+ 		av_buffer_unref(&decoder->hw_device_ctx);
Index: games/chiaki/patches/patch-switch_src_io_cpp
===================================================================
RCS file: games/chiaki/patches/patch-switch_src_io_cpp
diff -N games/chiaki/patches/patch-switch_src_io_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/chiaki/patches/patch-switch_src_io_cpp	5 Sep 2025 16:20:30 -0000
@@ -0,0 +1,13 @@
+Index: switch/src/io.cpp
+--- switch/src/io.cpp.orig
++++ switch/src/io.cpp
+@@ -332,7 +332,9 @@ bool IO::FreeVideo()
+ 	// avcodec_alloc_context3(codec);
+ 	if(this->codec_context)
+ 	{
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 		avcodec_close(this->codec_context);
++#endif
+ 		avcodec_free_context(&this->codec_context);
+ 	}
+ 
Index: games/fs2open/patches/patch-code_cutscene_ffmpeg_internal_cpp
===================================================================
RCS file: games/fs2open/patches/patch-code_cutscene_ffmpeg_internal_cpp
diff -N games/fs2open/patches/patch-code_cutscene_ffmpeg_internal_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/fs2open/patches/patch-code_cutscene_ffmpeg_internal_cpp	11 Sep 2025 22:36:03 -0000
@@ -0,0 +1,41 @@
+https://github.com/scp-fs2open/fs2open.github.com/pull/6948/commits/af833f059cc0cfc925792e019f6c2b754c6d53c1
+
+Index: code/cutscene/ffmpeg/internal.cpp
+--- code/cutscene/ffmpeg/internal.cpp.orig
++++ code/cutscene/ffmpeg/internal.cpp
+@@ -12,9 +12,10 @@ DecoderStatus::~DecoderStatus() {
+ 	videoCodec = nullptr;
+ 
+ 	if (videoCodecCtx != nullptr) {
+-		avcodec_close(videoCodecCtx);
+ #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255)
+ 		avcodec_free_context(&videoCodecCtx);
++#else
++		avcodec_close(videoCodecCtx);
+ #endif
+ 		videoCodecCtx = nullptr;
+ 	}
+@@ -24,9 +25,10 @@ DecoderStatus::~DecoderStatus() {
+ 	audioCodec = nullptr;
+ 
+ 	if (audioCodecCtx != nullptr) {
+-		avcodec_close(audioCodecCtx);
+ #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255)
+ 		avcodec_free_context(&audioCodecCtx);
++#else
++		avcodec_close(audioCodecCtx);
+ #endif
+ 		audioCodecCtx = nullptr;
+ 	}
+@@ -36,9 +38,10 @@ DecoderStatus::~DecoderStatus() {
+ 	subtitleCodec = nullptr;
+ 
+ 	if (subtitleCodecCtx != nullptr) {
+-		avcodec_close(subtitleCodecCtx);
+ #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255)
+ 		avcodec_free_context(&subtitleCodecCtx);
++#else
++		avcodec_close(subtitleCodecCtx);
+ #endif
+ 		subtitleCodecCtx = nullptr;
+ 	}
Index: games/fs2open/patches/patch-code_sound_ffmpeg_FFmpegWaveFile_cpp
===================================================================
RCS file: games/fs2open/patches/patch-code_sound_ffmpeg_FFmpegWaveFile_cpp
diff -N games/fs2open/patches/patch-code_sound_ffmpeg_FFmpegWaveFile_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/fs2open/patches/patch-code_sound_ffmpeg_FFmpegWaveFile_cpp	11 Sep 2025 22:36:44 -0000
@@ -0,0 +1,17 @@
+https://github.com/scp-fs2open/fs2open.github.com/pull/6948/commits/af833f059cc0cfc925792e019f6c2b754c6d53c1
+
+Index: code/sound/ffmpeg/FFmpegWaveFile.cpp
+--- code/sound/ffmpeg/FFmpegWaveFile.cpp.orig
++++ code/sound/ffmpeg/FFmpegWaveFile.cpp
+@@ -151,9 +151,10 @@ FFmpegWaveFile::~FFmpegWaveFile()
+ 	av_frame_free(&m_decodeFrame);
+ 
+ 	if (m_audioCodecCtx) {
+-		avcodec_close(m_audioCodecCtx);
+ #if LIBAVCODEC_VERSION_INT > AV_VERSION_INT(57, 24, 255)
+ 		avcodec_free_context(&m_audioCodecCtx);
++#else
++		avcodec_close(m_audioCodecCtx);
+ #endif
+ 		m_audioCodecCtx = nullptr;
+ 	}
Index: games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_cpp
===================================================================
RCS file: games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_cpp
diff -N games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_cpp	19 Sep 2025 21:38:11 -0000
@@ -0,0 +1,229 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: apps/openmw/mwsound/ffmpeg_decoder.cpp
+--- apps/openmw/mwsound/ffmpeg_decoder.cpp.orig
++++ apps/openmw/mwsound/ffmpeg_decoder.cpp
+@@ -8,6 +8,10 @@
+ #include <components/debug/debuglog.hpp>
+ #include <components/vfs/manager.hpp>
+ 
++#if FFMPEG_5_OR_GREATER
++#include <libavutil/channel_layout.h>
++#endif
++
+ namespace MWSound
+ {
+ 
+@@ -29,7 +33,11 @@ int FFmpeg_Decoder::readPacket(void *user_data, uint8_
+     }
+ }
+ 
++#if FFMPEG_CONST_WRITEPACKET
++int FFmpeg_Decoder::writePacket(void*, const uint8_t*, int)
++#else
+ int FFmpeg_Decoder::writePacket(void *, uint8_t *, int)
++#endif
+ {
+     Log(Debug::Error) << "can't write to read-only stream";
+     return -1;
+@@ -124,7 +132,11 @@ bool FFmpeg_Decoder::getAVAudioData()
+             if(!mDataBuf || mDataBufLen < mFrame->nb_samples)
+             {
+                 av_freep(&mDataBuf);
++#if FFMPEG_5_OR_GREATER
++                if (av_samples_alloc(&mDataBuf, nullptr, mOutputChannelLayout.nb_channels,
++#else
+                 if(av_samples_alloc(&mDataBuf, nullptr, av_get_channel_layout_nb_channels(mOutputChannelLayout),
++#endif
+                                     mFrame->nb_samples, mOutputSampleFormat, 0) < 0)
+                     return false;
+                 else
+@@ -159,7 +171,11 @@ size_t FFmpeg_Decoder::readAVAudioData(void *data, siz
+             if(!getAVAudioData())
+                 break;
+             mFramePos = 0;
++#if FFMPEG_5_OR_GREATER
++            mFrameSize = mFrame->nb_samples * mOutputChannelLayout.nb_channels *
++#else
+             mFrameSize = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) *
++#endif
+                          av_get_bytes_per_sample(mOutputSampleFormat);
+         }
+ 
+@@ -256,11 +272,20 @@ void FFmpeg_Decoder::open(const std::string &fname)
+         else
+             mOutputSampleFormat = AV_SAMPLE_FMT_S16;
+ 
++#if FFMPEG_5_OR_GREATER
++        mOutputChannelLayout = (*mStream)->codecpar->ch_layout; // sefault
++        if (mOutputChannelLayout.u.mask == 0)
++            av_channel_layout_default(&mOutputChannelLayout, mCodecCtx->ch_layout.nb_channels);
++
++        mCodecCtx->ch_layout = mOutputChannelLayout;
++#else
+         mOutputChannelLayout = (*mStream)->codecpar->channel_layout;
+         if(mOutputChannelLayout == 0)
+             mOutputChannelLayout = av_get_default_channel_layout(mCodecCtx->channels);
+ 
+         mCodecCtx->channel_layout = mOutputChannelLayout;
++#endif
++
+     }
+     catch(...)
+     {
+@@ -346,42 +371,87 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelC
+         *type = SampleType_Int16;
+     }
+ 
+-    if(mOutputChannelLayout == AV_CH_LAYOUT_MONO)
+-        *chans = ChannelConfig_Mono;
+-    else if(mOutputChannelLayout == AV_CH_LAYOUT_STEREO)
+-        *chans = ChannelConfig_Stereo;
+-    else if(mOutputChannelLayout == AV_CH_LAYOUT_QUAD)
+-        *chans = ChannelConfig_Quad;
+-    else if(mOutputChannelLayout == AV_CH_LAYOUT_5POINT1)
+-        *chans = ChannelConfig_5point1;
+-    else if(mOutputChannelLayout == AV_CH_LAYOUT_7POINT1)
+-        *chans = ChannelConfig_7point1;
+-    else
++#if FFMPEG_5_OR_GREATER
++    switch (mOutputChannelLayout.u.mask)
++#else
++    switch (mOutputChannelLayout)
++#endif
+     {
+-        char str[1024];
+-        av_get_channel_layout_string(str, sizeof(str), mCodecCtx->channels, mCodecCtx->channel_layout);
+-        Log(Debug::Error) << "Unsupported channel layout: "<< str;
+-
+-        if(mCodecCtx->channels == 1)
+-        {
+-            mOutputChannelLayout = AV_CH_LAYOUT_MONO;
++        case AV_CH_LAYOUT_MONO:
+             *chans = ChannelConfig_Mono;
+-        }
+-        else
+-        {
+-            mOutputChannelLayout = AV_CH_LAYOUT_STEREO;
++            break;
++        case AV_CH_LAYOUT_STEREO:
+             *chans = ChannelConfig_Stereo;
+-        }
+-    }
++            break;
++        case AV_CH_LAYOUT_QUAD:
++            *chans = ChannelConfig_Quad;
++            break;
++        case AV_CH_LAYOUT_5POINT1:
++            *chans = ChannelConfig_5point1;
++            break;
++        case AV_CH_LAYOUT_7POINT1:
++            *chans = ChannelConfig_7point1;
++            break;
++        default:
++            char str[1024];
++#if FFMPEG_5_OR_GREATER
++            av_channel_layout_describe(&mCodecCtx->ch_layout, str, sizeof(str));
++            Log(Debug::Error) << "Unsupported channel layout: " << str;
+ 
++            if (mCodecCtx->ch_layout.nb_channels == 1)
++            {
++                mOutputChannelLayout = AV_CHANNEL_LAYOUT_MONO;
++                *chans = ChannelConfig_Mono;
++            }
++            else
++            {
++                mOutputChannelLayout = AV_CHANNEL_LAYOUT_STEREO;
++                *chans = ChannelConfig_Stereo;
++            }
++#else
++            av_get_channel_layout_string(str, sizeof(str), mCodecCtx->channels, mCodecCtx->channel_layout);
++            Log(Debug::Error) << "Unsupported channel layout: " << str;
++
++            if (mCodecCtx->channels == 1)
++            {
++                mOutputChannelLayout = AV_CH_LAYOUT_MONO;
++                *chans = ChannelConfig_Mono;
++            }
++            else
++            {
++                mOutputChannelLayout = AV_CH_LAYOUT_STEREO;
++                *chans = ChannelConfig_Stereo;
++            }
++#endif
++            break;
++    }
+     *samplerate = mCodecCtx->sample_rate;
++#if FFMPEG_5_OR_GREATER
++    AVChannelLayout ch_layout = mCodecCtx->ch_layout;
++    if (ch_layout.u.mask == 0)
++        av_channel_layout_default(&ch_layout, mCodecCtx->ch_layout.nb_channels);
++
++    if (mOutputSampleFormat != mCodecCtx->sample_fmt || mOutputChannelLayout.u.mask != ch_layout.u.mask)
++#else
+     int64_t ch_layout = mCodecCtx->channel_layout;
+     if(ch_layout == 0)
+         ch_layout = av_get_default_channel_layout(mCodecCtx->channels);
+ 
+     if(mOutputSampleFormat != mCodecCtx->sample_fmt ||
+        mOutputChannelLayout != ch_layout)
++#endif
+     {
++#if FFMPEG_5_OR_GREATER
++        swr_alloc_set_opts2(&mSwr,                        // SwrContext
++                            &mOutputChannelLayout,        // output ch layout
++                            mOutputSampleFormat,          // output sample format
++                            mCodecCtx->sample_rate,       // output sample rate
++                            &ch_layout,                   // input ch layout
++                            mCodecCtx->sample_fmt,        // input sample format
++                            mCodecCtx->sample_rate,       // input sample rate
++                            0,                            // logging level offset
++                            nullptr);                     // log context
++#else
+         mSwr = swr_alloc_set_opts(mSwr,                   // SwrContext
+                           mOutputChannelLayout,           // output ch layout
+                           mOutputSampleFormat,            // output sample format
+@@ -391,6 +461,7 @@ void FFmpeg_Decoder::getInfo(int *samplerate, ChannelC
+                           mCodecCtx->sample_rate, // input sample rate
+                           0,                              // logging level offset
+                           nullptr);                          // log context
++#endif
+         if(!mSwr)
+             throw std::runtime_error("Couldn't allocate SwrContext");
+         int init=swr_init(mSwr);
+@@ -419,7 +490,11 @@ void FFmpeg_Decoder::readAll(std::vector<char> &output
+ 
+     while(getAVAudioData())
+     {
++#if FFMPEG_5_OR_GREATER
++        size_t got = mFrame->nb_samples * mOutputChannelLayout.nb_channels *
++#else
+         size_t got = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) *
++#endif
+                      av_get_bytes_per_sample(mOutputSampleFormat);
+         const char *inbuf = reinterpret_cast<char*>(mFrameData[0]);
+         output.insert(output.end(), inbuf, inbuf+got);
+@@ -428,7 +503,11 @@ void FFmpeg_Decoder::readAll(std::vector<char> &output
+ 
+ size_t FFmpeg_Decoder::getSampleOffset()
+ {
++#if FFMPEG_5_OR_GREATER
++    int delay = (mFrameSize - mFramePos) / mOutputChannelLayout.nb_channels /
++#else
+     int delay = (mFrameSize-mFramePos) / av_get_channel_layout_nb_channels(mOutputChannelLayout) /
++#endif
+                 av_get_bytes_per_sample(mOutputSampleFormat);
+     return (int)(mNextPts*mCodecCtx->sample_rate) - delay;
+ }
+@@ -444,7 +523,11 @@ FFmpeg_Decoder::FFmpeg_Decoder(const VFS::Manager* vfs
+   , mNextPts(0.0)
+   , mSwr(nullptr)
+   , mOutputSampleFormat(AV_SAMPLE_FMT_NONE)
++#if FFMPEG_5_OR_GREATER
++        , mOutputChannelLayout({})
++#else
+   , mOutputChannelLayout(0)
++#endif
+   , mDataBuf(nullptr)
+   , mFrameData(nullptr)
+   , mDataBufLen(0)
Index: games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_hpp
===================================================================
RCS file: games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_hpp
diff -N games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_hpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-apps_openmw_mwsound_ffmpeg_decoder_hpp	22 Sep 2025 17:55:44 -0000
@@ -0,0 +1,39 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: apps/openmw/mwsound/ffmpeg_decoder.hpp
+--- apps/openmw/mwsound/ffmpeg_decoder.hpp.orig
++++ apps/openmw/mwsound/ffmpeg_decoder.hpp
+@@ -31,6 +31,9 @@ extern "C"
+ #include "sound_decoder.hpp"
+ 
+ 
++#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
++#define FFMPEG_CONST_WRITEPACKET (LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(60, 12, 100) && !defined(FF_API_AVIO_WRITE_NONCONST))
++
+ namespace MWSound
+ {
+     class FFmpeg_Decoder final : public Sound_Decoder
+@@ -49,7 +52,11 @@ namespace MWSound
+ 
+         SwrContext *mSwr;
+         enum AVSampleFormat mOutputSampleFormat;
++#if FFMPEG_5_OR_GREATER
++        AVChannelLayout mOutputChannelLayout;
++#else
+         int64_t mOutputChannelLayout;
++#endif
+         uint8_t *mDataBuf;
+         uint8_t **mFrameData;
+         int mDataBufLen;
+@@ -59,7 +66,11 @@ namespace MWSound
+         Files::IStreamPtr mDataStream;
+ 
+         static int readPacket(void *user_data, uint8_t *buf, int buf_size);
++#if FFMPEG_CONST_WRITEPACKET
++        static int writePacket(void* user_data, const uint8_t* buf, int buf_size);
++#else
+         static int writePacket(void *user_data, uint8_t *buf, int buf_size);
++#endif
+         static int64_t seek(void *user_data, int64_t offset, int whence);
+ 
+         bool getAVAudioData();
Index: games/openmw/patches/patch-apps_openmw_mwsound_movieaudiofactory_cpp
===================================================================
RCS file: games/openmw/patches/patch-apps_openmw_mwsound_movieaudiofactory_cpp
diff -N games/openmw/patches/patch-apps_openmw_mwsound_movieaudiofactory_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-apps_openmw_mwsound_movieaudiofactory_cpp	19 Sep 2025 21:38:39 -0000
@@ -0,0 +1,17 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: apps/openmw/mwsound/movieaudiofactory.cpp
+--- apps/openmw/mwsound/movieaudiofactory.cpp.orig
++++ apps/openmw/mwsound/movieaudiofactory.cpp
+@@ -44,7 +44,11 @@ namespace MWSound
+ 
+         size_t getSampleOffset()
+         {
++#if FFMPEG_5_OR_GREATER
++            ssize_t clock_delay = (mFrameSize - mFramePos) / mOutputChannelLayout.nb_channels /
++#else
+             ssize_t clock_delay = (mFrameSize-mFramePos) / av_get_channel_layout_nb_channels(mOutputChannelLayout) /
++#endif
+                                   av_get_bytes_per_sample(mOutputSampleFormat);
+             return (size_t)(mAudioClock*mAudioContext->sample_rate) - clock_delay;
+         }
Index: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_cpp
===================================================================
RCS file: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_cpp
diff -N games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_cpp	19 Sep 2025 21:38:36 -0000
@@ -0,0 +1,147 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: extern/osg-ffmpeg-videoplayer/audiodecoder.cpp
+--- extern/osg-ffmpeg-videoplayer/audiodecoder.cpp.orig
++++ extern/osg-ffmpeg-videoplayer/audiodecoder.cpp
+@@ -18,6 +18,10 @@ extern "C"
+     #pragma warning (pop)
+ #endif
+ 
++#if FFMPEG_5_OR_GREATER
++    #include <libavutil/channel_layout.h>
++#endif
++
+ #include "videostate.hpp"
+ 
+ namespace
+@@ -53,7 +57,11 @@ MovieAudioDecoder::MovieAudioDecoder(VideoState* video
+     : mVideoState(videoState)
+     , mAVStream(*videoState->audio_st)
+     , mOutputSampleFormat(AV_SAMPLE_FMT_NONE)
++    #if FFMPEG_5_OR_GREATER
++    , mOutputChannelLayout({})
++    #else
+     , mOutputChannelLayout(0)
++    #endif
+     , mOutputSampleRate(0)
+     , mFramePos(0)
+     , mFrameSize(0)
+@@ -109,21 +117,49 @@ void MovieAudioDecoder::setupFormat()
+ 
+     AVSampleFormat inputSampleFormat = mAudioContext->sample_fmt;
+ 
++#if FFMPEG_5_OR_GREATER
++    AVChannelLayout inputChannelLayout = mAudioContext->ch_layout;
++    if (inputChannelLayout.u.mask != 0)
++        mOutputChannelLayout = inputChannelLayout;
++    else
++        av_channel_layout_default(&mOutputChannelLayout, mAudioContext->ch_layout.nb_channels);
++#else
+     uint64_t inputChannelLayout = mAudioContext->channel_layout;
+     if (inputChannelLayout == 0)
+         inputChannelLayout = av_get_default_channel_layout(mAudioContext->channels);
++#endif
+ 
+     int inputSampleRate = mAudioContext->sample_rate;
+ 
+     mOutputSampleRate = inputSampleRate;
+     mOutputSampleFormat = inputSampleFormat;
++
++#if FFMPEG_5_OR_GREATER
++    adjustAudioSettings(mOutputSampleFormat, mOutputChannelLayout.u.mask, mOutputSampleRate);
++#else
+     mOutputChannelLayout = inputChannelLayout;
+     adjustAudioSettings(mOutputSampleFormat, mOutputChannelLayout, mOutputSampleRate);
++#endif
+ 
+     if (inputSampleFormat != mOutputSampleFormat
++        #if FFMPEG_5_OR_GREATER
++            || inputChannelLayout.u.mask != mOutputChannelLayout.u.mask
++        #else
+             || inputChannelLayout != mOutputChannelLayout
++        #endif
+             || inputSampleRate != mOutputSampleRate)
+     {
++    #if FFMPEG_5_OR_GREATER
++        swr_alloc_set_opts2(&mAudioResampler->mSwr,
++          &mOutputChannelLayout,
++          mOutputSampleFormat,
++          mOutputSampleRate,
++          &inputChannelLayout,
++          inputSampleFormat,
++          inputSampleRate,
++          0,                             // logging level offset
++          nullptr);                      // log context
++    #else
+         mAudioResampler->mSwr = swr_alloc_set_opts(mAudioResampler->mSwr,
+                           mOutputChannelLayout,
+                           mOutputSampleFormat,
+@@ -133,6 +169,8 @@ void MovieAudioDecoder::setupFormat()
+                           inputSampleRate,
+                           0,                             // logging level offset
+                           nullptr);                      // log context
++    #endif
++
+         if(!mAudioResampler->mSwr)
+             fail(std::string("Couldn't allocate SwrContext"));
+         if(swr_init(mAudioResampler->mSwr) < 0)
+@@ -158,7 +196,11 @@ int MovieAudioDecoder::synchronize_audio()
+         if(fabs(avg_diff) >= mAudioDiffThreshold)
+         {
+             int n = av_get_bytes_per_sample(mOutputSampleFormat) *
++        #if FFMPEG_5_OR_GREATER
++                    mOutputChannelLayout.nb_channels;
++        #else
+                     av_get_channel_layout_nb_channels(mOutputChannelLayout);
++        #endif
+             sample_skip = ((int)(diff * mAudioContext->sample_rate) * n);
+         }
+     }
+@@ -204,7 +246,11 @@ int MovieAudioDecoder::audio_decode_frame(AVFrame *fra
+                 if(!mDataBuf || mDataBufLen < frame->nb_samples)
+                 {
+                     av_freep(&mDataBuf);
++    #if FFMPEG_5_OR_GREATER
++                    if(av_samples_alloc(&mDataBuf, nullptr, mOutputChannelLayout.nb_channels,
++    #else
+                     if(av_samples_alloc(&mDataBuf, nullptr, av_get_channel_layout_nb_channels(mOutputChannelLayout),
++    #endif
+                                         frame->nb_samples, mOutputSampleFormat, 0) < 0)
+                         break;
+                     else
+@@ -221,7 +267,11 @@ int MovieAudioDecoder::audio_decode_frame(AVFrame *fra
+             else
+                 mFrameData = &frame->data[0];
+ 
++    #if FFMPEG_5_OR_GREATER
++            int result = frame->nb_samples * mOutputChannelLayout.nb_channels *
++    #else
+             int result = frame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) *
++    #endif
+                     av_get_bytes_per_sample(mOutputSampleFormat);
+ 
+             /* We have data, return it and come back for more later */
+@@ -298,7 +348,11 @@ size_t MovieAudioDecoder::read(char *stream, size_t le
+             len1 = std::min<size_t>(len1, -mFramePos);
+ 
+             int n = av_get_bytes_per_sample(mOutputSampleFormat)
++    #if FFMPEG_5_OR_GREATER
++                    * mOutputChannelLayout.nb_channels;
++    #else
+                     * av_get_channel_layout_nb_channels(mOutputChannelLayout);
++    #endif
+ 
+             /* add samples by copying the first sample*/
+             if(n == 1)
+@@ -348,7 +402,11 @@ int MovieAudioDecoder::getOutputSampleRate() const
+ 
+ uint64_t MovieAudioDecoder::getOutputChannelLayout() const
+ {
++    #if FFMPEG_5_OR_GREATER
++    return mOutputChannelLayout.u.mask;
++    #else
+     return mOutputChannelLayout;
++    #endif
+ }
+ 
+ AVSampleFormat MovieAudioDecoder::getOutputSampleFormat() const
Index: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_hpp
===================================================================
RCS file: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_hpp
diff -N games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_hpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_audiodecoder_hpp	19 Sep 2025 21:38:30 -0000
@@ -0,0 +1,26 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: extern/osg-ffmpeg-videoplayer/audiodecoder.hpp
+--- extern/osg-ffmpeg-videoplayer/audiodecoder.hpp.orig
++++ extern/osg-ffmpeg-videoplayer/audiodecoder.hpp
+@@ -29,6 +29,8 @@ extern "C"
+ typedef SSIZE_T ssize_t;
+ #endif
+ 
++#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
++
+ namespace Video
+ {
+ 
+@@ -43,7 +45,11 @@ class MovieAudioDecoder (protected)
+     AVCodecContext* mAudioContext;
+     AVStream *mAVStream;
+     enum AVSampleFormat mOutputSampleFormat;
++    #if FFMPEG_5_OR_GREATER
++    AVChannelLayout mOutputChannelLayout;
++    #else
+     uint64_t mOutputChannelLayout;
++    #endif
+     int mOutputSampleRate;
+     ssize_t mFramePos;
+     ssize_t mFrameSize;
Index: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_cpp
===================================================================
RCS file: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_cpp
diff -N games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_cpp	19 Sep 2025 21:38:24 -0000
@@ -0,0 +1,17 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: extern/osg-ffmpeg-videoplayer/videostate.cpp
+--- extern/osg-ffmpeg-videoplayer/videostate.cpp.orig
++++ extern/osg-ffmpeg-videoplayer/videostate.cpp
+@@ -243,7 +243,11 @@ int VideoState::istream_read(void *user_data, uint8_t 
+     }
+ }
+ 
++#if FFMPEG_CONST_WRITEPACKET
++int VideoState::istream_write(void *, const unsigned char *, int)
++#else
+ int VideoState::istream_write(void *, uint8_t *, int)
++#endif
+ {
+     throw std::runtime_error("can't write to read-only stream");
+ }
Index: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_hpp
===================================================================
RCS file: games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_hpp
diff -N games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_hpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/openmw/patches/patch-extern_osg-ffmpeg-videoplayer_videostate_hpp	22 Sep 2025 17:55:48 -0000
@@ -0,0 +1,30 @@
+https://github.com/OpenMW/openmw/commit/61cb5b4da638d520c41a9d99b5850384b2e22679
+
+Index: extern/osg-ffmpeg-videoplayer/videostate.hpp
+--- extern/osg-ffmpeg-videoplayer/videostate.hpp.orig
++++ extern/osg-ffmpeg-videoplayer/videostate.hpp
+@@ -42,6 +42,9 @@ extern "C"
+ 
+ #define VIDEO_PICTURE_QUEUE_SIZE 50
+ 
++#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
++#define FFMPEG_CONST_WRITEPACKET (LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(60, 12, 100) && !defined(FF_API_AVIO_WRITE_NONCONST))
++
+ extern "C"
+ {
+     struct SwsContext;
+@@ -155,7 +158,13 @@ struct VideoState {
+     double get_master_clock();
+ 
+     static int istream_read(void *user_data, uint8_t *buf, int buf_size);
+-    static int istream_write(void *user_data, uint8_t *buf, int buf_size);
++
++#if FFMPEG_CONST_WRITEPACKET
++    static int istream_write(void *, const unsigned char *, int);
++#else
++    static int istream_write(void *, uint8_t *, int);
++#endif
++
+     static int64_t istream_seek(void *user_data, int64_t offset, int whence);
+ 
+     osg::ref_ptr<osg::Texture2D> mTexture;
Index: games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp
===================================================================
RCS file: /home/cvs/ports/games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp,v
diff -u -p -r1.4 patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp
--- games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp	19 May 2023 10:57:57 -0000	1.4
+++ games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_cpp	11 Sep 2025 23:28:43 -0000
@@ -9,7 +9,18 @@
 Index: src/arch/MovieTexture/MovieTexture_FFMpeg.cpp
 --- src/arch/MovieTexture/MovieTexture_FFMpeg.cpp.orig
 +++ src/arch/MovieTexture/MovieTexture_FFMpeg.cpp
-@@ -109,6 +109,10 @@ MovieDecoder_FFMpeg::MovieDecoder_FFMpeg()
+@@ -9,6 +9,10 @@
+ 
+ #include <cerrno>
+ 
++#if LIBAVCODEC_VERSION_MAJOR > 59
++#define frame_number frame_num
++#endif
++
+ static void FixLilEndian()
+ {
+ #if defined(ENDIAN_LITTLE)
+@@ -109,6 +113,10 @@ MovieDecoder_FFMpeg::MovieDecoder_FFMpeg()
  {
  	FixLilEndian();
  
@@ -20,7 +31,7 @@ Index: src/arch/MovieTexture/MovieTextur
  	m_fctx = NULL;
  	m_pStream = NULL;
  	m_iCurrentPacketOffset = -1;
-@@ -119,16 +123,37 @@ MovieDecoder_FFMpeg::MovieDecoder_FFMpeg()
+@@ -119,16 +127,37 @@ MovieDecoder_FFMpeg::MovieDecoder_FFMpeg()
  
  MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg()
  {
@@ -58,7 +69,7 @@ Index: src/arch/MovieTexture/MovieTextur
      if (m_avioContext != NULL )
      {
          RageFile *file = (RageFile *)m_avioContext->opaque;
-@@ -136,29 +161,14 @@ MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg()
+@@ -136,29 +165,14 @@ MovieDecoder_FFMpeg::~MovieDecoder_FFMpeg()
          delete file;
          avcodec::av_free(m_avioContext);
      }
@@ -93,7 +104,7 @@ Index: src/arch/MovieTexture/MovieTextur
  }
  
  /* Read until we get a frame, EOF or error.  Return -1 on error, 0 on EOF, 1 if we have a frame. */
-@@ -265,16 +275,23 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTi
+@@ -265,16 +279,23 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTi
  		bool bSkipThisFrame = 
  			fTargetTime != -1 &&
  			GetTimestamp() + GetFrameDuration() < fTargetTime &&
@@ -120,7 +131,7 @@ Index: src/arch/MovieTexture/MovieTextur
  
  		if( len < 0 )
  		{
-@@ -333,9 +350,15 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTi
+@@ -333,9 +354,15 @@ int MovieDecoder_FFMpeg::DecodePacket( float fTargetTi
  
  void MovieDecoder_FFMpeg::GetFrame( RageSurface *pSurface )
  {
@@ -136,7 +147,7 @@ Index: src/arch/MovieTexture/MovieTextur
  
  	/* XXX 1: Do this in one of the Open() methods instead?
  	 * XXX 2: The problem of doing this in Open() is that m_AVTexfmt is not
-@@ -344,12 +367,12 @@ void MovieDecoder_FFMpeg::GetFrame( RageSurface *pSurf
+@@ -344,12 +371,12 @@ void MovieDecoder_FFMpeg::GetFrame( RageSurface *pSurf
  	if( m_swsctx == NULL )
  	{
  		m_swsctx = avcodec::sws_getCachedContext( m_swsctx,
@@ -151,7 +162,7 @@ Index: src/arch/MovieTexture/MovieTextur
  			return;
  		}
  	}
-@@ -384,8 +407,10 @@ void MovieTexture_FFMpeg::RegisterProtocols()
+@@ -384,8 +411,10 @@ void MovieTexture_FFMpeg::RegisterProtocols()
  		return;
  	Done = true;
  
@@ -162,7 +173,7 @@ Index: src/arch/MovieTexture/MovieTextur
  }
  
  static int AVIORageFile_ReadPacket( void *opaque, uint8_t *buf, int buf_size )
-@@ -413,6 +438,8 @@ RString MovieDecoder_FFMpeg::Open( RString sFile )
+@@ -413,6 +442,8 @@ RString MovieDecoder_FFMpeg::Open( RString sFile )
  {
  	MovieTexture_FFMpeg::RegisterProtocols();
      
@@ -171,7 +182,7 @@ Index: src/arch/MovieTexture/MovieTextur
  	m_fctx = avcodec::avformat_alloc_context();
  	if( !m_fctx )
  		return "AVCodec: Couldn't allocate context";
-@@ -444,54 +471,76 @@ RString MovieDecoder_FFMpeg::Open( RString sFile )
+@@ -444,54 +475,84 @@ RString MovieDecoder_FFMpeg::Open( RString sFile )
  		m_fctx->streams[stream_idx] == NULL )
  		return "Couldn't find any video streams";
  	m_pStream = m_fctx->streams[stream_idx];
@@ -219,7 +230,11 @@ Index: src/arch/MovieTexture/MovieTextur
 -	if( m_pStream->codec->codec )
 -		avcodec::avcodec_close( m_pStream->codec );
 +	if( m_pStreamCodec->codec )
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
 +		avcodec::avcodec_close( m_pStreamCodec );
++#else
++		avcodec::avcodec_free_context( &m_pStreamCodec );
++#endif
  
 -	avcodec::AVCodec *pCodec = avcodec::avcodec_find_decoder( m_pStream->codec->codec_id );
 +#if LIBAVCODEC_VERSION_MAJOR >= 59
@@ -261,7 +276,11 @@ Index: src/arch/MovieTexture/MovieTextur
 +	if( m_pStream && m_pStreamCodec->codec )
  	{
 -		avcodec::avcodec_close( m_pStream->codec );
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
 +		avcodec::avcodec_close( m_pStreamCodec );
++#else
++		avcodec::avcodec_free_context( &m_pStreamCodec );
++#endif
  		m_pStream = NULL;
  	}
  
Index: games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h
===================================================================
RCS file: /home/cvs/ports/games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h,v
diff -u -p -r1.3 patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h
--- games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h	19 May 2023 10:57:57 -0000	1.3
+++ games/stepmania/patches/patch-src_arch_MovieTexture_MovieTexture_FFMpeg_h	22 Sep 2025 19:19:04 -0000
@@ -7,7 +7,7 @@
 Index: src/arch/MovieTexture/MovieTexture_FFMpeg.h
 --- src/arch/MovieTexture/MovieTexture_FFMpeg.h.orig
 +++ src/arch/MovieTexture/MovieTexture_FFMpeg.h
-@@ -13,6 +13,22 @@ namespace avcodec
+@@ -13,11 +13,31 @@ namespace avcodec
  		#include <libavformat/avformat.h>
  		#include <libswscale/swscale.h>
  		#include <libavutil/pixdesc.h>
@@ -30,6 +30,15 @@ Index: src/arch/MovieTexture/MovieTextur
  	}
  };
  
+ #define STEPMANIA_FFMPEG_BUFFER_SIZE 4096
++#ifdef SWS_BICUBIC
+ static const int sws_flags = SWS_BICUBIC; // XXX: Reasonable default?
++#else
++static const int sws_flags = avcodec::SWS_BICUBIC; // XXX: Reasonable default?
++#endif
+ 
+ class MovieTexture_FFMpeg: public MovieTexture_Generic
+ {
 @@ -48,8 +64,8 @@ class MovieDecoder_FFMpeg: public MovieDecoder (public
  	void GetFrame( RageSurface *pOut );
  	int DecodeFrame( float fTargetTime );
Index: games/vcmi/patches/patch-client_CVideoHandler_cpp
===================================================================
RCS file: games/vcmi/patches/patch-client_CVideoHandler_cpp
diff -N games/vcmi/patches/patch-client_CVideoHandler_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ games/vcmi/patches/patch-client_CVideoHandler_cpp	12 Sep 2025 08:42:48 -0000
@@ -0,0 +1,25 @@
+https://github.com/vcmi/vcmi/commit/50a4e3213d402227b376dad0a538535e6582564f
+
+Index: client/CVideoHandler.cpp
+--- client/CVideoHandler.cpp.orig
++++ client/CVideoHandler.cpp
+@@ -439,7 +439,9 @@ void CVideoPlayer::close()
+ 
+ 	if (codec)
+ 	{
++#if (LIBAVCODEC_VERSION_MAJOR < 61 )
+ 		avcodec_close(codecContext);
++#endif
+ 		codec = nullptr;
+ 	}
+ 	if (codecContext)
+@@ -597,7 +599,9 @@ std::pair<std::unique_ptr<ui8 []>, si64> CVideoPlayer:
+ 
+ 	if (codecAudio)
+ 	{
++#if (LIBAVCODEC_VERSION_MAJOR < 61 )
+ 		avcodec_close(codecContextAudio);
++#endif
+ 		codecAudio = nullptr;
+ 	}
+ 	if (codecContextAudio)
Index: graphics/arcan/patches/patch-src_frameserver_encode_default_encode_ffmpeg_c
===================================================================
RCS file: graphics/arcan/patches/patch-src_frameserver_encode_default_encode_ffmpeg_c
diff -N graphics/arcan/patches/patch-src_frameserver_encode_default_encode_ffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/arcan/patches/patch-src_frameserver_encode_default_encode_ffmpeg_c	15 Sep 2025 15:03:21 -0000
@@ -0,0 +1,74 @@
+https://github.com/letoram/arcan/commit/e717c1b5833bdc2dea7dc6f64eeaf39c683ebd26
+
+Index: src/frameserver/encode/default/encode_ffmpeg.c
+--- src/frameserver/encode/default/encode_ffmpeg.c.orig
++++ src/frameserver/encode/default/encode_ffmpeg.c
+@@ -22,6 +22,8 @@
+ #include <libavcodec/version.h>
+ #include <libavutil/opt.h>
+ #include <libavutil/imgutils.h>
++#include <libavutil/channel_layout.h>
++
+ #include <libavformat/avformat.h>
+ #include <libswscale/swscale.h>
+ #include <libswresample/swresample.h>
+@@ -70,7 +72,8 @@ static struct {
+ 	const AVCodec* acodec;
+ 	AVStream* astream;
+ 	AVPacket* apacket;
+-	int channel_layout;
++	int64_t anext_pts;
++
+ 	int apts_ofs; /* used to roughly displace A/V
+ 									 synchronisation in encoded frames */
+ 	int silence_samples; /* used to dynamically drop or insert
+@@ -218,18 +221,6 @@ static uint8_t* s16swrconv(int* size, int* nsamp)
+ 	static uint8_t** resamp_outbuf = NULL;
+ 
+ 	if (!resampler){
+-		resampler =
+-			swr_alloc_set_opts(
+-				NULL,
+-				AV_CH_LAYOUT_STEREO,
+-				recctx.acontext->sample_fmt,
+-				recctx.acontext->sample_rate,
+-				AV_CH_LAYOUT_STEREO,
+-				AV_SAMPLE_FMT_S16,
+-				ARCAN_SHMIF_SAMPLERATE, 0, NULL);
+-
+-/*
+- * This is intended to be the 'coming interface' versus the factory above..
+ 		resampler = swr_alloc();
+ 		av_opt_set_chlayout(resampler, "in_chlayout", &recctx.acontext->ch_layout, 0);
+ 		av_opt_set_int(resampler, "in_sample_rate", recctx.acontext->sample_rate, 0);
+@@ -237,7 +228,6 @@ static uint8_t* s16swrconv(int* size, int* nsamp)
+ 		av_opt_set_chlayout(resampler, "out_chlayout", &recctx.acontext->ch_layout, 0);
+ 		av_opt_set_int(resampler, "out_sample_rate", recctx.acontext->sample_rate, 0);
+ 		av_opt_set_sample_fmt(resampler, "out_sample_fmt", recctx.acontext->sample_fmt, 0);
+-	*/
+ 
+ 		resamp_outbuf = av_malloc(sizeof(uint8_t*) * ARCAN_SHMIF_ACHANNELS);
+ 		av_samples_alloc(resamp_outbuf, NULL, ARCAN_SHMIF_ACHANNELS,
+@@ -312,7 +302,7 @@ static bool encode_audio(bool flush)
+ 		exit(EXIT_FAILURE);
+ 	}
+ 
+-	frame->channel_layout = audio->channel_layout;
++	av_channel_layout_copy(&frame->ch_layout, &audio->ch_layout);
+ /*
+  * same as with setup above, this the direct assignment will be
+  * deprecated ..
+@@ -400,10 +390,9 @@ void arcan_frameserver_stepframe()
+ /* interleave audio / video */
+ 	if (recctx.astream && recctx.vstream){
+ 		while(1){
+-			apts = av_stream_get_end_pts(recctx.astream);
+-			vpts = av_stream_get_end_pts(recctx.vstream);
+-
+-			if (apts < vpts){
++			if (av_compare_ts(
++					recctx.aframe_ptscnt, recctx.acontext->time_base,
++					recctx.framecount, recctx.vcontext->time_base) <= 0){
+ 				if (!encode_audio(false))
+ 					break;
+ 			}
Index: graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_c
===================================================================
RCS file: graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_c
diff -N graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_c	15 Sep 2025 15:04:51 -0000
@@ -0,0 +1,52 @@
+https://github.com/letoram/arcan/commit/e717c1b5833bdc2dea7dc6f64eeaf39c683ebd26
+
+Index: src/frameserver/encode/default/encode_presets.c
+--- src/frameserver/encode/default/encode_presets.c.orig
++++ src/frameserver/encode/default/encode_presets.c
+@@ -63,7 +63,7 @@ static bool default_vcodec_setup(struct codec_ent* dst
+ 		dst->storage.video.codec, NULL) != 0){
+ 		dst->storage.video.codec   = NULL;
+ 		dst->storage.video.context = NULL;
+-		avcodec_close(dst->storage.video.context);
++		avcodec_free_context(&dst->storage.video.context);
+ 		return false;
+ 	}
+ 
+@@ -91,12 +91,18 @@ static bool default_acodec_setup(
+ 
+ 	if (avcodec_open2(
+ 		dst->storage.audio.context, dst->storage.audio.codec, NULL) != 0){
+-		avcodec_close(dst->storage.audio.context);
++		avcodec_free_context(&dst->storage.audio.context);
+ 		dst->storage.audio.context = NULL;
+ 		dst->storage.audio.codec   = NULL;
+ 		return false;
+ 	}
+ 
++	av_channel_layout_copy(
++		&ctx->ch_layout,
++		&(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);
++
++/* should sweep codec and find best match for number of channels */
++
+ 	return true;
+ }
+ 
+@@ -175,7 +181,7 @@ static bool setup_cb_x264(struct codec_ent* dst, unsig
+ 
+ 	if (avcodec_open2(dst->storage.video.context,
+ 		dst->storage.video.codec, &opts) != 0){
+-		avcodec_close(dst->storage.video.context);
++		avcodec_free_context(&dst->storage.video.context);
+ 		dst->storage.video.context = NULL;
+ 		dst->storage.video.codec   = NULL;
+ 		return false;
+@@ -241,7 +247,7 @@ static bool setup_cb_vp8(struct codec_ent* dst, unsign
+ 		width, height, fps, vbr / 1024);
+ 	if (avcodec_open2(dst->storage.video.context,
+ 		dst->storage.video.codec, &opts) != 0){
+-		avcodec_close(dst->storage.video.context);
++		avcodec_free_context(&dst->storage.video.context);
+ 		dst->storage.video.context = NULL;
+ 		dst->storage.video.codec   = NULL;
+ 		return false;
Index: graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_h
===================================================================
RCS file: graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_h
diff -N graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/arcan/patches/patch-src_frameserver_encode_default_encode_presets_h	15 Sep 2025 15:03:27 -0000
@@ -0,0 +1,14 @@
+https://github.com/letoram/arcan/commit/e717c1b5833bdc2dea7dc6f64eeaf39c683ebd26
+
+Index: src/frameserver/encode/default/encode_presets.h
+--- src/frameserver/encode/default/encode_presets.h.orig
++++ src/frameserver/encode/default/encode_presets.h
+@@ -29,7 +29,7 @@ struct codec_ent
+ 		} video, audio;
+ 
+ 		struct {
+-			AVOutputFormat*  format;
++			const AVOutputFormat*  format;
+ 			AVFormatContext* context;
+ 		} container;
+ 
Index: graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_cpp
===================================================================
RCS file: graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_cpp
diff -N graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_cpp	15 Sep 2025 10:33:35 -0000
@@ -0,0 +1,71 @@
+https://github.com/blender/blender/commit/ebfad2c071d712d126a5c3d93ebed8a226821feb
+
+Index: extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
+--- extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp.orig
++++ extern/audaspace/plugins/ffmpeg/FFMPEGReader.cpp
+@@ -255,13 +255,7 @@ void FFMPEGReader::init(int stream)
+ 	m_specs.rate = (SampleRate) m_codecCtx->sample_rate;
+ }
+ 
+-FFMPEGReader::FFMPEGReader(const std::string &filename, int stream) :
+-	m_pkgbuf(),
+-	m_formatCtx(nullptr),
+-	m_codecCtx(nullptr),
+-	m_frame(nullptr),
+-	m_aviocontext(nullptr),
+-	m_membuf(nullptr)
++FFMPEGReader::FFMPEGReader(const std::string& filename, int stream) : m_pkgbuf(), m_formatCtx(nullptr), m_codecCtx(nullptr), m_frame(nullptr), m_aviocontext(nullptr)
+ {
+ 	// open file
+ 	if(avformat_open_input(&m_formatCtx, filename.c_str(), nullptr, nullptr)!=0)
+@@ -285,13 +279,15 @@ FFMPEGReader::FFMPEGReader(std::shared_ptr<Buffer> buf
+ 		m_membuffer(buffer),
+ 		m_membufferpos(0)
+ {
+-	m_membuf = reinterpret_cast<data_t*>(av_malloc(AV_INPUT_BUFFER_MIN_SIZE + AV_INPUT_BUFFER_PADDING_SIZE));
++	constexpr int BUFFER_SIZE{4096};
+ 
+-	m_aviocontext = avio_alloc_context(m_membuf, AV_INPUT_BUFFER_MIN_SIZE, 0, this, read_packet, nullptr, seek_packet);
++	auto membuf = reinterpret_cast<data_t*>(av_malloc(BUFFER_SIZE));
+ 
++	m_aviocontext = avio_alloc_context(membuf, BUFFER_SIZE, 0, this, read_packet, nullptr, seek_packet);
++
+ 	if(!m_aviocontext)
+ 	{
+-		av_free(m_aviocontext);
++		av_free(membuf);
+ 		AUD_THROW(FileException, "Buffer reading context couldn't be created with ffmpeg.");
+ 	}
+ 
+@@ -299,6 +295,8 @@ FFMPEGReader::FFMPEGReader(std::shared_ptr<Buffer> buf
+ 	m_formatCtx->pb = m_aviocontext;
+ 	if(avformat_open_input(&m_formatCtx, "", nullptr, nullptr)!=0)
+ 	{
++		if(m_aviocontext->buffer)
++			av_free(m_aviocontext->buffer);
+ 		av_free(m_aviocontext);
+ 		AUD_THROW(FileException, "Buffer couldn't be read with ffmpeg.");
+ 	}
+@@ -310,6 +308,8 @@ FFMPEGReader::FFMPEGReader(std::shared_ptr<Buffer> buf
+ 	catch(Exception&)
+ 	{
+ 		avformat_close_input(&m_formatCtx);
++		if(m_aviocontext->buffer)
++			av_free(m_aviocontext->buffer);
+ 		av_free(m_aviocontext);
+ 		throw;
+ 	}
+@@ -325,6 +325,13 @@ FFMPEGReader::~FFMPEGReader()
+ 	if(m_codecCtx)
+ 		avcodec_free_context(&m_codecCtx);
+ #endif
++	if(m_aviocontext)
++	{
++		if(m_aviocontext->buffer)
++			av_free(m_aviocontext->buffer);
++		av_free(m_aviocontext);
++	}
++
+ 	avformat_close_input(&m_formatCtx);
+ }
+ 
Index: graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_h
===================================================================
RCS file: graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_h
diff -N graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/blender/patches/patch-extern_audaspace_plugins_ffmpeg_FFMPEGReader_h	15 Sep 2025 10:33:40 -0000
@@ -0,0 +1,17 @@
+https://github.com/blender/blender/commit/ebfad2c071d712d126a5c3d93ebed8a226821feb
+
+Index: extern/audaspace/plugins/ffmpeg/FFMPEGReader.h
+--- extern/audaspace/plugins/ffmpeg/FFMPEGReader.h.orig
++++ extern/audaspace/plugins/ffmpeg/FFMPEGReader.h
+@@ -107,11 +107,6 @@ class AUD_PLUGIN_API FFMPEGReader : public IReader (pr
+ 	std::shared_ptr<Buffer> m_membuffer;
+ 
+ 	/**
+-	 * The buffer to read with.
+-	 */
+-	data_t* m_membuf;
+-
+-	/**
+ 	 * Reading position of the buffer.
+ 	 */
+ 	long long m_membufferpos;
Index: graphics/blender/patches/patch-source_blender_imbuf_movie_intern_movie_write_audio_cc
===================================================================
RCS file: graphics/blender/patches/patch-source_blender_imbuf_movie_intern_movie_write_audio_cc
diff -N graphics/blender/patches/patch-source_blender_imbuf_movie_intern_movie_write_audio_cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/blender/patches/patch-source_blender_imbuf_movie_intern_movie_write_audio_cc	12 Sep 2025 16:52:31 -0000
@@ -0,0 +1,24 @@
+https://github.com/blender/blender/commit/f5f30131131025a24be93eced7d04f9d96cf5cbf
+
+Index: source/blender/imbuf/movie/intern/movie_write_audio.cc
+--- source/blender/imbuf/movie/intern/movie_write_audio.cc.orig
++++ source/blender/imbuf/movie/intern/movie_write_audio.cc
+@@ -323,12 +323,12 @@ AVStream *alloc_audio_stream(MovieWriter *context,
+   c->time_base.num = 1;
+   c->time_base.den = c->sample_rate;
+ 
+-  if (c->frame_size == 0) {
+-    /* Used to be if ((c->codec_id >= CODEC_ID_PCM_S16LE) && (c->codec_id <= CODEC_ID_PCM_DVD))
+-     * not sure if that is needed anymore, so let's try out if there are any
+-     * complaints regarding some FFMPEG versions users might have. */
+-    context->audio_input_samples = AV_INPUT_BUFFER_MIN_SIZE * 8 / c->bits_per_coded_sample /
+-                                   audio_channels;
++  if (c->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) {
++    /* If the audio format has a variable frame size, default to 1024.
++     * This is because we won't try to encode any variable frame size.
++     * 1024 seems to be a good compromize between size and speed.
++     */
++    context->audio_input_samples = 1024;
+   }
+   else {
+     context->audio_input_samples = c->frame_size;
Index: graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_moviedecoder_cpp
===================================================================
RCS file: graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_moviedecoder_cpp
diff -N graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_moviedecoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_moviedecoder_cpp	1 Sep 2025 15:16:03 -0000
@@ -0,0 +1,60 @@
+https://github.com/dirkvdb/ffmpegthumbnailer/pull/240
+
+Index: libffmpegthumbnailer/moviedecoder.cpp
+--- libffmpegthumbnailer/moviedecoder.cpp.orig
++++ libffmpegthumbnailer/moviedecoder.cpp
+@@ -406,7 +406,7 @@ void MovieDecoder::initializeFilterGraph(const AVRatio
+             "Failed to create filter sink");
+ 
+     AVFilterContext* yadifFilter = nullptr;
+-    if (m_pFrame->interlaced_frame != 0)
++    if (m_pFrame->flags & AV_FRAME_FLAG_INTERLACED)
+     {
+         checkRc(avfilter_graph_create_filter(&yadifFilter, avfilter_get_by_name("yadif"), "thumb_deint", "deint=1", nullptr, m_pFilterGraph),
+                 "Failed to create deinterlace filter");
+@@ -518,7 +518,7 @@ void MovieDecoder::seek(int timeInSeconds)
+         }
+ 
+         ++keyFrameAttempts;
+-    } while ((!gotFrame || !m_pFrame->key_frame) && keyFrameAttempts < 200);
++    } while ((!gotFrame || !(m_pFrame->flags & AV_FRAME_FLAG_KEY)) && keyFrameAttempts < 200); 
+ 
+     if (gotFrame == 0)
+     {
+@@ -655,20 +655,27 @@ void MovieDecoder::checkRc(int ret, const std::string&
+ 
+ int32_t MovieDecoder::getStreamRotation()
+ {
+-    auto matrix = reinterpret_cast<int32_t*>(av_stream_get_side_data(m_pVideoStream, AV_PKT_DATA_DISPLAYMATRIX, nullptr));
+-    if (matrix)
+-    {
++    if (!m_pVideoStream || !m_pVideoStream->codecpar) {
++        return -1;
++    }
++
++    // For FFmpeg 5.0+
++    const AVPacketSideData* side_data = av_packet_side_data_get(
++        m_pVideoStream->codecpar->coded_side_data,
++        m_pVideoStream->codecpar->nb_coded_side_data,
++        AV_PKT_DATA_DISPLAYMATRIX
++    );
++
++    if (side_data && side_data->size >= sizeof(int32_t) * 9) {
++        const int32_t* matrix = reinterpret_cast<const int32_t*>(side_data->data);
+         auto angle = lround(av_display_rotation_get(matrix));
+-        if (angle < -135)
+-        {
++        if (angle < -135) {
+             return 3;
+         }
+-        else if (angle > 45 && angle < 135)
+-        {
++        else if (angle > 45 && angle < 135) {
+             return 2;
+         }
+-        else if (angle < -45 && angle > -135)
+-        {
++        else if (angle < -45 && angle > -135) {
+             return 1;
+         }
+     }
Index: graphics/opencv/patches/patch-modules_videoio_src_cap_ffmpeg_impl_hpp
===================================================================
RCS file: graphics/opencv/patches/patch-modules_videoio_src_cap_ffmpeg_impl_hpp
diff -N graphics/opencv/patches/patch-modules_videoio_src_cap_ffmpeg_impl_hpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/opencv/patches/patch-modules_videoio_src_cap_ffmpeg_impl_hpp	4 Sep 2025 14:41:12 -0000
@@ -0,0 +1,35 @@
+https://github.com/opencv/opencv/commit/90c444abd387ffa70b2e72a34922903a2f0f4f5a
+
+Index: modules/videoio/src/cap_ffmpeg_impl.hpp
+--- modules/videoio/src/cap_ffmpeg_impl.hpp.orig
++++ modules/videoio/src/cap_ffmpeg_impl.hpp
+@@ -685,7 +685,10 @@ void CvCapture_FFMPEG::close()
+     if( video_st )
+     {
+ #ifdef CV_FFMPEG_CODECPAR
++// avcodec_close removed in FFmpeg release 8.0
++# if (LIBAVCODEC_BUILD < CALC_FFMPEG_VERSION(62, 11, 100))
+         avcodec_close( context );
++# endif
+ #endif
+         video_st = NULL;
+     }
+@@ -2005,7 +2008,18 @@ void CvCapture_FFMPEG::get_rotation_angle()
+     rotation_angle = 0;
+ #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(57, 68, 100)
+     const uint8_t *data = 0;
++    // av_stream_get_side_data removed in FFmpeg release 8.0
++# if (LIBAVCODEC_BUILD < CALC_FFMPEG_VERSION(62, 11, 100))
+     data = av_stream_get_side_data(video_st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
++# else
++    AVPacketSideData* sd = video_st->codecpar->coded_side_data;
++    int nb_sd = video_st->codecpar->nb_coded_side_data;
++    if (sd && nb_sd > 0)
++    {
++        const AVPacketSideData* mtx = av_packet_side_data_get(sd,  nb_sd, AV_PKT_DATA_DISPLAYMATRIX);
++        data = mtx->data;
++    }
++# endif
+     if (data)
+     {
+         rotation_angle = -cvRound(av_display_rotation_get((const int32_t*)data));
Index: graphics/openimageio/patches/patch-src_ffmpeg_imageio_ffmpeginput_cpp
===================================================================
RCS file: graphics/openimageio/patches/patch-src_ffmpeg_imageio_ffmpeginput_cpp
diff -N graphics/openimageio/patches/patch-src_ffmpeg_imageio_ffmpeginput_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ graphics/openimageio/patches/patch-src_ffmpeg_imageio_ffmpeginput_cpp	2 Sep 2025 08:17:44 -0000
@@ -0,0 +1,15 @@
+Index: src/ffmpeg.imageio/ffmpeginput.cpp
+--- src/ffmpeg.imageio/ffmpeginput.cpp.orig
++++ src/ffmpeg.imageio/ffmpeginput.cpp
+@@ -581,7 +581,11 @@ bool
+ FFmpegInput::close(void)
+ {
+     if (m_codec_context)
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+         avcodec_close(m_codec_context);
++#else
++        avcodec_free_context(&m_codec_context);
++#endif
+     if (m_format_context) {
+         avformat_close_input(&m_format_context);
+         av_free(m_format_context);  // will free m_codec and m_codec_context
Index: graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp
===================================================================
RCS file: /home/cvs/ports/graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp,v
diff -u -p -r1.1 patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp
--- graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp	1 Nov 2024 09:51:59 -0000	1.1
+++ graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderAudio_cpp	10 Sep 2025 21:45:07 -0000
@@ -19,7 +19,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  namespace osgFFmpeg {
  
  static int decode_audio(AVCodecContext *avctx, int16_t *samples,
-@@ -32,25 +23,23 @@ static int decode_audio(AVCodecContext *avctx, int16_t
+@@ -32,26 +23,28 @@ static int decode_audio(AVCodecContext *avctx, int16_t
                           int out_nb_channels,
                           AVSampleFormat out_sample_format)
  {
@@ -45,11 +45,34 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
 +    if (ret >= 0) {
  #else
 -    if (ret >= 0 && got_frame && av_frame_get_channels(frame)>0) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
 +    if (ret >= 0 && frame->channels>0) {
++#else
++    if (ret >= 0 && frame->ch_layout.nb_channels>0) {
  #endif
++#endif
          int ch, plane_size;
          int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
-@@ -108,11 +97,6 @@ static int decode_audio(AVCodecContext *avctx, int16_t
+ 
+@@ -92,9 +85,15 @@ static int decode_audio(AVCodecContext *avctx, int16_t
+ 
+             memcpy(samples, frame->extended_data[0], plane_size);
+ 
+-            if (planar && avctx->channels > 1) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
++            int _channels = avctx->channels;
++#else
++            int _channels = avctx->ch_layout.nb_channels;
++#endif
++
++            if (planar && _channels > 1) {
+                 uint8_t *out = ((uint8_t *)samples) + plane_size;
+-                for (ch = 1; ch < avctx->channels; ch++) {
++                for (ch = 1; ch < _channels; ch++) {
+                     memcpy(out, frame->extended_data[ch], plane_size);
+                     out += plane_size;
+                 }
+@@ -108,11 +107,6 @@ static int decode_audio(AVCodecContext *avctx, int16_t
      }
      av_frame_free(&frame);
      return ret;
@@ -61,7 +84,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  }
  
  
-@@ -151,7 +135,9 @@ void FFmpegDecoderAudio::open(AVStream * const stream,
+@@ -151,10 +145,16 @@ void FFmpegDecoderAudio::open(AVStream * const stream,
              return;
  
          m_stream = stream;
@@ -71,8 +94,46 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
 +        m_context = avcodec_alloc_context3(p_codec);
  
          m_in_sample_rate = m_context->sample_rate;
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
          m_in_nb_channels = m_context->channels;
-@@ -214,7 +200,7 @@ printf("### CONVERTING from sample format %s TO %s\n\t
++#else
++        m_in_nb_channels = m_context->ch_layout.nb_channels;
++#endif
+         m_in_sample_format = m_context->sample_fmt;
+ 
+         AVDictionaryEntry *opt_out_sample_rate = av_dict_get( *parameters->getOptions(), "out_sample_rate", NULL, 0 );
+@@ -189,16 +189,30 @@ printf("### CONVERTING from sample format %s TO %s\n\t
+             m_in_sample_rate,
+             m_out_sample_rate);
+ #endif
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
+             m_swr_context = swr_alloc_set_opts(NULL,
+                     av_get_default_channel_layout(m_out_nb_channels),
++#else
++            int err = swr_alloc_set_opts2(&m_swr_context,
++                    &m_context->ch_layout,
++#endif
+                     m_out_sample_format,
+                     m_out_sample_rate,
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
+                     av_get_default_channel_layout(m_in_nb_channels),
++#else
++                    &m_context->ch_layout,
++#endif
+                     m_in_sample_format,
+                     m_in_sample_rate,
+                     0, NULL );
+ 
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
+             int err = swr_init(m_swr_context);
++#else
++            if ( !err )
++                err = swr_init(m_swr_context);
++#endif
+ 
+             if ( err ) {
+                 char error_string[512];
+@@ -214,7 +228,7 @@ printf("### CONVERTING from sample format %s TO %s\n\t
              throw std::runtime_error("invalid audio codec");;
  
          // Find the decoder for the audio stream
Index: graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp
===================================================================
RCS file: /home/cvs/ports/graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp,v
diff -u -p -r1.1 patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp
--- graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp	1 Nov 2024 09:51:59 -0000	1.1
+++ graphics/openscenegraph/patches/patch-src_osgPlugins_ffmpeg_FFmpegDecoderVideo_cpp	10 Sep 2025 21:47:27 -0000
@@ -3,7 +3,19 @@ Fix building with newer FFmpeg
 Index: src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
 --- src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp.orig
 +++ src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
-@@ -62,7 +62,9 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
+@@ -51,7 +51,11 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
+ 
+     if (m_context)
+     {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+         avcodec_close(m_context);
++#else
++        avcodec_free_context(&m_context);
++#endif
+     }
+ 
+     OSG_INFO<<"Destructed FFmpegDecoderVideo"<<std::endl;
+@@ -62,7 +66,9 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
  void FFmpegDecoderVideo::open(AVStream * const stream)
  {
      m_stream = stream;
@@ -14,7 +26,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  
      // Trust the video size given at this point
      // (avcodec_open seems to sometimes return a 0x0 size)
-@@ -74,11 +76,7 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
+@@ -74,11 +80,7 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
      m_alpha_channel = (m_context->pix_fmt == AV_PIX_FMT_YUVA420P);
  
      // Find out the framerate
@@ -26,7 +38,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  
      // Find the decoder for the video stream
      m_codec = avcodec_find_decoder(m_context->codec_id);
-@@ -99,11 +97,12 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
+@@ -99,11 +101,12 @@ void FFmpegDecoderVideo::open(AVStream * const stream)
  
      // Allocate converted RGB frame
      m_frame_rgba.reset(av_frame_alloc());
@@ -41,7 +53,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  
      // Override get_buffer()/release_buffer() from codec context in order to retrieve the PTS of each frame.
      m_context->opaque = this;
-@@ -169,7 +168,7 @@ void FFmpegDecoderVideo::decodeLoop()
+@@ -169,7 +172,7 @@ void FFmpegDecoderVideo::decodeLoop()
              int frame_finished = 0;
  
              // We want to use the entire packet since some codecs will require extra information for decoding
@@ -50,7 +62,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  
              if (bytes_decoded < 0)
                  throw std::runtime_error("avcodec_decode_video failed()");
-@@ -180,40 +179,9 @@ void FFmpegDecoderVideo::decodeLoop()
+@@ -180,40 +183,9 @@ void FFmpegDecoderVideo::decodeLoop()
              // Publish the frame if we have decoded a complete frame
              if (frame_finished)
              {
@@ -91,7 +103,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
                      pts = av_q2d(m_stream->time_base) * m_frame->pts;
                  }
                  else if (packet.packet.dts == int64_t(AV_NOPTS_VALUE) &&
-@@ -230,7 +198,6 @@ void FFmpegDecoderVideo::decodeLoop()
+@@ -230,7 +202,6 @@ void FFmpegDecoderVideo::decodeLoop()
                  {
                      pts = 0;
                  }
@@ -99,7 +111,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
                  const double synched_pts = m_clocks.videoSynchClock(m_frame.get(), av_q2d(av_inv_q(m_context->framerate)), pts);
                  const double frame_delay = m_clocks.videoRefreshSchedule(synched_pts);
  
-@@ -283,7 +250,7 @@ void FFmpegDecoderVideo::findAspectRatio()
+@@ -283,7 +254,7 @@ void FFmpegDecoderVideo::findAspectRatio()
      m_pixel_aspect_ratio = ratio;
  }
  
@@ -108,7 +120,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
              int src_pix_fmt, int src_width, int src_height)
  {
      osg::Timer_t startTick = osg::Timer::instance()->tick();
-@@ -334,11 +301,11 @@ void FFmpegDecoderVideo::publishFrame(const double del
+@@ -334,11 +305,11 @@ void FFmpegDecoderVideo::publishFrame(const double del
          return;
  #endif
  
@@ -123,7 +135,7 @@ Index: src/osgPlugins/ffmpeg/FFmpegDecod
  
      // Convert YUVA420p (i.e. YUV420p plus alpha channel) using our own routine
  
-@@ -370,7 +337,7 @@ void FFmpegDecoderVideo::publishFrame(const double del
+@@ -370,7 +341,7 @@ void FFmpegDecoderVideo::publishFrame(const double del
  
  
  
Index: multimedia/dvdstyler/patches/patch-src_mediaenc_ffmpeg_cpp
===================================================================
RCS file: /home/cvs/ports/multimedia/dvdstyler/patches/patch-src_mediaenc_ffmpeg_cpp,v
diff -u -p -r1.5 patch-src_mediaenc_ffmpeg_cpp
--- multimedia/dvdstyler/patches/patch-src_mediaenc_ffmpeg_cpp	19 May 2023 10:43:55 -0000	1.5
+++ multimedia/dvdstyler/patches/patch-src_mediaenc_ffmpeg_cpp	15 Sep 2025 12:33:00 -0000
@@ -1,5 +1,6 @@
 - fixed encoding of silent audio file
 - added support of ffmpeg5
+- https://sourceforge.net/p/dvdstyler/DVDStyler/ci/4e8e4aae705a9c4c7958e584015c4c1e222e96c8/
 
 Index: src/mediaenc_ffmpeg.cpp
 --- src/mediaenc_ffmpeg.cpp.orig
@@ -130,7 +131,20 @@ Index: src/mediaenc_ffmpeg.cpp
  	if (!encoder) {
  		wxLogError(wxT("Video codec not found"));
  		return false;
-@@ -252,25 +265,21 @@ bool wxFfmpegMediaEncoder::addAudioStream(int codecId)
+@@ -211,7 +224,11 @@ bool wxFfmpegMediaEncoder::addVideoStream(int codecId,
+ 	m_videoOutbuf = (uint8_t*) av_malloc(VIDEO_BUF_SIZE);
+ 
+ 	AVCPBProperties *props;
+-	props = (AVCPBProperties*) av_stream_new_side_data(m_videoStm, AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props));
++	const AVPacketSideData *sd = av_packet_side_data_new(
++		&m_videoStm->codecpar->coded_side_data,
++		&m_videoStm->codecpar->nb_coded_side_data,
++		AV_PKT_DATA_CPB_PROPERTIES, sizeof(*props), 0);
++	props = (AVCPBProperties*) sd->data;
+ 	props->buffer_size = VIDEO_BUF_SIZE;
+ 	props->max_bitrate = 0;
+ 	props->min_bitrate = 0;
+@@ -252,25 +269,21 @@ bool wxFfmpegMediaEncoder::addAudioStream(int codecId)
  		m_audioStm = NULL;
  		return true;
  	}
@@ -166,7 +180,7 @@ Index: src/mediaenc_ffmpeg.cpp
  	} else {
  		sampleFmt = AV_SAMPLE_FMT_S16;
   		encoder = avcodec_find_encoder((AVCodecID) codecId );
-@@ -285,54 +294,52 @@ bool wxFfmpegMediaEncoder::addAudioStream(int codecId)
+@@ -285,54 +298,60 @@ bool wxFfmpegMediaEncoder::addAudioStream(int codecId)
  
  	AVCodecContext* c = m_audioCodec;
  	c->thread_count = m_threadCount;
@@ -175,22 +189,29 @@ Index: src/mediaenc_ffmpeg.cpp
  	c->bit_rate = 64000;
  	c->sample_rate = 48000;
  	c->sample_fmt = sampleFmt;
- 	c->channels = 2;
- 	c->channel_layout = AV_CH_LAYOUT_STEREO;
+-	c->channels = 2;
+-	c->channel_layout = AV_CH_LAYOUT_STEREO;
 -	c->time_base = (AVRational){ 1, c->sample_rate };
 -	// some formats want stream headers to be separate
 -	if(m_outputCtx->oformat->flags & AVFMT_GLOBALHEADER)
 -	    c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
++	AVChannelLayout chLayoutStereo;
++	av_channel_layout_default(&chLayoutStereo, 2);
++	if (av_channel_layout_copy(&c->ch_layout, &chLayoutStereo)) {
++		wxLogError("Failed to set 2 channels");
++		return false;
++	}
+ 
+-	m_audioStm->time_base = c->time_base;
 +	if (m_audioStm && avcodec_parameters_from_context(m_audioStm->codecpar, c) < 0) {
 +		wxLogError("Failed to copy encoder parameters to output audio stream");
 +		return false;
 +	}
  
--	m_audioStm->time_base = c->time_base;
--
  	
  	if (avcodec_open2(c, encoder, NULL) < 0) {
- 		wxLogError(wxT("Could not open audio codec"));
+-		wxLogError(wxT("Could not open audio codec"));
++		wxLogError("Could not open audio codec");
  		return false;
  	}
 -	if (avcodec_parameters_from_context(m_audioStm->codecpar, c) < 0) {
@@ -210,7 +231,10 @@ Index: src/mediaenc_ffmpeg.cpp
 -	avcodec_fill_audio_frame(m_audioFrame, c->channels, c->sample_fmt, (uint8_t *) m_samples, c->frame_size
 -			* av_get_bytes_per_sample(c->sample_fmt) * c->channels, 1);
 +	m_audioFrame->format = c->sample_fmt;
-+	m_audioFrame->channel_layout = c->channel_layout;
++	if (av_channel_layout_copy(&m_audioFrame->ch_layout, &c->ch_layout) < 0) {
++		wxLogError("Could not open copy channel layout");
++		return false;
++	}
 +		
 +	int ret = av_frame_get_buffer(m_audioFrame, 0); // allocate the data buffers
 +	if (ret < 0) {
@@ -220,7 +244,7 @@ Index: src/mediaenc_ffmpeg.cpp
 +	ret = av_frame_make_writable(m_audioFrame);
 +	if (ret < 0)
 +		return false;
-+	for (int i = 0; i < c->channels; i++) {
++	for (int i = 0; i < c->ch_layout.nb_channels; i++) {
 +		uint16_t *samples = (uint16_t*)m_audioFrame->data[i];
 +		memset(samples, 0, c->frame_size * av_get_bytes_per_sample(c->sample_fmt));
 +	}
@@ -246,7 +270,7 @@ Index: src/mediaenc_ffmpeg.cpp
  }
  
  void wxFfmpegMediaEncoder::CloseVideoEncoder() {
-@@ -345,10 +352,8 @@ void wxFfmpegMediaEncoder::CloseVideoEncoder() {
+@@ -345,10 +364,8 @@ void wxFfmpegMediaEncoder::CloseVideoEncoder() {
  		av_freep(&m_picture);
  	}
  	av_freep(&m_videoOutbuf);
@@ -258,7 +282,7 @@ Index: src/mediaenc_ffmpeg.cpp
  }
  
  bool wxFfmpegMediaEncoder::EncodeImage(wxImage image, int frames, AbstractProgressDialog* progressDialog) {
-@@ -390,20 +395,77 @@ bool wxFfmpegMediaEncoder::EncodeImage(wxImage image, 
+@@ -390,20 +407,77 @@ bool wxFfmpegMediaEncoder::EncodeImage(wxImage image, 
  	return true;
  }
  
@@ -346,15 +370,94 @@ Index: src/mediaenc_ffmpeg.cpp
  	}
  	return true;
  }
-@@ -429,7 +491,6 @@ int encode(AVCodecContext *avctx, AVPacket *pkt, AVFra
+@@ -429,32 +503,30 @@ int encode(AVCodecContext *avctx, AVPacket *pkt, AVFra
  	return ret;
  }
  
 -
  bool wxFfmpegMediaEncoder::writeAudioFrame() {
- 	AVPacket pkt = { 0 }; // data and size must be 0;
- 	int got_packet;
-@@ -495,14 +556,17 @@ bool wxFfmpegMediaEncoder::writeVideoFrame() {
+-	AVPacket pkt = { 0 }; // data and size must be 0;
+-	int got_packet;
+-
+-	av_init_packet(&pkt);
++	AVPacket* pkt = av_packet_alloc();
+ 	AVCodecContext *c = m_audioCodec;
+ 	
+ 	m_audioFrame->pts = m_nextAudioPts;
+ 	m_nextAudioPts += m_audioFrame->nb_samples;
+-	encode(c, &pkt, m_audioFrame, &got_packet);
++
++	int got_packet = 0;
++	encode(c, pkt, m_audioFrame, &got_packet);
+ 	if (!got_packet) {
+-		av_packet_unref(&pkt);
++		av_packet_unref(pkt);
+ 		return true;
+ 	}
+ 
+-	pkt.stream_index = m_audioStm->index; 
++	pkt->stream_index = m_audioStm->index;
+ 	
+ 	// write the compressed frame in the media file
+-	int ret = av_interleaved_write_frame(m_outputCtx, &pkt);
++	int ret = av_interleaved_write_frame(m_outputCtx, pkt);
+ 	if (ret < 0) {
+-		av_packet_unref(&pkt);
++		av_packet_unref(pkt);
+ 		print_error("Error while writing audio frame", ret);
+ 		return false;
+ 	}
+-	av_packet_unref(&pkt);
++	av_packet_unref(pkt);
+ 	return true;
+ }
+ 
+@@ -463,46 +535,48 @@ bool wxFfmpegMediaEncoder::writeVideoFrame() {
+ 	
+ 	// encode the image
+ 	m_picture->pts = m_nextVideoPts++;
+-	AVPacket pkt;
+-	av_init_packet(&pkt);
+-	pkt.data = m_videoOutbuf;
+-	pkt.size = VIDEO_BUF_SIZE;
++	AVPacket* pkt = av_packet_alloc();
++	pkt->data = m_videoOutbuf;
++	pkt->size = VIDEO_BUF_SIZE;
+ 	
+ 	int got_packet = 0;
+-	int ret = encode(c, &pkt, m_picture, &got_packet);
++	int ret = encode(c, pkt, m_picture, &got_packet);
+ 	if (ret < 0) {
+-		av_packet_unref(&pkt);
++		av_packet_unref(pkt);
+ 		print_error("Error while writing video frame", ret);
+ 		return false;
+ 	}
+ 	if (got_packet) {
+-		if (pkt.pts != (int64_t) AV_NOPTS_VALUE)
+-			pkt.pts = av_rescale_q(pkt.pts, c->time_base, m_videoStm->time_base);
+-		if (pkt.dts != (int64_t) AV_NOPTS_VALUE)
+-			pkt.dts = av_rescale_q(pkt.dts, c->time_base, m_videoStm->time_base);
+-		pkt.stream_index = m_videoStm->index;
++		if (pkt->pts != (int64_t) AV_NOPTS_VALUE)
++			pkt->pts = av_rescale_q(pkt->pts, c->time_base, m_videoStm->time_base);
++		if (pkt->dts != (int64_t) AV_NOPTS_VALUE)
++			pkt->dts = av_rescale_q(pkt->dts, c->time_base, m_videoStm->time_base);
++		pkt->stream_index = m_videoStm->index;
+ 		
+ 		// write the compressed frame in the media file
+-		ret = av_interleaved_write_frame(m_outputCtx, &pkt);
++		ret = av_interleaved_write_frame(m_outputCtx, pkt);
+ 		if (ret < 0) {
+-			av_packet_unref(&pkt);
++			av_packet_unref(pkt);
+ 			print_error("Error while writing video frame", ret);
+ 			return false;
+ 		}
+ 	}
+-	av_packet_unref(&pkt);
++	av_packet_unref(pkt);
+ 	return true;
  }
  
  void wxFfmpegMediaEncoder::EndEncode() {
Index: multimedia/handbrake/patches/patch-libhb_audio_resample_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_audio_resample_c
diff -N multimedia/handbrake/patches/patch-libhb_audio_resample_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_audio_resample_c	10 Sep 2025 22:27:55 -0000
@@ -0,0 +1,16 @@
+Index: libhb/audio_resample.c
+--- libhb/audio_resample.c.orig
++++ libhb/audio_resample.c
+@@ -90,10 +90,12 @@ static int is_mono(uint64_t layout)
+     int ii, channel_count;
+     int64_t mask;
+ 
++#ifdef AV_CH_LAYOUT_NATIVE
+     if (layout == AV_CH_LAYOUT_NATIVE)
+     {
+         return 0;
+     }
++#endif
+     for (ii = 0, channel_count = 0, mask = 1;
+          ii < 64 && channel_count < 2; ii++, mask <<= 1)
+     {
Index: multimedia/handbrake/patches/patch-libhb_decavcodec_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_decavcodec_c
diff -N multimedia/handbrake/patches/patch-libhb_decavcodec_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_decavcodec_c	10 Sep 2025 23:13:16 -0000
@@ -0,0 +1,64 @@
+Index: libhb/decavcodec.c
+--- libhb/decavcodec.c.orig
++++ libhb/decavcodec.c
+@@ -2037,8 +2037,8 @@ static void compute_frame_duration( hb_work_private_t 
+     int64_t max_fps = 64LL;
+ 
+     // context->time_base may be in fields, so set the max *fields* per second
+-    if ( pv->context->ticks_per_frame > 1 )
+-        max_fps *= pv->context->ticks_per_frame;
++    if ( pv->context->codec_descriptor->props & AV_CODEC_PROP_FIELDS )
++        max_fps *= 2;
+ 
+     if ( pv->title->opaque_priv )
+     {
+@@ -2057,7 +2057,8 @@ static void compute_frame_duration( hb_work_private_t 
+         // Raw demuxers set a default fps of 25 and do not parse
+         // a value from the container.  So use the codec time_base
+         // for raw demuxers.
+-        else if (ic->iformat->raw_codec_id == AV_CODEC_ID_NONE)
++        // See: https://github.com/HandBrake/HandBrake/pull/5884
++        else if (st->start_time == AV_NOPTS_VALUE && st->duration == AV_NOPTS_VALUE)
+         {
+             // XXX We don't have a frame count or duration so try to use the
+             // far less reliable time base info in the stream.
+@@ -2083,11 +2084,11 @@ static void compute_frame_duration( hb_work_private_t 
+         {
+             duration =  (double)pv->context->time_base.num /
+                         (double)pv->context->time_base.den;
+-            if ( pv->context->ticks_per_frame > 1 )
++            if ( pv->context->codec_descriptor->props & AV_CODEC_PROP_FIELDS )
+             {
+                 // for ffmpeg 0.5 & later, the H.264 & MPEG-2 time base is
+                 // field rate rather than frame rate so convert back to frames.
+-                duration *= pv->context->ticks_per_frame;
++                duration *= 2;
+             }
+         }
+     }
+@@ -2098,11 +2099,11 @@ static void compute_frame_duration( hb_work_private_t 
+         {
+             duration =  (double)pv->context->time_base.num /
+                             (double)pv->context->time_base.den;
+-            if ( pv->context->ticks_per_frame > 1 )
++            if ( pv->context->codec_descriptor->props & AV_CODEC_PROP_FIELDS )
+             {
+                 // for ffmpeg 0.5 & later, the H.264 & MPEG-2 time base is
+                 // field rate rather than frame rate so convert back to frames.
+-                duration *= pv->context->ticks_per_frame;
++                duration *= 2;
+             }
+         }
+     }
+@@ -2113,9 +2114,9 @@ static void compute_frame_duration( hb_work_private_t 
+     }
+     pv->duration = duration * 90000.;
+     pv->field_duration = pv->duration;
+-    if ( pv->context->ticks_per_frame > 1 )
++    if ( pv->context->codec_descriptor->props & AV_CODEC_PROP_FIELDS )
+     {
+-        pv->field_duration /= pv->context->ticks_per_frame;
++        pv->field_duration /= 2;
+     }
+ }
+ 
Index: multimedia/handbrake/patches/patch-libhb_encavcodec_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_encavcodec_c
diff -N multimedia/handbrake/patches/patch-libhb_encavcodec_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_encavcodec_c	11 Sep 2025 21:40:17 -0000
@@ -0,0 +1,103 @@
+Index: libhb/encavcodec.c
+--- libhb/encavcodec.c.orig
++++ libhb/encavcodec.c
+@@ -333,7 +333,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * j
+     if ((job->vcodec == HB_VCODEC_FFMPEG_VCE_H264) || (job->vcodec == HB_VCODEC_FFMPEG_VCE_H265) || (job->vcodec == HB_VCODEC_FFMPEG_VCE_H265_10BIT))
+     {
+         // Set encoder preset
+-        context->profile = FF_PROFILE_UNKNOWN;
++        context->profile = AV_PROFILE_UNKNOWN;
+         if (job->encoder_preset != NULL && *job->encoder_preset)
+         {
+             if ((!strcasecmp(job->encoder_preset, "balanced"))
+@@ -915,17 +915,17 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * j
+     if (job->vcodec == HB_VCODEC_FFMPEG_VCE_H264)
+     {
+         // Set profile and level
+-        context->profile = FF_PROFILE_UNKNOWN;
++        context->profile = AV_PROFILE_UNKNOWN;
+         if (job->encoder_profile != NULL && *job->encoder_profile)
+         {
+             if (!strcasecmp(job->encoder_profile, "baseline"))
+-                context->profile = FF_PROFILE_H264_BASELINE;
++                context->profile = AV_PROFILE_H264_BASELINE;
+             else if (!strcasecmp(job->encoder_profile, "main"))
+-                 context->profile = FF_PROFILE_H264_MAIN;
++                 context->profile = AV_PROFILE_H264_MAIN;
+             else if (!strcasecmp(job->encoder_profile, "high"))
+-                context->profile = FF_PROFILE_H264_HIGH;
++                context->profile = AV_PROFILE_H264_HIGH;
+         }
+-        context->level = FF_LEVEL_UNKNOWN;
++        context->level = AV_LEVEL_UNKNOWN;
+         if (job->encoder_level != NULL && *job->encoder_level)
+         {
+             int i = 1;
+@@ -941,13 +941,13 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * j
+     if (job->vcodec == HB_VCODEC_FFMPEG_VCE_H265 || job->vcodec == HB_VCODEC_FFMPEG_VCE_H265_10BIT)
+     {
+         // Set profile and level
+-        context->profile = FF_PROFILE_UNKNOWN;
++        context->profile = AV_PROFILE_UNKNOWN;
+         if (job->encoder_profile != NULL && *job->encoder_profile)
+         {
+             if (!strcasecmp(job->encoder_profile, "main"))
+-                 context->profile = FF_PROFILE_HEVC_MAIN;
++                 context->profile = AV_PROFILE_HEVC_MAIN;
+         }
+-        context->level = FF_LEVEL_UNKNOWN;
++        context->level = AV_LEVEL_UNKNOWN;
+         if (job->encoder_level != NULL && *job->encoder_level)
+         {
+             int i = 1;
+@@ -1000,15 +1000,15 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * j
+ 
+     if (job->vcodec == HB_VCODEC_FFMPEG_MF_H264)
+     {
+-        context->profile = FF_PROFILE_UNKNOWN;
++        context->profile = AV_PROFILE_UNKNOWN;
+         if (job->encoder_profile != NULL && *job->encoder_profile)
+         {
+             if (!strcasecmp(job->encoder_profile, "baseline"))
+-                context->profile = FF_PROFILE_H264_BASELINE;
++                context->profile = AV_PROFILE_H264_BASELINE;
+             else if (!strcasecmp(job->encoder_profile, "main"))
+-                 context->profile = FF_PROFILE_H264_MAIN;
++                 context->profile = AV_PROFILE_H264_MAIN;
+             else if (!strcasecmp(job->encoder_profile, "high"))
+-                context->profile = FF_PROFILE_H264_HIGH;
++                context->profile = AV_PROFILE_H264_HIGH;
+         }
+ 
+     }
+@@ -1332,7 +1332,6 @@ static void Encode( hb_work_object_t *w, hb_buffer_t *
+            when this frame finally pops out of the encoder we'll mark
+            its buffer as the start of a chapter. */
+         frame.pict_type = AV_PICTURE_TYPE_I;
+-        frame.key_frame = 1;
+         hb_chapter_enqueue(pv->chapter_queue, in);
+     }
+ 
+@@ -1446,17 +1445,17 @@ int encavcodecWork( hb_work_object_t * w, hb_buffer_t 
+ 
+ static int apply_svt_av1_options(hb_job_t *job, AVCodecContext *context, AVDictionary **av_opts, hb_dict_t *opts)
+ {
+-    context->profile = FF_PROFILE_UNKNOWN;
++    context->profile = AV_PROFILE_UNKNOWN;
+     if (job->encoder_profile != NULL && *job->encoder_profile)
+     {
+         if (!strcasecmp(job->encoder_profile, "main"))
+-            context->profile = FF_PROFILE_AV1_MAIN;
++            context->profile = AV_PROFILE_AV1_MAIN;
+         else if (!strcasecmp(job->encoder_profile, "high"))
+-             context->profile = FF_PROFILE_AV1_HIGH;
++             context->profile = AV_PROFILE_AV1_HIGH;
+         else if (!strcasecmp(job->encoder_profile, "professional"))
+-            context->profile = FF_PROFILE_AV1_PROFESSIONAL;
++            context->profile = AV_PROFILE_AV1_PROFESSIONAL;
+     }
+-    context->level = FF_LEVEL_UNKNOWN;
++    context->level = AV_LEVEL_UNKNOWN;
+     if (job->encoder_level != NULL && *job->encoder_level)
+     {
+         int i = 1;
Index: multimedia/handbrake/patches/patch-libhb_encavcodecaudio_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_encavcodecaudio_c
diff -N multimedia/handbrake/patches/patch-libhb_encavcodecaudio_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_encavcodecaudio_c	11 Sep 2025 21:40:17 -0000
@@ -0,0 +1,34 @@
+Index: libhb/encavcodecaudio.c
+--- libhb/encavcodecaudio.c.orig
++++ libhb/encavcodecaudio.c
+@@ -74,7 +74,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job
+     enum AVCodecID codec_id        = AV_CODEC_ID_NONE;
+     enum AVSampleFormat sample_fmt = AV_SAMPLE_FMT_FLTP;
+     int bits_per_raw_sample        = 0;
+-    int profile                    = FF_PROFILE_UNKNOWN;
++    int profile                    = AV_PROFILE_UNKNOWN;
+ 
+     // override with encoder-specific values
+     switch (audio->config.out.codec)
+@@ -99,10 +99,10 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job
+             switch (audio->config.out.codec)
+             {
+                 case HB_ACODEC_FDK_HAAC:
+-                    profile = FF_PROFILE_AAC_HE;
++                    profile = AV_PROFILE_AAC_HE;
+                     break;
+                 default:
+-                    profile = FF_PROFILE_AAC_LOW;
++                    profile = AV_PROFILE_AAC_LOW;
+                     break;
+             }
+             // FFmpeg's libfdk-aac wrapper expects back channels for 5.1
+@@ -238,7 +238,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job
+     pv->input_buf         = malloc(pv->input_samples * sizeof(float));
+     // Some encoders in libav (e.g. fdk-aac) fail if the output buffer
+     // size is not some minimum value.  8K seems to be enough :(
+-    pv->max_output_bytes  = MAX(AV_INPUT_BUFFER_MIN_SIZE,
++    pv->max_output_bytes  = MAX(AV_INPUT_BUFFER_PADDING_SIZE,
+                                 (pv->input_samples *
+                                  av_get_bytes_per_sample(context->sample_fmt)));
+ 
Index: multimedia/handbrake/patches/patch-libhb_hbavfilter_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_hbavfilter_c
diff -N multimedia/handbrake/patches/patch-libhb_hbavfilter_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_hbavfilter_c	12 Sep 2025 10:00:24 -0000
@@ -0,0 +1,25 @@
+Index: libhb/hbavfilter.c
+--- libhb/hbavfilter.c.orig
++++ libhb/hbavfilter.c
+@@ -271,6 +271,7 @@ void hb_avfilter_graph_update_init(hb_avfilter_graph_t
+ {
+     // Retrieve the parameters of the output filter
+     AVFilterLink *link     = graph->output->inputs[0];
++    AVRational frame_rate  = av_buffersink_get_frame_rate(graph->output);
+     init->geometry.width   = link->w;
+     init->geometry.height  = link->h;
+     init->geometry.par.num = link->sample_aspect_ratio.num;
+@@ -278,10 +279,10 @@ void hb_avfilter_graph_update_init(hb_avfilter_graph_t
+     init->pix_fmt          = link->format;
+     // avfilter can generate "unknown" framerates.  If this happens
+     // just pass along the source framerate.
+-    if (link->frame_rate.num > 0 && link->frame_rate.den > 0)
++    if (frame_rate.num > 0 && frame_rate.den > 0)
+     {
+-        init->vrate.num        = link->frame_rate.num;
+-        init->vrate.den        = link->frame_rate.den;
++        init->vrate.num        = frame_rate.num;
++        init->vrate.den        = frame_rate.den;
+     }
+ }
+ 
Index: multimedia/handbrake/patches/patch-libhb_hbffmpeg_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_hbffmpeg_c
diff -N multimedia/handbrake/patches/patch-libhb_hbffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_hbffmpeg_c	12 Sep 2025 10:07:53 -0000
@@ -0,0 +1,40 @@
+Index: libhb/hbffmpeg.c
+--- libhb/hbffmpeg.c.orig
++++ libhb/hbffmpeg.c
+@@ -41,12 +41,17 @@ void hb_video_buffer_to_avframe(AVFrame *frame, hb_buf
+     frame->linesize[2] = buf->plane[2].stride;
+ 
+     frame->pts              = buf->s.start;
+-    frame->reordered_opaque = buf->s.duration;
+     frame->width            = buf->f.width;
+     frame->height           = buf->f.height;
+     frame->format           = buf->f.fmt;
+-    frame->interlaced_frame = !!buf->s.combed;
+-    frame->top_field_first  = !!(buf->s.flags & PIC_FLAG_TOP_FIELD_FIRST);
++    if (!!buf->s.combed)
++        frame->flags        |= AV_FRAME_FLAG_INTERLACED;
++    else
++        frame->flags        &= ~AV_FRAME_FLAG_INTERLACED;
++    if (!!(buf->s.flags & PIC_FLAG_TOP_FIELD_FIRST))
++        frame->flags        |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++    else
++        frame->flags        &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
+ 
+     frame->format          = buf->f.fmt;
+     frame->color_primaries = hb_colr_pri_hb_to_ff(buf->f.color_prim);
+@@ -65,13 +70,12 @@ void hb_avframe_set_video_buffer_flags(hb_buffer_t * b
+     }
+ 
+     buf->s.start = av_rescale_q(frame->pts, time_base, (AVRational){1, 90000});
+-    buf->s.duration = frame->reordered_opaque;
+ 
+-    if (frame->top_field_first)
++    if (frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)
+     {
+         buf->s.flags |= PIC_FLAG_TOP_FIELD_FIRST;
+     }
+-    if (!frame->interlaced_frame)
++    if (!(frame->flags & AV_FRAME_FLAG_INTERLACED))
+     {
+         buf->s.flags |= PIC_FLAG_PROGRESSIVE_FRAME;
+     }
Index: multimedia/handbrake/patches/patch-libhb_muxavformat_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_muxavformat_c
diff -N multimedia/handbrake/patches/patch-libhb_muxavformat_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_muxavformat_c	12 Sep 2025 10:28:21 -0000
@@ -0,0 +1,45 @@
+Index: libhb/muxavformat.c
+--- libhb/muxavformat.c.orig
++++ libhb/muxavformat.c
+@@ -556,10 +556,11 @@ static int avformatInit( hb_mux_object_t * m )
+             uint8_t *mastering_data = av_malloc(sizeof(AVMasteringDisplayMetadata));
+             memcpy(mastering_data, &mastering, sizeof(AVMasteringDisplayMetadata));
+ 
+-            av_stream_add_side_data(track->st,
++            av_packet_side_data_add(&track->st->codecpar->coded_side_data,
++                                    &track->st->codecpar->nb_coded_side_data,
+                                     AV_PKT_DATA_MASTERING_DISPLAY_METADATA,
+                                     mastering_data,
+-                                    sizeof(AVMasteringDisplayMetadata));
++                                    sizeof(AVMasteringDisplayMetadata), 0);
+         }
+ 
+         if (job->coll.max_cll && job->coll.max_fall)
+@@ -571,10 +572,11 @@ static int avformatInit( hb_mux_object_t * m )
+             uint8_t *coll_data = av_malloc(sizeof(AVContentLightMetadata));
+             memcpy(coll_data, &coll, sizeof(AVContentLightMetadata));
+ 
+-            av_stream_add_side_data(track->st,
++            av_packet_side_data_add(&track->st->codecpar->coded_side_data,
++                                    &track->st->codecpar->nb_coded_side_data,
+                                     AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
+                                     coll_data,
+-                                    sizeof(AVContentLightMetadata));
++                                    sizeof(AVContentLightMetadata), 0);
+         }
+     }
+ 
+@@ -884,9 +886,10 @@ static int avformatInit( hb_mux_object_t * m )
+ 
+                         track = audio->priv.mux_data;
+                         fallback_track = fallback->priv.mux_data;
+-                        sd = (int*)av_stream_new_side_data(track->st,
+-                                                     AV_PKT_DATA_FALLBACK_TRACK,
+-                                                     sizeof(int));
++                        sd = (int*)av_packet_side_data_new(&track->st->codecpar->coded_side_data,
++                                                           &track->st->codecpar->nb_coded_side_data,
++                                                           AV_PKT_DATA_FALLBACK_TRACK,
++                                                           sizeof(int), 0);
+                         if (sd != NULL)
+                         {
+                             *sd = fallback_track->st->index;
Index: multimedia/handbrake/patches/patch-libhb_scan_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_scan_c
diff -N multimedia/handbrake/patches/patch-libhb_scan_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_scan_c	12 Sep 2025 10:08:43 -0000
@@ -0,0 +1,12 @@
+Index: libhb/scan.c
+--- libhb/scan.c.orig
++++ libhb/scan.c
+@@ -1459,7 +1459,7 @@ static void LookForAudio(hb_scan_t *scan, hb_title_t *
+         const AVCodec *codec = avcodec_find_decoder(audio->config.in.codec_param);
+         if (codec != NULL)
+         {
+-            if (info.profile != FF_PROFILE_UNKNOWN)
++            if (info.profile != AV_PROFILE_UNKNOWN)
+             {
+                 profile_name = av_get_profile_name(codec, info.profile);
+             }
Index: multimedia/handbrake/patches/patch-libhb_stream_c
===================================================================
RCS file: multimedia/handbrake/patches/patch-libhb_stream_c
diff -N multimedia/handbrake/patches/patch-libhb_stream_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/handbrake/patches/patch-libhb_stream_c	12 Sep 2025 10:17:43 -0000
@@ -0,0 +1,67 @@
+Index: libhb/stream.c
+--- libhb/stream.c.orig
++++ libhb/stream.c
+@@ -4052,16 +4052,16 @@ static int probe_dts_profile( hb_stream_t *stream, hb_
+     }
+     switch (info.profile)
+     {
+-        case FF_PROFILE_DTS:
+-        case FF_PROFILE_DTS_ES:
+-        case FF_PROFILE_DTS_96_24:
++        case AV_PROFILE_DTS:
++        case AV_PROFILE_DTS_ES:
++        case AV_PROFILE_DTS_96_24:
+             pes->codec = HB_ACODEC_DCA;
+             pes->stream_type = 0x82;
+             pes->stream_kind = A;
+             break;
+ 
+-        case FF_PROFILE_DTS_HD_HRA:
+-        case FF_PROFILE_DTS_HD_MA:
++        case AV_PROFILE_DTS_HD_HRA:
++        case AV_PROFILE_DTS_HD_MA:
+             pes->stream_type = 0;
+             pes->stream_kind = A;
+             break;
+@@ -5408,14 +5408,14 @@ static void add_ffmpeg_audio(hb_title_t *title, hb_str
+         {
+             switch (codecpar->profile)
+             {
+-                case FF_PROFILE_DTS:
+-                case FF_PROFILE_DTS_ES:
+-                case FF_PROFILE_DTS_96_24:
++                case AV_PROFILE_DTS:
++                case AV_PROFILE_DTS_ES:
++                case AV_PROFILE_DTS_96_24:
+                     audio->config.in.codec = HB_ACODEC_DCA;
+                     break;
+ 
+-                case FF_PROFILE_DTS_HD_MA:
+-                case FF_PROFILE_DTS_HD_HRA:
++                case AV_PROFILE_DTS_HD_MA:
++                case AV_PROFILE_DTS_HD_HRA:
+                     audio->config.in.codec = HB_ACODEC_DCA_HD;
+                     break;
+ 
+@@ -5846,9 +5846,9 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *str
+             }
+ 
+             int j;
+-            for (j = 0; j < st->nb_side_data; j++)
++            for (j = 0; j < codecpar->nb_coded_side_data; j++)
+             {
+-                AVPacketSideData sd = st->side_data[j];
++                AVPacketSideData sd = codecpar->coded_side_data[j];
+                 switch (sd.type)
+                 {
+                     case AV_PKT_DATA_DISPLAYMATRIX:
+@@ -5899,7 +5899,8 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *str
+             // title->video_timebase.den = st->time_base.den;
+             title->video_timebase.num = 1;
+             title->video_timebase.den = 90000;
+-            if (ic->iformat->raw_codec_id != AV_CODEC_ID_NONE)
++            // See: https://github.com/HandBrake/HandBrake/pull/5884
++            if (st->start_time == AV_NOPTS_VALUE && st->duration == AV_NOPTS_VALUE)
+             {
+                 title->flags |= HBTF_RAW_VIDEO;
+             }
Index: multimedia/lebiniou/patches/patch-plugins_main_video_video_c
===================================================================
RCS file: multimedia/lebiniou/patches/patch-plugins_main_video_video_c
diff -N multimedia/lebiniou/patches/patch-plugins_main_video_video_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/lebiniou/patches/patch-plugins_main_video_video_c	12 Sep 2025 16:45:51 -0000
@@ -0,0 +1,12 @@
+Index: plugins/main/video/video.c
+--- plugins/main/video/video.c.orig
++++ plugins/main/video/video.c
+@@ -225,7 +225,7 @@ static void
+ free_allocated(void)
+ {
+   if (NULL != codec_ctx) {
+-    avcodec_close(codec_ctx);
++    avcodec_free_context(&codec_ctx);
+   }
+   if (NULL != fmt_ctx) {
+     avformat_close_input(&fmt_ctx);
Index: multimedia/minidlna/patches/patch-libav_h
===================================================================
RCS file: multimedia/minidlna/patches/patch-libav_h
diff -N multimedia/minidlna/patches/patch-libav_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/minidlna/patches/patch-libav_h	1 Sep 2025 21:37:06 -0000
@@ -0,0 +1,27 @@
+Index: libav.h
+--- libav.h.orig
++++ libav.h
+@@ -174,7 +174,11 @@ lav_get_interlaced(AVStream *s)
+ #define lav_codec_tag(s) s->codecpar->codec_tag
+ #define lav_sample_rate(s) s->codecpar->sample_rate
+ #define lav_bit_rate(s) s->codecpar->bit_rate
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
+ #define lav_channels(s) s->codecpar->channels
++#else
++#define lav_channels(s) s->codecpar->ch_layout.nb_channels
++#endif
+ #define lav_width(s) s->codecpar->width
+ #define lav_height(s) s->codecpar->height
+ #define lav_profile(s) s->codecpar->profile
+@@ -186,7 +190,11 @@ lav_get_interlaced(AVStream *s)
+ #define lav_codec_tag(s) s->codec->codec_tag
+ #define lav_sample_rate(s) s->codec->sample_rate
+ #define lav_bit_rate(s) s->codec->bit_rate
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 24, 100)
+ #define lav_channels(s) s->codec->channels
++#else
++#define lav_channels(s) s->codec->ch_layout.nb_channels
++#endif
+ #define lav_width(s) s->codec->width
+ #define lav_height(s) s->codec->height
+ #define lav_profile(s) s->codec->profile
Index: multimedia/minidlna/patches/patch-minidlna_c
===================================================================
RCS file: /home/cvs/ports/multimedia/minidlna/patches/patch-minidlna_c,v
diff -u -p -r1.14 patch-minidlna_c
--- multimedia/minidlna/patches/patch-minidlna_c	3 Mar 2023 07:54:45 -0000	1.14
+++ multimedia/minidlna/patches/patch-minidlna_c	1 Sep 2025 21:36:30 -0000
@@ -4,7 +4,7 @@ https://sourceforge.net/p/minidlna/bugs/
 Index: minidlna.c
 --- minidlna.c.orig
 +++ minidlna.c
-@@ -1150,7 +1150,7 @@ main(int argc, char **argv)
+@@ -1231,7 +1231,7 @@ main(int argc, char **argv)
  	lastdbtime = _get_dbtime();
  
  #ifdef HAVE_WATCH
Index: multimedia/mlt7/patches/patch-src_modules_avformat_common_c
===================================================================
RCS file: multimedia/mlt7/patches/patch-src_modules_avformat_common_c
diff -N multimedia/mlt7/patches/patch-src_modules_avformat_common_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mlt7/patches/patch-src_modules_avformat_common_c	2 Sep 2025 16:33:23 -0000
@@ -0,0 +1,27 @@
+Backport https://github.com/mltframework/mlt/commit/ae83ceee72a0a39c063b02310f6ce928839712a2
+
+Index: src/modules/avformat/common.c
+--- src/modules/avformat/common.c.orig
++++ src/modules/avformat/common.c
+@@ -367,10 +367,20 @@ void mlt_image_to_avframe(mlt_image image, mlt_frame m
+     avframe->height = image->height;
+     avframe->format = mlt_to_av_image_format(image->format);
+     avframe->sample_aspect_ratio = av_d2q(mlt_frame_get_aspect_ratio(mltframe), 1024);
+-    ;
+     avframe->pts = mlt_frame_get_position(mltframe);
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++    if (!mlt_properties_get_int(frame_properties, "progressive"))
++        avframe->flags |= AV_FRAME_FLAG_INTERLACED;
++    else
++        avframe->flags &= ~AV_FRAME_FLAG_INTERLACED;
++    if (mlt_properties_get_int(frame_properties, "top_field_first"))
++        avframe->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++    else
++        avframe->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+     avframe->interlaced_frame = !mlt_properties_get_int(frame_properties, "progressive");
+     avframe->top_field_first = mlt_properties_get_int(frame_properties, "top_field_first");
++#endif
+     avframe->color_primaries = mlt_properties_get_int(frame_properties, "color_primaries");
+     avframe->color_trc = mlt_properties_get_int(frame_properties, "color_trc");
+     avframe->color_range = mlt_properties_get_int(frame_properties, "full_range")
Index: multimedia/mlt7/patches/patch-src_modules_avformat_consumer_avformat_c
===================================================================
RCS file: multimedia/mlt7/patches/patch-src_modules_avformat_consumer_avformat_c
diff -N multimedia/mlt7/patches/patch-src_modules_avformat_consumer_avformat_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mlt7/patches/patch-src_modules_avformat_consumer_avformat_c	2 Sep 2025 16:34:17 -0000
@@ -0,0 +1,40 @@
+Backport https://github.com/mltframework/mlt/commit/ae83ceee72a0a39c063b02310f6ce928839712a2
+
+Index: src/modules/avformat/consumer_avformat.c
+--- src/modules/avformat/consumer_avformat.c.orig
++++ src/modules/avformat/consumer_avformat.c
+@@ -1923,18 +1923,27 @@ static int encode_video(encode_ctx_t *enc_ctx,
+         avframe->pts = enc_ctx->frame_count;
+ 
+         // Set frame interlace hints
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++        if (!mlt_properties_get_int(frame_properties, "progressive"))
++            avframe->flags |= AV_FRAME_FLAG_INTERLACED;
++        else
++            avframe->flags &= ~AV_FRAME_FLAG_INTERLACED;
++        const int tff = mlt_properties_get_int(frame_properties, "top_field_first");
++        if (tff)
++            avframe->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++        else
++            avframe->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+         avframe->interlaced_frame = !mlt_properties_get_int(frame_properties, "progressive");
+-        avframe->top_field_first = mlt_properties_get_int(frame_properties, "top_field_first");
++        const int tff = avframe->top_field_first = mlt_properties_get_int(frame_properties,
++                                                                          "top_field_first");
++#endif
+         if (mlt_properties_get_int(frame_properties, "progressive"))
+             c->field_order = AV_FIELD_PROGRESSIVE;
+         else if (c->codec_id == AV_CODEC_ID_MJPEG)
+-            c->field_order = (mlt_properties_get_int(frame_properties, "top_field_first"))
+-                                 ? AV_FIELD_TT
+-                                 : AV_FIELD_BB;
++            c->field_order = tff ? AV_FIELD_TT : AV_FIELD_BB;
+         else
+-            c->field_order = (mlt_properties_get_int(frame_properties, "top_field_first"))
+-                                 ? AV_FIELD_TB
+-                                 : AV_FIELD_BT;
++            c->field_order = tff ? AV_FIELD_TB : AV_FIELD_BT;
+ 
+         // Encode the image
+         ret = avcodec_send_frame(c, avframe);
Index: multimedia/mlt7/patches/patch-src_modules_avformat_filter_avfilter_c
===================================================================
RCS file: multimedia/mlt7/patches/patch-src_modules_avformat_filter_avfilter_c
diff -N multimedia/mlt7/patches/patch-src_modules_avformat_filter_avfilter_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mlt7/patches/patch-src_modules_avformat_filter_avfilter_c	2 Sep 2025 16:34:13 -0000
@@ -0,0 +1,27 @@
+Backport https://github.com/mltframework/mlt/commit/ae83ceee72a0a39c063b02310f6ce928839712a2
+
+Index: src/modules/avformat/filter_avfilter.c
+--- src/modules/avformat/filter_avfilter.c.orig
++++ src/modules/avformat/filter_avfilter.c
+@@ -802,10 +802,21 @@ static int filter_get_image(mlt_frame frame,
+         pdata->avinframe->sample_aspect_ratio = (AVRational){profile->sample_aspect_num,
+                                                              profile->sample_aspect_den};
+         pdata->avinframe->pts = pos;
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++        if (!mlt_properties_get_int(frame_properties, "progressive"))
++            pdata->avinframe->flags |= AV_FRAME_FLAG_INTERLACED;
++        else
++            pdata->avinframe->flags &= ~AV_FRAME_FLAG_INTERLACED;
++        if (mlt_properties_get_int(frame_properties, "top_field_first"))
++            pdata->avinframe->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++        else
++            pdata->avinframe->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+         pdata->avinframe->interlaced_frame = !mlt_properties_get_int(frame_properties,
+                                                                      "progressive");
+         pdata->avinframe->top_field_first = mlt_properties_get_int(frame_properties,
+                                                                    "top_field_first");
++#endif
+         pdata->avinframe->color_primaries = mlt_properties_get_int(frame_properties,
+                                                                    "color_primaries");
+         pdata->avinframe->color_trc = mlt_properties_get_int(frame_properties, "color_trc");
Index: multimedia/mlt7/patches/patch-src_modules_avformat_filter_swscale_c
===================================================================
RCS file: multimedia/mlt7/patches/patch-src_modules_avformat_filter_swscale_c
diff -N multimedia/mlt7/patches/patch-src_modules_avformat_filter_swscale_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mlt7/patches/patch-src_modules_avformat_filter_swscale_c	2 Sep 2025 16:34:08 -0000
@@ -0,0 +1,21 @@
+Backport https://github.com/mltframework/mlt/commit/ae83ceee72a0a39c063b02310f6ce928839712a2
+
+Index: src/modules/avformat/filter_swscale.c
+--- src/modules/avformat/filter_swscale.c.orig
++++ src/modules/avformat/filter_swscale.c
+@@ -170,8 +170,15 @@ static int filter_scale(mlt_frame frame,
+         avinframe->height = iheight;
+         avinframe->format = avformat;
+         avinframe->sample_aspect_ratio = av_d2q(mlt_frame_get_aspect_ratio(frame), 1024);
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++        if (!mlt_properties_get_int(properties, "progressive"))
++            avinframe->flags |= AV_FRAME_FLAG_INTERLACED;
++        if (mlt_properties_get_int(properties, "top_field_first"))
++            avinframe->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+         avinframe->interlaced_frame = !mlt_properties_get_int(properties, "progressive");
+         avinframe->top_field_first = mlt_properties_get_int(properties, "top_field_first");
++#endif
+         av_image_fill_arrays(avinframe->data,
+                              avinframe->linesize,
+                              *image,
Index: multimedia/mlt7/patches/patch-src_modules_avformat_link_avfilter_c
===================================================================
RCS file: multimedia/mlt7/patches/patch-src_modules_avformat_link_avfilter_c
diff -N multimedia/mlt7/patches/patch-src_modules_avformat_link_avfilter_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mlt7/patches/patch-src_modules_avformat_link_avfilter_c	2 Sep 2025 16:34:03 -0000
@@ -0,0 +1,27 @@
+Backport https://github.com/mltframework/mlt/commit/ae83ceee72a0a39c063b02310f6ce928839712a2
+
+Index: src/modules/avformat/link_avfilter.c
+--- src/modules/avformat/link_avfilter.c.orig
++++ src/modules/avformat/link_avfilter.c
+@@ -917,10 +917,21 @@ static int link_get_image(mlt_frame frame,
+         pdata->avinframe->sample_aspect_ratio = (AVRational){profile->sample_aspect_num,
+                                                              profile->sample_aspect_den};
+         pdata->avinframe->pts = pos;
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++        if (!mlt_properties_get_int(frame_properties, "progressive"))
++            pdata->avinframe->flags |= AV_FRAME_FLAG_INTERLACED;
++        else
++            pdata->avinframe->flags &= ~AV_FRAME_FLAG_INTERLACED;
++        if (mlt_properties_get_int(frame_properties, "top_field_first"))
++            pdata->avinframe->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++        else
++            pdata->avinframe->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+         pdata->avinframe->interlaced_frame = !mlt_properties_get_int(frame_properties,
+                                                                      "progressive");
+         pdata->avinframe->top_field_first = mlt_properties_get_int(frame_properties,
+                                                                    "top_field_first");
++#endif
+         pdata->avinframe->color_primaries = mlt_properties_get_int(frame_properties,
+                                                                    "color_primaries");
+         pdata->avinframe->color_trc = mlt_properties_get_int(frame_properties, "color_trc");
Index: multimedia/mlt7/patches/patch-src_modules_avformat_producer_avformat_c
===================================================================
RCS file: multimedia/mlt7/patches/patch-src_modules_avformat_producer_avformat_c
diff -N multimedia/mlt7/patches/patch-src_modules_avformat_producer_avformat_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mlt7/patches/patch-src_modules_avformat_producer_avformat_c	2 Sep 2025 16:33:38 -0000
@@ -0,0 +1,192 @@
+Backport https://github.com/mltframework/mlt/commit/ae83ceee72a0a39c063b02310f6ce928839712a2
+
+Index: src/modules/avformat/producer_avformat.c
+--- src/modules/avformat/producer_avformat.c.orig
++++ src/modules/avformat/producer_avformat.c
+@@ -335,11 +335,20 @@ static int first_video_index(producer_avformat self)
+ 
+ static const char *get_projection(AVStream *st)
+ {
++#if LIBAVCODEC_VERSION_INT >= ((60 << 16) + (29 << 8) + 100)
++    const AVPacketSideData *psd = av_packet_side_data_get(st->codecpar->coded_side_data,
++                                                          st->codecpar->nb_coded_side_data,
++                                                          AV_PKT_DATA_SPHERICAL);
++    if (psd) {
++        const AVSphericalMapping *spherical = (const AVSphericalMapping *) psd->data;
++#else
+     const AVSphericalMapping *spherical
+         = (const AVSphericalMapping *) av_stream_get_side_data(st, AV_PKT_DATA_SPHERICAL, NULL);
+ 
+-    if (spherical)
++    if (spherical) {
++#endif
+         return av_spherical_projection_name(spherical->projection);
++    }
+     return NULL;
+ }
+ 
+@@ -349,7 +358,16 @@ static double get_rotation(mlt_properties properties, 
+ {
+     AVDictionaryEntry *rotate_tag = av_dict_get(st->metadata, "rotate", NULL, 0);
+     int has_rotate_metadata = rotate_tag && *rotate_tag->value && strcmp(rotate_tag->value, "0");
++#if LIBAVCODEC_VERSION_INT >= ((60 << 16) + (29 << 8) + 100)
++    int32_t *displaymatrix = NULL;
++    const AVPacketSideData *psd = av_packet_side_data_get(st->codecpar->coded_side_data,
++                                                          st->codecpar->nb_coded_side_data,
++                                                          AV_PKT_DATA_DISPLAYMATRIX);
++    if (psd)
++        displaymatrix = (int32_t *) psd->data;
++#else
+     uint8_t *displaymatrix = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
++#endif
+     double theta = mlt_properties_get_double(properties, "rotate");
+     int has_mlt_rotate = !!mlt_properties_get(properties, "rotate");
+ 
+@@ -418,14 +436,7 @@ static AVRational guess_frame_rate(producer_avformat s
+         frame_rate = av_d2q(av_q2d(stream->avg_frame_rate), 1024);
+         fps = av_q2d(frame_rate);
+     }
+-    // XXX frame rates less than 1 fps are not considered sane
+     if (isnan(fps) || isinf(fps) || fps < 1.0) {
+-        // Get the frame rate from the codec.
+-        frame_rate.num = self->video_codec->time_base.den;
+-        frame_rate.den = self->video_codec->time_base.num * self->video_codec->ticks_per_frame;
+-        fps = av_q2d(frame_rate);
+-    }
+-    if (isnan(fps) || isinf(fps) || fps < 1.0) {
+         // Use the profile frame rate if all else fails.
+         mlt_profile profile = mlt_service_profile(MLT_PRODUCER_SERVICE(self->parent));
+         frame_rate.num = profile->frame_rate_num;
+@@ -1580,7 +1591,7 @@ static void get_audio_streams_info(producer_avformat s
+ #endif
+                 if (codec_params->sample_rate > self->max_frequency)
+                     self->max_frequency = codec_params->sample_rate;
+-                avcodec_close(codec_context);
++                avcodec_free_context(&codec_context);
+             }
+             pthread_mutex_unlock(&self->open_mutex);
+         }
+@@ -1716,7 +1727,11 @@ static int sliced_h_pix_fmt_conv_proc(int id, int idx,
+     struct SwsContext *sws;
+     struct sliced_pix_fmt_conv_t *ctx = (struct sliced_pix_fmt_conv_t *) cookie;
+ 
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++    interlaced = ctx->frame->flags & AV_FRAME_FLAG_INTERLACED;
++#else
+     interlaced = ctx->frame->interlaced_frame;
++#endif
+     field = (interlaced) ? (idx & 1) : 0;
+     idx = (interlaced) ? (idx / 2) : idx;
+     slices = (interlaced) ? (jobs / 2) : jobs;
+@@ -1865,7 +1880,11 @@ static void convert_image_rgb(producer_avformat self,
+     uint8_t *out_data[4];
+     int out_stride[4];
+ 
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++    if (src_pix_fmt == AV_PIX_FMT_YUV420P && (frame->flags & AV_FRAME_FLAG_INTERLACED)) {
++#else
+     if (src_pix_fmt == AV_PIX_FMT_YUV420P && frame->interlaced_frame) {
++#endif
+         // Perform field-aware conversion for 4:2:0
+         int field_height = height / 2;
+         const uint8_t *in_data[4];
+@@ -2041,8 +2060,13 @@ static int convert_image(producer_avformat self,
+ 
+         int sliced = !getenv("MLT_AVFORMAT_SLICED_PIXFMT_DISABLE") && src_pix_fmt != ctx.dst_format;
+         if (sliced) {
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++            ctx.slice_w = (width < 1000) ? (256 >> (frame->flags & AV_FRAME_FLAG_INTERLACED))
++                                         : (512 >> (frame->flags & AV_FRAME_FLAG_INTERLACED));
++#else
+             ctx.slice_w = (width < 1000) ? (256 >> frame->interlaced_frame)
+                                          : (512 >> frame->interlaced_frame);
++#endif
+         } else {
+             ctx.slice_w = width;
+         }
+@@ -2052,10 +2076,18 @@ static int convert_image(producer_avformat self,
+ 
+         if (sliced && (last_slice_w % 8) == 0
+             && !(ctx.src_format == AV_PIX_FMT_YUV422P && last_slice_w % 16)) {
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++            c *= (frame->flags & AV_FRAME_FLAG_INTERLACED) ? 2 : 1;
++#else
+             c *= frame->interlaced_frame ? 2 : 1;
++#endif
+             mlt_slices_run_normal(c, sliced_h_pix_fmt_conv_proc, &ctx);
+         } else {
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++            c = (frame->flags & AV_FRAME_FLAG_INTERLACED) ? 2 : 1;
++#else
+             c = frame->interlaced_frame ? 2 : 1;
++#endif
+             ctx.slice_w = width;
+             for (i = 0; i < c; i++)
+                 sliced_h_pix_fmt_conv_proc(i, i, c, &ctx);
+@@ -2524,7 +2556,11 @@ static int producer_get_image(mlt_frame frame,
+                         // there are I frames, and find_first_pts() fails as a result.
+                         // Try to set first_pts here after getting pict_type.
+                         if (self->first_pts == AV_NOPTS_VALUE
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++                            && ((self->video_frame->flags & AV_FRAME_FLAG_KEY)
++#else
+                             && (self->video_frame->key_frame
++#endif
+                                 || self->video_frame->pict_type == AV_PICTURE_TYPE_I))
+                             self->first_pts = pts;
+                         if (self->first_pts != AV_NOPTS_VALUE)
+@@ -2558,22 +2594,45 @@ static int producer_get_image(mlt_frame frame,
+                 if (mlt_properties_get(properties, "force_progressive")) {
+                     self->progressive = !!mlt_properties_get_int(properties, "force_progressive");
+                 } else if (self->video_frame && codec_params) {
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++                    self->progressive = !(self->video_frame->flags & AV_FRAME_FLAG_INTERLACED)
++#else
+                     self->progressive = !self->video_frame->interlaced_frame
++#endif
+                                         && (codec_params->field_order == AV_FIELD_PROGRESSIVE
+                                             || codec_params->field_order == AV_FIELD_UNKNOWN);
+                 } else {
+                     self->progressive = 0;
+                 }
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++                if (!self->progressive)
++                    self->video_frame->flags |= AV_FRAME_FLAG_INTERLACED;
++                else
++                    self->video_frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
++#else
+                 self->video_frame->interlaced_frame = !self->progressive;
++#endif
+                 // Detect and correct field order
+                 if (mlt_properties_get(properties, "force_tff")) {
+                     self->top_field_first = !!mlt_properties_get_int(properties, "force_tff");
+                 } else {
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++                    self->top_field_first = (self->video_frame->flags
++                                             & AV_FRAME_FLAG_TOP_FIELD_FIRST)
++#else
+                     self->top_field_first = self->video_frame->top_field_first
++#endif
+                                             || codec_params->field_order == AV_FIELD_TT
+                                             || codec_params->field_order == AV_FIELD_TB;
+                 }
++#if LIBAVUTIL_VERSION_INT >= ((58 << 16) + (7 << 8) + 100)
++                if (self->top_field_first)
++                    self->video_frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++                else
++                    self->video_frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+                 self->video_frame->top_field_first = self->top_field_first;
++#endif
+ #ifdef AVFILTER
+                 if ((self->autorotate || mlt_properties_get(properties, "filtergraph"))
+                     && !setup_filters(self) && self->vfilter_graph) {
+@@ -3690,7 +3749,7 @@ static int audio_codec_init(producer_avformat self, in
+         if (codec && avcodec_open2(codec_context, codec, NULL) >= 0) {
+             // Now store the codec with its destructor
+             if (self->audio_codec[index])
+-                avcodec_close(self->audio_codec[index]);
++                avcodec_free_context(&self->audio_codec[index]);
+             self->audio_codec[index] = codec_context;
+             self->audio_index = index;
+         } else {
Index: multimedia/mpv/patches/patch-demux_demux_mkv_c
===================================================================
RCS file: multimedia/mpv/patches/patch-demux_demux_mkv_c
diff -N multimedia/mpv/patches/patch-demux_demux_mkv_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/mpv/patches/patch-demux_demux_mkv_c	1 Sep 2025 12:38:37 -0000
@@ -0,0 +1,23 @@
+Index: demux/demux_mkv.c
+--- demux/demux_mkv.c.orig
++++ demux/demux_mkv.c
+@@ -2200,16 +2200,16 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_
+             // [0x30..0x37] are component tags utilized for
+             // non-mobile captioning service ("profile A").
+             if (component_tag >= 0x30 && component_tag <= 0x37)
+-                lav->profile = FF_PROFILE_ARIB_PROFILE_A;
++                lav->profile = AV_PROFILE_ARIB_PROFILE_A;
+             break;
+         case 0x0012:
+             // component tag 0x87 signifies a mobile/partial reception
+             // (1seg) captioning service ("profile C").
+             if (component_tag == 0x87)
+-                lav->profile = FF_PROFILE_ARIB_PROFILE_C;
++                lav->profile = AV_PROFILE_ARIB_PROFILE_C;
+             break;
+         }
+-        if (lav->profile == FF_PROFILE_UNKNOWN)
++        if (lav->profile == AV_PROFILE_UNKNOWN)
+             MP_WARN(demuxer, "ARIB caption profile %02x / %04x not supported.\n",
+                     component_tag, data_component_id);
+     }
Index: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_demux_avformat_c
===================================================================
RCS file: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_demux_avformat_c
diff -N multimedia/xine-lib/patches/patch-src_combined_ffmpeg_demux_avformat_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/xine-lib/patches/patch-src_combined_ffmpeg_demux_avformat_c	5 Sep 2025 23:57:47 -0000
@@ -0,0 +1,39 @@
+15250:771f4ae27e58
+15287:1e7b18400886
+
+Index: src/combined/ffmpeg/demux_avformat.c
+--- src/combined/ffmpeg/demux_avformat.c.orig
++++ src/combined/ffmpeg/demux_avformat.c
+@@ -1,5 +1,5 @@
+ /*
+- * Copyright (C) 2013-2022 the xine project
++ * Copyright (C) 2013-2023 the xine project
+  * Copyright (C) 2013-2020 Petri Hintukainen <phintuka@users.sourceforge.net>
+  *
+  * This file is part of xine, a free video player.
+@@ -423,8 +423,13 @@ static int find_avformat_streams(avformat_demux_plugin
+     }
+ 
+ #ifdef XFF_CODECPAR
++#  if XFF_AUDIO_CHANNEL_LAYOUT < 2
+     if (st->codecpar && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+         st->codecpar->sample_rate != 0 && st->codecpar->channels != 0)
++#  else
++    if (st->codecpar && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
++        st->codecpar->sample_rate != 0 && st->codecpar->ch_layout.nb_channels != 0)
++#  endif
+ #else
+     if (st->codec && st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
+         st->codec->sample_rate != 0 && st->codec->channels != 0)
+@@ -501,7 +506,11 @@ static void send_headers_audio(avformat_demux_plugin_t
+   buf->size = extradata_size + sizeof(xine_waveformatex);
+   buf->decoder_info[1] = ctx->sample_rate;
+   buf->decoder_info[2] = ctx->bits_per_coded_sample;
++#if XFF_AUDIO_CHANNEL_LAYOUT < 2
+   buf->decoder_info[3] = ctx->channels;
++#else
++  buf->decoder_info[3] = ctx->ch_layout.nb_channels;
++#endif
+   buf->decoder_flags = BUF_FLAG_HEADER | BUF_FLAG_STDHEADER | BUF_FLAG_FRAME_END;
+ 
+   this->stream->audio_fifo->put (this->stream->audio_fifo, buf);
Index: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_audio_decoder_c
===================================================================
RCS file: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_audio_decoder_c
diff -N multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_audio_decoder_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_audio_decoder_c	5 Sep 2025 23:58:38 -0000
@@ -0,0 +1,293 @@
+15250:771f4ae27e58
+15287:1e7b18400886
+15288:73b833e7fe35
+
+Index: src/combined/ffmpeg/ff_audio_decoder.c
+--- src/combined/ffmpeg/ff_audio_decoder.c.orig
++++ src/combined/ffmpeg/ff_audio_decoder.c
+@@ -1,5 +1,5 @@
+ /*
+- * Copyright (C) 2001-2022 the xine project
++ * Copyright (C) 2001-2024 the xine project
+  *
+  * This file is part of xine, a free video player.
+  *
+@@ -67,6 +67,7 @@ typedef struct {
+ 
+   xine_t                 *xine;
+   float                   gain;
++  int                     bitexact;
+ } ff_audio_class_t;
+ 
+ typedef struct ff_audio_decoder_s {
+@@ -188,14 +189,25 @@ static int ff_aac_mode_parse (ff_audio_decoder_t *this
+         xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
+           "ffmpeg_audio_dec: found AAC ADTS syncword after %d bytes\n", i);
+         if (this->buftype == BUF_AUDIO_AAC_LATM) {
++          uint8_t *ed = NULL;
++          int es = 0;
+           xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
+             "ffmpeg_audio_dec: stream says LATM but is ADTS -> switching decoders\n");
+-          if (this->decoder_ok) {
+-            pthread_mutex_lock (&ffmpeg_lock);
+-            avcodec_close (this->context);
+-            pthread_mutex_unlock (&ffmpeg_lock);
+-            this->decoder_ok = 0;
++          pthread_mutex_lock (&ffmpeg_lock);
++          if (this->context) {
++            ed = this->context->extradata;
++            es = this->context->extradata_size;
++            this->context->extradata = NULL;
++            this->context->extradata_size = 0;
++            XFF_FREE_CONTEXT (this->context);
+           }
++          this->decoder_ok = 0;
++          this->context = XFF_ALLOC_CONTEXT ();
++          if (this->context) {
++            this->context->extradata = ed;
++            this->context->extradata_size = es;
++          }
++          pthread_mutex_unlock (&ffmpeg_lock);
+           this->codec = NULL;
+           ff_audio_open_codec (this, BUF_AUDIO_AAC);
+         }
+@@ -303,7 +315,11 @@ static void ff_audio_init_codec(ff_audio_decoder_t *th
+ 
+   this->context->bits_per_sample = this->ff_bits;
+   this->context->sample_rate = this->ff_sample_rate;
++#if XFF_AUDIO_CHANNEL_LAYOUT < 2
+   this->context->channels    = this->ff_channels;
++#else
++  this->context->ch_layout.nb_channels = this->ff_channels;
++#endif
+   this->context->codec_id    = this->codec->id;
+   this->context->codec_type  = this->codec->type;
+   this->context->codec_tag   = _x_stream_info_get(this->stream, XINE_STREAM_INFO_AUDIO_FOURCC);
+@@ -345,6 +361,11 @@ static int ff_audio_open_codec(ff_audio_decoder_t *thi
+     return -1;
+   }
+ 
++  if (this->class->bitexact)
++    this->context->flags |= CODEC_FLAG_BITEXACT;
++  else
++    this->context->flags &= ~CODEC_FLAG_BITEXACT;
++
+   pthread_mutex_lock (&ffmpeg_lock);
+   if (XFF_AVCODEC_OPEN (this->context, this->codec) < 0) {
+     pthread_mutex_unlock (&ffmpeg_lock);
+@@ -527,17 +548,76 @@ static void ff_audio_output_close(ff_audio_decoder_t *
+   this->ao_mode = 0;
+ }
+ 
++static unsigned int ff_list_channels (uint8_t *list, uint64_t map) {
++  unsigned int n, bit;
++
++  for (n = bit = 0; map; map >>= 1, bit++) {
++    uint32_t b = map & 1;
++
++    list[n] = bit;
++    n += b;
++  }
++  return n;
++}
++
+ static void ff_map_channels (ff_audio_decoder_t *this) {
+   uint64_t ff_map;
++  uint8_t ff_list[64];
++  unsigned int ff_num;
++  const char *type = "native";
+   int caps = this->stream->audio_out->get_capabilities (this->stream->audio_out);
+ 
++#if XFF_AUDIO_CHANNEL_LAYOUT < 2
++
+   /* safety kludge for very old libavcodec */
+-#ifdef AV_CH_FRONT_LEFT
++#  ifdef AV_CH_FRONT_LEFT
+   ff_map = this->context->channel_layout;
+   if (!ff_map) /* wma2 bug */
+-#endif
++#  endif
+     ff_map = ((uint64_t)1 << this->context->channels) - 1;
++  ff_num = ff_list_channels (ff_list, ff_map);
+ 
++#else /* XFF_AUDIO_CHANNEL_LAYOUT == 2 */
++
++  ff_num = this->context->ch_layout.nb_channels;
++  if (ff_num > (int)(sizeof (ff_list) / sizeof (ff_list[0])))
++    ff_num = sizeof (ff_list) / sizeof (ff_list[0]);
++  switch (this->context->ch_layout.order) {
++    const AVChannelCustom *cmap;
++    unsigned int i;
++
++    case AV_CHANNEL_ORDER_UNSPEC:
++      type = "unknown";
++      goto _fallback;
++
++    case AV_CHANNEL_ORDER_NATIVE:
++      ff_map = this->context->ch_layout.u.mask;
++      if (!ff_map) /* wma2 bug */
++        ff_map = ((uint64_t)1 << ff_num) - 1;
++      ff_num = ff_list_channels (ff_list, ff_map);
++      break;
++
++    case AV_CHANNEL_ORDER_CUSTOM:
++      type = "custom";
++      if (!(cmap = this->context->ch_layout.u.map))
++        goto _fallback;
++      ff_map = 0;
++      for (i = 0; i < ff_num; i++) {
++        ff_list[i] = cmap[i].id;
++        ff_map |= (uint64_t)1 << ff_list[i];
++      }
++      break;
++
++    default:
++      type = "unsupported";
++      /* fall through */
++    _fallback:
++      ff_map = ((uint64_t)1 << ff_num) - 1;
++      ff_num = ff_list_channels (ff_list, ff_map);
++  }
++
++#endif
++
+   if ((caps != this->ao_caps) || (ff_map != this->ff_map)) {
+     unsigned int i, j;
+     /* ff: see names[] below; xine: L R RL RR C LFE */
+@@ -562,7 +642,7 @@ static void ff_map_channels (ff_audio_decoder_t *this)
+ 
+     this->ao_caps     = caps;
+     this->ff_map      = ff_map;
+-    this->ff_channels = this->context->channels;
++    this->ff_channels = ff_num;
+ 
+     /* silence out */
+     for (i = 0; i < MAX_CHANNELS; i++)
+@@ -576,20 +656,23 @@ static void ff_map_channels (ff_audio_decoder_t *this)
+       this->left[0] = this->right[0] = 0;
+       tries = wishlist + 0 * num_modes;
+     } else if (this->ff_channels == 2) { /* stereo */
++      /* FIXME: libxine does not yet support audio selection _after_ decoding.
++       * For now, treat the most common "dual mono" case as stereo. */
+       name_map[0] = 0;
+       name_map[1] = 1;
+       this->left[0] = 0;
+       this->right[0] = 1;
+       tries = wishlist + 1 * num_modes;
+     } else {
+-      for (i = j = 0; i < sizeof (base_map) / sizeof (base_map[0]); i++) {
+-        if ((ff_map >> i) & 1) {
+-          int8_t target = base_map[i];
+-          if ((target >= 0) && (this->map[target] < 0))
+-            this->map[target] = j;
+-          name_map[j] = i; /* for debug output below */
+-          j++;
+-        }
++      for (i = 0; i < ff_num; i++) {
++        int8_t target;
++        uint32_t num = ff_list[i];
++        if (num >= sizeof (base_map) / sizeof (base_map[0]))
++          continue;
++        target = base_map[num];
++        if ((target >= 0) && (this->map[target] < 0))
++          this->map[target] = i;
++        name_map[i] = num; /* for debug output below */
+       }
+       this->left[0]  = this->map[0] < 0 ? 0 : this->map[0];
+       this->map[0]   = -1;
+@@ -641,8 +724,8 @@ static void ff_map_channels (ff_audio_decoder_t *this)
+         "rear center",
+         "side left", "side right"
+       };
+-      int8_t buf[200];
+-      int p = sprintf (buf, "ff_audio_dec: channel layout: ");
++      int8_t buf[256];
++      int p = sprintf (buf, "ff_audio_dec: %s channel layout: ", type);
+       int8_t *indx = this->left;
+       for (i = 0; i < 2; i++) {
+         buf[p++] = '[';
+@@ -1310,11 +1393,27 @@ static void ff_audio_reset (audio_decoder_t *this_gen)
+       XFF_FREE_FRAME (this->av_frame);
+     }
+ #endif
++#if 1
++    avcodec_flush_buffers (this->context);
++#else
+     pthread_mutex_lock (&ffmpeg_lock);
+-    avcodec_close (this->context);
+-    if (XFF_AVCODEC_OPEN (this->context, this->codec) < 0)
++    {
++      uint8_t *ed = this->context->extradata;
++      int es = this->context->extradata_size;
++      this->context->extradata = NULL;
++      this->context->extradata_size = 0;
++      XFF_FREE_CONTEXT (this->context);
+       this->decoder_ok = 0;
++      this->context = XFF_ALLOC_CONTEXT ();
++      if (this->context) {
++        this->context->extradata = ed;
++        this->context->extradata_size = es;
++      }
++    }
++    if (XFF_AVCODEC_OPEN (this->context, this->codec) >= 0)
++      this->decoder_ok = 1;
+     pthread_mutex_unlock (&ffmpeg_lock);
++#endif
+   }
+ 
+   ff_audio_reset_parser(this);
+@@ -1352,20 +1451,20 @@ static void ff_audio_dispose (audio_decoder_t *this_ge
+       XFF_FREE_FRAME (this->av_frame);
+     }
+ #endif
+-    pthread_mutex_lock (&ffmpeg_lock);
+-    avcodec_close (this->context);
+-    pthread_mutex_unlock (&ffmpeg_lock);
+   }
++  pthread_mutex_lock (&ffmpeg_lock);
++  if (this->context) {
++    _x_freep (&this->context->extradata);
++    this->context->extradata_size = 0;
++    XFF_FREE_CONTEXT (this->context);
++  }
++  pthread_mutex_unlock (&ffmpeg_lock);
+ 
+   ff_audio_output_close(this);
+ 
+   xine_free_aligned (this->buf);
+   xine_free_aligned (this->decode_buffer);
+ 
+-  _x_freep (&this->context->extradata);
+-  this->context->extradata_size = 0;
+-  XFF_FREE_CONTEXT (this->context);
+-
+   XFF_PACKET_UNREF (this->avpkt);
+ 
+   xine_pts_queue_delete (&this->pts_queue);
+@@ -1447,6 +1546,12 @@ static void dispose_audio_class (audio_decoder_class_t
+   free (this);
+ }
+ 
++static void ff_bitexact_cb (void *user_data, xine_cfg_entry_t *entry) {
++  ff_audio_class_t *class = (ff_audio_class_t *)user_data;
++
++  class->bitexact = entry->num_value;
++}
++
+ void *init_audio_plugin (xine_t *xine, const void *data) {
+ 
+   ff_audio_class_t *this ;
+@@ -1473,6 +1578,13 @@ void *init_audio_plugin (xine_t *xine, const void *dat
+         "This cannot be fixed by volume control, but by this setting."),
+       10, ff_gain_cb, this)
+     / (float)20);
++
++  this->bitexact = xine->config->register_bool (xine->config,
++      "audio.processing.ffmpeg_bitexact", 0,
++      _("Let FFmpeg use precise but slower math"),
++      _("Get slightly better sound, at the expense of speed.\n"
++        "Takes effect with next stream."),
++      10, ff_bitexact_cb, this);
+ 
+   return this;
+ }
Index: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_video_decoder_c
===================================================================
RCS file: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_video_decoder_c
diff -N multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_video_decoder_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ff_video_decoder_c	6 Sep 2025 08:10:16 -0000
@@ -0,0 +1,514 @@
+15287:1e7b18400886
+15288:73b833e7fe35
+
+Index: src/combined/ffmpeg/ff_video_decoder.c
+--- src/combined/ffmpeg/ff_video_decoder.c.orig
++++ src/combined/ffmpeg/ff_video_decoder.c
+@@ -89,6 +89,11 @@
+ # define ENABLE_EMMS
+ #endif
+ 
++/*
++#undef XFF_AVCODEC_SLICE_TABLE
++#define XFF_AVCODEC_SLICE_TABLE 1
++*/
++
+ #define VIDEOBUFSIZE        (128*1024)
+ #define SLICE_BUFFER_SIZE   (1194*1024)
+ 
+@@ -128,6 +133,7 @@ struct ff_video_decoder_s {
+ 
+   int64_t           pts;
+   int64_t           last_pts;
++  int64_t           tagged_pts;
+   int               video_step;
+   int               reported_video_step;
+   uint8_t           pts_tag_pass;
+@@ -147,11 +153,11 @@ struct ff_video_decoder_s {
+   int               bufsize;
+   int               size;
+   int               skipframes;
+-
++#if XFF_AVCODEC_SLICE_TABLE == 1
+   int              *slice_offset_table;
+   int               slice_offset_size;
+   int               slice_offset_pos;
+-
++#endif
+   AVFrame          *av_frame;
+   AVFrame          *av_frame2;
+   AVCodecContext   *context;
+@@ -237,6 +243,13 @@ struct ff_video_decoder_s {
+ #if XFF_VIDEO > 1
+   XFF_PACKET_DECL (avpkt);
+ #endif
++
++#if XFF_AVCODEC_SLICE_TABLE == 2
++  uint8_t          *temp_buf;
++  uint32_t          temp_size;
++  int               slice_num;
++  uint8_t           slice_table[1 + 256 * 8];
++#endif
+ };
+ 
+ /* import color matrix names */
+@@ -551,7 +564,9 @@ static int get_buffer_vaapi_vld (AVCodecContext *conte
+ #  ifdef XFF_FRAME_AGE
+   av_frame->age = 1;
+ #  endif
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
+   av_frame->reordered_opaque = context->reordered_opaque;
++#endif
+ 
+   ffsf = ffsf_new (this);
+   if (!ffsf)
+@@ -862,7 +877,9 @@ static int get_buffer (AVCodecContext *context, AVFram
+ # endif
+ 
+   /* take over pts for this frame to have it reordered */
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
+   av_frame->reordered_opaque = context->reordered_opaque;
++#endif
+ 
+   return 0;
+ }
+@@ -1142,9 +1159,13 @@ static void init_video_codec (ff_video_decoder_t *this
+   if (this->codec->id == CODEC_ID_VC1 &&
+       (!this->bih.biWidth || !this->bih.biHeight)) {
+     /* VC1 codec must be re-opened with correct width and height. */
+-    avcodec_close(this->context);
+-
+-    if (XFF_AVCODEC_OPEN (this->context, this->codec) < 0) {
++    if (this->context) {
++      _x_freep (&this->context->extradata);
++      this->context->extradata_size = 0;
++      XFF_FREE_CONTEXT (this->context);
++    }
++    this->context = XFF_ALLOC_CONTEXT ();
++    if (!(this->context && XFF_AVCODEC_OPEN (this->context, this->codec) >= 0)) {
+       pthread_mutex_unlock(&ffmpeg_lock);
+       xprintf (this->stream->xine, XINE_VERBOSITY_LOG,
+ 	       _("ffmpeg_video_dec: couldn't open decoder (pass 2)\n"));
+@@ -1211,6 +1232,11 @@ static void init_video_codec (ff_video_decoder_t *this
+   /* dont want initial AV_NOPTS_VALUE here */
+   this->context->reordered_opaque = 0;
+ #endif
++
++#ifdef XFF_AVCODEC_FRAME_PTS
++  this->context->time_base.num = 1;
++  this->context->time_base.den = 90000 << 8;
++#endif
+ }
+ 
+ #ifdef ENABLE_VAAPI
+@@ -1769,10 +1795,9 @@ static void ff_handle_header_buffer (ff_video_decoder_
+   this->size += buf->size;
+ 
+   if (buf->decoder_flags & BUF_FLAG_FRAME_END) {
+-    int codec_type;
++    uint32_t codec_type = buf->type & 0xFFFF0000;
+ 
+     lprintf ("header complete\n");
+-    codec_type = buf->type & 0xFFFF0000;
+ 
+     if (buf->decoder_flags & BUF_FLAG_STDHEADER) {
+ 
+@@ -1896,33 +1921,44 @@ static void ff_handle_special_buffer (ff_video_decoder
+ #endif
+   }
+   else if (buf->decoder_info[1] == BUF_SPECIAL_RV_CHUNK_TABLE) {
+-    /* o dear. Multiple decoding threads use individual contexts.
+-      av_decode_video2 () does only copy the _pointer_ to the offsets,
+-      not the offsets themselves. So we must not overwrite anything
+-      that another thread has not yet read. */
+-    int i, l, total;
++    {
++#if XFF_AVCODEC_SLICE_TABLE == 1
++      /* o dear. Multiple decoding threads use individual contexts.
++       * av_decode_video2 () does only copy the _pointer_ to the offsets,
++       * not the offsets themselves. So we must not overwrite anything
++       * that another thread has not yet read. */
++      int i, l, total;
+ 
+-    lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n");
+-    l = buf->decoder_info[2] + 1;
++      lprintf("BUF_SPECIAL_RV_CHUNK_TABLE\n");
++      l = buf->decoder_info[2] + 1;
+ 
+-    total = l * this->class->thread_count;
+-    if (total < SLICE_OFFSET_SIZE)
+-      total = SLICE_OFFSET_SIZE;
+-    if (total > this->slice_offset_size) {
+-      this->slice_offset_table = realloc (this->slice_offset_table, total * sizeof (int));
+-      this->slice_offset_size = total;
+-    }
++      total = l * this->class->thread_count;
++      if (total < SLICE_OFFSET_SIZE)
++        total = SLICE_OFFSET_SIZE;
++      if (total > this->slice_offset_size) {
++        this->slice_offset_table = realloc (this->slice_offset_table, total * sizeof (int));
++        this->slice_offset_size = total;
++      }
+ 
+-    if (this->slice_offset_pos + l > this->slice_offset_size)
+-      this->slice_offset_pos = 0;
+-    this->context->slice_offset = this->slice_offset_table + this->slice_offset_pos;
+-    this->context->slice_count = l;
++      if (this->slice_offset_pos + l > this->slice_offset_size)
++        this->slice_offset_pos = 0;
++      this->context->slice_offset = this->slice_offset_table + this->slice_offset_pos;
++      this->context->slice_count = l;
+ 
+-    lprintf ("slice_count=%d\n", l);
+-    for (i = 0; i < l; i++) {
+-      this->slice_offset_table[this->slice_offset_pos++] =
+-        ((uint32_t *)buf->decoder_info_ptr[2])[(2 * i) + 1];
+-      lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]);
++      lprintf ("slice_count=%d\n", l);
++      for (i = 0; i < l; i++) {
++        this->slice_offset_table[this->slice_offset_pos++] =
++          ((uint32_t *)buf->decoder_info_ptr[2])[(2 * i) + 1];
++        lprintf("slice_offset[%d]=%d\n", i, this->context->slice_offset[i]);
++      }
++#elif XFF_AVCODEC_SLICE_TABLE == 2
++      /* (count-1):1, 1:4, (offs[0]):4, 1:4, (offs[1]:4, ... just in front of the frame bitstream.
++       * reverse engineered from ffmpeg/libavcodec/rv34.c. they seem to expect no
++       * external use of rv decoders, and did not document this. */
++      this->slice_table[0] = buf->decoder_info[2];
++      this->slice_num = this->slice_table[0] + 1;
++      memcpy (this->slice_table + 1, buf->decoder_info_ptr[2], 8 * this->slice_num);
++#endif
+     }
+   }
+ }
+@@ -1957,7 +1993,26 @@ static int64_t ff_tag_pts (ff_video_decoder_t *this, i
+   return (pts * 256) | this->pts_tag_pass;
+ }
+ 
+-static int64_t ff_untag_pts (ff_video_decoder_t *this, int64_t pts) {
++static int64_t ff_untag_pts (ff_video_decoder_t *this, AVFrame *av_frame) {
++  int64_t pts;
++#if defined(XFF_AVCODEC_FRAME_PTS)
++  pts = (av_frame->pts != AV_NOPTS_VALUE) ? av_frame->pts : 0;
++#  if defined(XFF_AVCODEC_REORDERED_OPAQUE)
++  /* paranoia !!! */
++  if (pts != av_frame->reordered_opaque) {
++    xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG,
++      LOG_MODULE ": WARNING: frame pts %" PRId64 " != reordered_opaque %" PRId64 ".\n",
++      pts, av_frame->reordered_opaque);
++    pts = av_frame->reordered_opaque;
++  }
++  av_frame->reordered_opaque = 0;
++#  endif
++#elif defined(XFF_AVCODEC_REORDERED_OPAQUE)
++  pts = av_frame->reordered_opaque;
++  av_frame->reordered_opaque = 0;
++#else
++  pts = this->tagged_pts;
++#endif
+   if ((uint8_t)(pts & 0xff) == this->pts_tag_pass) {
+     /* restore sign. */
+     return pts >> 8;
+@@ -1969,6 +2024,7 @@ static int64_t ff_untag_pts (ff_video_decoder_t *this,
+ 
+ static int decode_video_wrapper (ff_video_decoder_t *this,
+   AVFrame *av_frame, int *err, void *buf, size_t buf_size) {
++  uint32_t tsize = 0;
+   int len;
+ 
+ #if ENABLE_VAAPI
+@@ -1978,11 +2034,36 @@ static int decode_video_wrapper (ff_video_decoder_t *t
+   }
+ #endif /* ENABLE_VAAPI */
+ 
++#if XFF_AVCODEC_SLICE_TABLE == 2
++  if ((this->slice_num > 0) && buf) {
++    uint32_t nsize;
++    tsize = 1 + this->slice_num * 8;
++    nsize = tsize + buf_size + AV_INPUT_BUFFER_PADDING_SIZE;
++    if (this->temp_size < nsize) {
++      nsize = nsize * 3 / 2;
++      free (this->temp_buf);
++      this->temp_buf = malloc (nsize);
++      if (!this->temp_buf)
++        nsize = 0;
++      this->temp_size = nsize;
++      nsize = tsize + buf_size + AV_INPUT_BUFFER_PADDING_SIZE;
++    }
++    if (this->temp_size >= nsize) {
++      memcpy (this->temp_buf, this->slice_table, tsize);
++      memcpy (this->temp_buf + tsize, buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
++      buf = this->temp_buf;
++    }
++    this->slice_num = 0;
++  }
++#endif
++
+ #if XFF_VIDEO > 1
+   this->avpkt->data = buf;
+-  this->avpkt->size = buf_size;
++  this->avpkt->size = buf_size + tsize;
+   this->avpkt->flags = AV_PKT_FLAG_KEY;
+-
++# ifdef XFF_AVCODEC_FRAME_PTS
++  this->avpkt->pts = this->tagged_pts;
++# endif
+ # if XFF_PALETTE == 2 || XFF_PALETTE == 3
+   if (buf && this->palette_changed) {
+     uint8_t *sd = av_packet_new_side_data (this->avpkt, AV_PKT_DATA_PALETTE, 256 * 4);
+@@ -2092,9 +2173,14 @@ static void ff_handle_mpeg12_buffer (ff_video_decoder_
+ #endif
+ 
+     /* apply valid pts to first frame _starting_ thereafter only */
+-    if (this->pts && !this->context->reordered_opaque) {
+-      this->context->reordered_opaque = 
+-      this->av_frame->reordered_opaque = ff_tag_pts (this, this->pts);
++    if (this->pts && !this->tagged_pts) {
++      this->tagged_pts = ff_tag_pts (this, this->pts);
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
++      this->context->reordered_opaque = this->av_frame->reordered_opaque = this->tagged_pts;
++#endif
++#ifdef XFF_AVCODEC_FRAME_PTS
++      this->av_frame->pts = this->tagged_pts;
++#endif
+       this->pts = 0;
+     }
+ 
+@@ -2201,13 +2287,20 @@ static void ff_handle_mpeg12_buffer (ff_video_decoder_
+       }
+ 
+       /* transfer some more frame settings for deinterlacing */
+-      img->progressive_frame = !this->av_frame->interlaced_frame;
+-      img->top_field_first   = this->av_frame->top_field_first;
++#if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 58, 7, 100 ))
++      img->progressive_frame = !(this->av_frame->flags & AV_FRAME_FLAG_INTERLACED);
++      img->top_field_first   = this->av_frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
++      img->progressive_frame = !this->av_frame2->interlaced_frame;
++      img->top_field_first   = this->av_frame2->top_field_first;
++#endif
+ 
+       /* get back reordered pts */
+-      img->pts = ff_untag_pts (this, this->av_frame->reordered_opaque);
+-      this->av_frame->reordered_opaque = 0;
++      img->pts = ff_untag_pts (this, this->av_frame);
++      this->tagged_pts = 0;
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
+       this->context->reordered_opaque = 0;
++#endif
+ 
+       if (this->av_frame->repeat_pict)
+         img->duration = this->video_step * 3 / 2;
+@@ -2285,14 +2378,14 @@ static int ff_video_step_get (ff_video_decoder_t *this
+     return step;
+ 
+   /* good: 2 * 1001 / 48000. */
+-  step = (int64_t)90000 * this->context->ticks_per_frame
++  step = (int64_t)90000 * (this->context->codec_descriptor->props & AV_CODEC_PROP_FIELDS ? 2 : 1)
+        * this->context->time_base.num / this->context->time_base.den;
+   if (step >= 90)
+     return step;
+ 
+   /* bad: 2 * 1 / 60000. seen this once from broken h.264 video usability info (VUI).
+    * VAAPI seems to apply a similar HACK.*/
+-  step = (int64_t)90000000 * this->context->ticks_per_frame
++  step = (int64_t)90000000 * (this->context->codec_descriptor->props & AV_CODEC_PROP_FIELDS ? 2 : 1)
+        * this->context->time_base.num / this->context->time_base.den;
+   return step;
+ }
+@@ -2328,9 +2421,14 @@ static void ff_handle_buffer (ff_video_decoder_t *this
+   }
+ 
+   if (this->size == 0) {
++    this->tagged_pts = ff_tag_pts (this, this->pts);
+     /* take over pts when we are about to buffer a frame */
+-    this->av_frame->reordered_opaque = ff_tag_pts(this, this->pts);
+-    this->context->reordered_opaque = ff_tag_pts(this, this->pts);
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
++    this->av_frame->reordered_opaque = this->context->reordered_opaque = this->tagged_pts;
++#endif
++#ifdef XFF_AVCODEC_FRAME_PTS
++    this->av_frame->pts = this->tagged_pts;
++#endif
+     this->pts = 0;
+   }
+ 
+@@ -2403,7 +2501,10 @@ static void ff_handle_buffer (ff_video_decoder_t *this
+         need_unref = 1;
+ #endif
+         /* reset consumed pts value */
+-        this->context->reordered_opaque = ff_tag_pts(this, 0);
++        this->tagged_pts = ff_tag_pts (this, 0);
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
++        this->context->reordered_opaque = this->tagged_pts;
++#endif
+ 
+         if (err) {
+ 
+@@ -2434,13 +2535,16 @@ static void ff_handle_buffer (ff_video_decoder_t *this
+           this->size -= len;
+ 
+           if (this->size > 0) {
+-            ff_check_bufsize(this, this->size);
+             memmove (this->buf, &chunk_buf[offset], this->size);
+             chunk_buf = this->buf;
+-
+             /* take over pts for next access unit */
+-            this->av_frame->reordered_opaque = ff_tag_pts(this, this->pts);
+-            this->context->reordered_opaque = ff_tag_pts(this, this->pts);
++            this->tagged_pts = ff_tag_pts (this, this->pts);
++#ifdef XFF_AVCODEC_REORDERED_OPAQUE
++            this->av_frame->reordered_opaque = this->context->reordered_opaque = this->tagged_pts;
++#endif
++#ifdef XFF_AVCODEC_FRAME_PTS
++            this->av_frame->pts = this->tagged_pts;
++#endif
+             this->pts = 0;
+           }
+         }
+@@ -2557,11 +2661,10 @@ static void ff_handle_buffer (ff_video_decoder_t *this
+           ff_convert_frame(this, img, this->av_frame);
+         }
+ 
+-        img->pts  = ff_untag_pts(this, this->av_frame->reordered_opaque);
+-        this->av_frame->reordered_opaque = 0;
++        img->pts  = ff_untag_pts(this, this->av_frame);
+ 
+-        /* workaround for weird 120fps streams */
+-        if( video_step_to_use == 750 ) {
++        /* workaround for weird 120fps streams, as well as some rv20 with frame duration 3pts. */
++        if (video_step_to_use <= 750) {
+           /* fallback to the VIDEO_PTS_MODE */
+           video_step_to_use = 0;
+         }
+@@ -2575,8 +2678,13 @@ static void ff_handle_buffer (ff_video_decoder_t *this
+           img->duration = video_step_to_use;
+ 
+         /* transfer some more frame settings for deinterlacing */
+-        img->progressive_frame = !this->av_frame->interlaced_frame;
+-        img->top_field_first   = this->av_frame->top_field_first;
++#if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 58, 7, 100 ))
++        img->progressive_frame = !(this->av_frame->flags & AV_FRAME_FLAG_INTERLACED);
++        img->top_field_first   = this->av_frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
++        img->progressive_frame = !this->av_frame2->interlaced_frame;
++        img->top_field_first   = this->av_frame2->top_field_first;
++#endif
+ 
+         this->skipframes = img->draw(img, this->stream);
+         this->state = STATE_FRAME_SENT;
+@@ -2598,8 +2706,7 @@ static void ff_handle_buffer (ff_video_decoder_t *this
+                                                 this->output_format,
+                                                 VO_BOTH_FIELDS|this->frame_flags);
+       /* set PTS to allow early syncing */
+-      img->pts       = ff_untag_pts(this, this->av_frame->reordered_opaque);
+-      this->av_frame->reordered_opaque = 0;
++      img->pts       = ff_untag_pts(this, this->av_frame);
+ 
+       img->duration  = video_step_to_use;
+ 
+@@ -2781,13 +2888,18 @@ static void ff_flush_internal (ff_video_decoder_t *thi
+       ff_convert_frame (this, img, this->av_frame2);
+     }
+ 
+-    img->pts = ff_untag_pts (this, this->av_frame2->reordered_opaque);
++    img->pts = ff_untag_pts (this, this->av_frame2);
+ 
+-    if (video_step_to_use == 750)
++    if (video_step_to_use <= 750)
+       video_step_to_use = 0;
+     img->duration = this->av_frame2->repeat_pict ? video_step_to_use * 3 / 2 : video_step_to_use;
++#if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 58, 7, 100 ))
++    img->progressive_frame = !(this->av_frame->flags & AV_FRAME_FLAG_INTERLACED);
++    img->top_field_first   = this->av_frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+     img->progressive_frame = !this->av_frame2->interlaced_frame;
+     img->top_field_first   = this->av_frame2->top_field_first;
++#endif
+ 
+     this->skipframes = img->draw (img, this->stream);
+     if (free_img)
+@@ -2887,6 +2999,9 @@ static void ff_reset (video_decoder_t *this_gen) {
+     mpeg_parser_reset(this->mpeg_parser);
+ 
+   /* this->pts_tag_pass = 0; */
++#if XFF_AVCODEC_SLICE_TABLE == 2
++  this->slice_num = 0;
++#endif
+ }
+ 
+ static void ff_dispose (video_decoder_t *this_gen) {
+@@ -2899,10 +3014,15 @@ static void ff_dispose (video_decoder_t *this_gen) {
+   rgb2yuy2_free (this->rgb2yuy2);
+ 
+   if (this->decoder_ok) {
++    uint8_t *ed;
+ 
+     pthread_mutex_lock(&ffmpeg_lock);
+-    avcodec_close (this->context);
++    ed = this->context->extradata;
++    this->context->extradata = NULL;
++    this->context->extradata_size = 0;
++    XFF_FREE_CONTEXT (this->context);
+     pthread_mutex_unlock(&ffmpeg_lock);
++    _x_freep (&ed);
+ 
+ #ifdef ENABLE_DIRECT_RENDERING
+     ff_free_dr1_frames (this, 1);
+@@ -2910,17 +3030,18 @@ static void ff_dispose (video_decoder_t *this_gen) {
+ 
+     this->stream->video_out->close(this->stream->video_out, this->stream);
+     this->decoder_ok = 0;
+-  }
+-
+-  if (this->slice_offset_table)
+-    free (this->slice_offset_table);
+-
+-  if (this->context) {
++  } else if (this->context) {
+     _x_freep (&this->context->extradata);
+     this->context->extradata_size = 0;
+     XFF_FREE_CONTEXT (this->context);
+   }
+ 
++#if XFF_AVCODEC_SLICE_TABLE == 1
++  free (this->slice_offset_table);
++#elif XFF_AVCODEC_SLICE_TABLE == 2
++  free (this->temp_buf);
++#endif
++
+ #if XFF_VIDEO > 1
+   XFF_PACKET_UNREF (this->avpkt);
+ #endif
+@@ -3007,21 +3128,25 @@ static video_decoder_t *ff_video_open_plugin (video_de
+   this->decoder_ok      = 0;
+   this->aspect_ratio    = 0;
+   this->pts_tag_pass    = 0;
+-#ifdef HAVE_POSTPROC
++#  ifdef HAVE_POSTPROC
+   this->pp_quality      = 0;
+   this->our_context     = NULL;
+   this->our_mode        = NULL;
+-#endif
++#  endif
+   this->mpeg_parser     = NULL;
+   this->set_stream_info = 0;
+   this->rgb2yuy2        = NULL;
+-#ifdef ENABLE_VAAPI
++#  ifdef ENABLE_VAAPI
+   this->accel           = NULL;
+   this->accel_img       = NULL;
+-#endif
+-#if XFF_VIDEO == 3
++#  endif
++#  if XFF_VIDEO == 3
+   this->flush_packet_sent = 0;
+-#endif
++#  endif
++#  if XFF_AVCODEC_SLICE_TABLE == 2
++  this->temp_size       = 0;
++  this->temp_buf        = NULL;
++#  endif
+ #endif
+ 
+   this->video_decoder.decode_data   = ff_decode_data;
Index: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ffmpeg_compat_h
===================================================================
RCS file: multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ffmpeg_compat_h
diff -N multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ffmpeg_compat_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ multimedia/xine-lib/patches/patch-src_combined_ffmpeg_ffmpeg_compat_h	12 Sep 2025 22:10:45 -0000
@@ -0,0 +1,12 @@
+Index: src/combined/ffmpeg/ffmpeg_compat.h
+--- src/combined/ffmpeg/ffmpeg_compat.h.orig
++++ src/combined/ffmpeg/ffmpeg_compat.h
+@@ -55,7 +55,7 @@
+ 
+ /* reordered_opaque appeared in libavcodec 51.68.0 */
+ #define XFF_AVCODEC_REORDERED_OPAQUE
+-#if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(51,68,0)
++#if LIBAVCODEC_VERSION_INT < XFF_INT_VERSION(51,68,0) || !defined(FF_API_REORDERED_OPAQUE)
+ # undef XFF_AVCODEC_REORDERED_OPAQUE
+ #endif
+ 
Index: net/guacamole/server/patches/patch-src_guacenc_video_c
===================================================================
RCS file: net/guacamole/server/patches/patch-src_guacenc_video_c
diff -N net/guacamole/server/patches/patch-src_guacenc_video_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ net/guacamole/server/patches/patch-src_guacenc_video_c	10 Sep 2025 20:26:55 -0000
@@ -0,0 +1,13 @@
+Index: src/guacenc/video.c
+--- src/guacenc/video.c.orig
++++ src/guacenc/video.c
+@@ -499,7 +499,9 @@ int guacenc_video_free(guacenc_video* video) {
+ 
+     /* Clean up encoding context */
+     if (video->context != NULL) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+         avcodec_close(video->context);
++#endif
+         avcodec_free_context(&(video->context));
+     }
+ 
Index: net/tdesktop/patches/patch-Telegram_SourceFiles_ffmpeg_ffmpeg_utility_cpp
===================================================================
RCS file: net/tdesktop/patches/patch-Telegram_SourceFiles_ffmpeg_ffmpeg_utility_cpp
diff -N net/tdesktop/patches/patch-Telegram_SourceFiles_ffmpeg_ffmpeg_utility_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ net/tdesktop/patches/patch-Telegram_SourceFiles_ffmpeg_ffmpeg_utility_cpp	16 Sep 2025 00:11:41 -0000
@@ -0,0 +1,22 @@
+Index: Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
+--- Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp.orig
++++ Telegram/SourceFiles/ffmpeg/ffmpeg_utility.cpp
+@@ -683,10 +683,18 @@ int DurationByPacket(const Packet &packet, AVRational 
+ }
+ 
+ int ReadRotationFromMetadata(not_null<AVStream*> stream) {
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 15, 100)
++	const AVPacketSideData *side_data = av_packet_side_data_get(
++		stream->codecpar->coded_side_data,
++		stream->codecpar->nb_coded_side_data,
++		AV_PKT_DATA_DISPLAYMATRIX);
++	const auto displaymatrix = side_data ? (AVCPBProperties *)side_data->data : NULL;
++#else
+ 	const auto displaymatrix = av_stream_get_side_data(
+ 		stream,
+ 		AV_PKT_DATA_DISPLAYMATRIX,
+ 		nullptr);
++#endif
+ 	auto theta = 0;
+ 	if (displaymatrix) {
+ 		theta = -round(av_display_rotation_get((int32_t*)displaymatrix));
Index: telephony/linphone/mediastreamer2/patches/patch-src_videofilters_h264dec_cpp
===================================================================
RCS file: /home/cvs/ports/telephony/linphone/mediastreamer2/patches/patch-src_videofilters_h264dec_cpp,v
diff -u -p -r1.1 patch-src_videofilters_h264dec_cpp
--- telephony/linphone/mediastreamer2/patches/patch-src_videofilters_h264dec_cpp	24 Nov 2024 08:51:46 -0000	1.1
+++ telephony/linphone/mediastreamer2/patches/patch-src_videofilters_h264dec_cpp	2 Sep 2025 08:34:04 -0000
@@ -22,7 +22,33 @@ Index: src/videofilters/h264dec.cpp
  	error = avcodec_open2(&d->av_context, codec, NULL);
  	if (error != 0) {
  		ms_fatal("avcodec_open() failed.");
-@@ -162,7 +160,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f, DecData *s, 
+@@ -113,7 +111,12 @@ static void dec_preprocess(MSFilter *f) {
+ }
+ 
+ static void dec_reinit(DecData *d) {
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 	avcodec_close(&d->av_context);
++#else
++	AVCodecContext *avctx = &d->av_context;
++	avcodec_free_context(&avctx);
++#endif
+ 	dec_open(d);
+ }
+ 
+@@ -125,7 +128,12 @@ static void dec_postprocess(MSFilter *f) {
+ static void dec_uninit(MSFilter *f) {
+ 	DecData *d = (DecData *)f->data;
+ 	delete d->unpacker;
++#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 3, 100)
+ 	avcodec_close(&d->av_context);
++#else
++	AVCodecContext *avctx = &d->av_context;
++	avcodec_free_context(&avctx);
++#endif
+ 	if (d->sps) freemsg(d->sps);
+ 	if (d->pps) freemsg(d->pps);
+ 	if (d->orig) av_frame_free(&d->orig);
+@@ -162,7 +170,7 @@ static mblk_t *get_as_yuvmsg(MSFilter *f, DecData *s, 
  		ms_error("%s: error in sws_scale().", f->desc->name);
  	}
  #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50, 43, 0) // backward compatibility with Debian Squeeze (6.0)
Index: wayland/wf-recorder/patches/patch-src_frame-writer_cpp
===================================================================
RCS file: wayland/wf-recorder/patches/patch-src_frame-writer_cpp
diff -N wayland/wf-recorder/patches/patch-src_frame-writer_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ wayland/wf-recorder/patches/patch-src_frame-writer_cpp	4 Sep 2025 20:34:41 -0000
@@ -0,0 +1,14 @@
+https://github.com/ammen99/wf-recorder/commit/560bb92d3ddaeb31d7af77d22d01b0050b45bebe
+
+Index: src/frame-writer.cpp
+--- src/frame-writer.cpp.orig
++++ src/frame-writer.cpp
+@@ -371,7 +371,7 @@ void FrameWriter::init_video_filters(const AVCodec *co
+     this->videoCodecCtx->height = filter_output->h;
+     this->videoCodecCtx->pix_fmt = (AVPixelFormat)filter_output->format;
+     this->videoCodecCtx->time_base = filter_output->time_base;
+-    this->videoCodecCtx->framerate = filter_output->frame_rate; // can be 1/0 if unknown
++    this->videoCodecCtx->framerate = AVRational{1,0};
+     this->videoCodecCtx->sample_aspect_ratio = filter_output->sample_aspect_ratio;
+ 
+     this->hw_frame_context = av_buffersink_get_hw_frames_ctx(
Index: x11/kde-applications/ffmpegthumbs/patches/patch-ffmpegthumbnailer_moviedecoder_cpp
===================================================================
RCS file: x11/kde-applications/ffmpegthumbs/patches/patch-ffmpegthumbnailer_moviedecoder_cpp
diff -N x11/kde-applications/ffmpegthumbs/patches/patch-ffmpegthumbnailer_moviedecoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-applications/ffmpegthumbs/patches/patch-ffmpegthumbnailer_moviedecoder_cpp	10 Sep 2025 19:58:43 -0000
@@ -0,0 +1,53 @@
+https://github.com/KDE/ffmpegthumbs/commit/d39fae995420d5b78d40a51a5a748c1ecd74a0ee
+
+Index: ffmpegthumbnailer/moviedecoder.cpp
+--- ffmpegthumbnailer/moviedecoder.cpp.orig
++++ ffmpegthumbnailer/moviedecoder.cpp
+@@ -89,7 +89,7 @@ void MovieDecoder::destroy()
+ {
+     deleteFilterGraph();
+     if (m_pVideoCodecContext) {
+-        avcodec_close(m_pVideoCodecContext);
++        avcodec_free_context(&m_pVideoCodecContext);
+         m_pVideoCodecContext = nullptr;
+     }
+     m_pVideoStream = nullptr;
+@@ -215,7 +215,7 @@ void MovieDecoder::seek(int timeInSeconds)
+         }
+ 
+         ++keyFrameAttempts;
+-    } while ((!gotFrame || !m_pFrame->key_frame) && keyFrameAttempts < 200);
++    } while ((!gotFrame || !(m_pFrame->flags & AV_FRAME_FLAG_KEY)) && keyFrameAttempts < 200);
+ 
+     if (gotFrame == 0) {
+         qCDebug(ffmpegthumbs_LOG) << "Seeking in video failed";
+@@ -263,15 +263,15 @@ QImageIOHandler::Transformations MovieDecoder::transfo
+         return ret;
+     }
+ 
+-    for (int i=0; i<m_pVideoStream->nb_side_data; i++) {
+-        if (m_pVideoStream->side_data[i].type != AV_PKT_DATA_DISPLAYMATRIX) {
++    for (int i=0; i<m_pVideoStream->codecpar->nb_coded_side_data; i++) {
++        if (m_pVideoStream->codecpar->coded_side_data[i].type != AV_PKT_DATA_DISPLAYMATRIX) {
+             continue;
+         }
+-        if (m_pVideoStream->side_data[i].size != sizeof(int32_t) * 9) {
+-            qCWarning(ffmpegthumbs_LOG) << "Invalid display matrix size" << m_pVideoStream->side_data[i].size << "expected" << sizeof(int32_t) * 9;
++        if (m_pVideoStream->codecpar->coded_side_data[i].size != sizeof(int32_t) * 9) {
++            qCWarning(ffmpegthumbs_LOG) << "Invalid display matrix size" << m_pVideoStream->codecpar->coded_side_data[i].size << "expected" << sizeof(int32_t) * 9;
+             continue;
+         }
+-        int32_t *matrix = reinterpret_cast<int32_t*>(m_pVideoStream->side_data[i].data);
++        int32_t *matrix = reinterpret_cast<int32_t*>(m_pVideoStream->codecpar->coded_side_data[i].data);
+         double rotation = av_display_rotation_get(matrix);
+         if (qFuzzyCompare(rotation, 0.)) {
+             ret |= QImageIOHandler::TransformationNone;
+@@ -404,7 +404,7 @@ bool MovieDecoder::processFilterGraph(AVFrame *dst, co
+ 
+ void MovieDecoder::getScaledVideoFrame(int scaledSize, bool maintainAspectRatio, VideoFrame& videoFrame)
+ {
+-    if (m_pFrame->interlaced_frame) {
++    if (m_pFrame->flags & AV_FRAME_FLAG_INTERLACED) {
+         processFilterGraph((AVFrame*) m_pFrame, (AVFrame*) m_pFrame, m_pVideoCodecContext->pix_fmt,
+                               m_pVideoCodecContext->width, m_pVideoCodecContext->height);
+     }
Index: x11/kde-plasma/kpipewire/patches/patch-src_h264vaapiencoder_cpp
===================================================================
RCS file: x11/kde-plasma/kpipewire/patches/patch-src_h264vaapiencoder_cpp
diff -N x11/kde-plasma/kpipewire/patches/patch-src_h264vaapiencoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-plasma/kpipewire/patches/patch-src_h264vaapiencoder_cpp	4 Sep 2025 11:06:40 -0000
@@ -0,0 +1,29 @@
+Index: src/h264vaapiencoder.cpp
+--- src/h264vaapiencoder.cpp.orig
++++ src/h264vaapiencoder.cpp
+@@ -130,13 +130,25 @@ bool H264VAAPIEncoder::initialize(const QSize &size)
+ 
+     switch (m_profile) {
+     case H264Profile::Baseline:
++#ifdef AV_PROFILE_H264_CONSTRAINED_BASELINE
++        m_avCodecContext->profile = AV_PROFILE_H264_CONSTRAINED_BASELINE;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
++#endif
+         break;
+     case H264Profile::Main:
++#ifdef AV_PROFILE_H264_MAIN
++        m_avCodecContext->profile = AV_PROFILE_H264_MAIN;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_MAIN;
++#endif
+         break;
+     case H264Profile::High:
++#ifdef AV_PROFILE_H264_HIGH
++        m_avCodecContext->profile = AV_PROFILE_H264_HIGH;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_HIGH;
++#endif
+         break;
+     }
+ 
Index: x11/kde-plasma/kpipewire/patches/patch-src_libopenh264encoder_cpp
===================================================================
RCS file: x11/kde-plasma/kpipewire/patches/patch-src_libopenh264encoder_cpp
diff -N x11/kde-plasma/kpipewire/patches/patch-src_libopenh264encoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-plasma/kpipewire/patches/patch-src_libopenh264encoder_cpp	4 Sep 2025 11:06:40 -0000
@@ -0,0 +1,29 @@
+Index: src/libopenh264encoder.cpp
+--- src/libopenh264encoder.cpp.orig
++++ src/libopenh264encoder.cpp
+@@ -64,13 +64,25 @@ bool LibOpenH264Encoder::initialize(const QSize &size)
+         // passes that through, but libopenh264 only allows BASELINE.
+         // Until that bug is fixed there'll always be a warning that the
+         // profile is not supported (https://github.com/cisco/openh264/issues/3613)
++#ifdef AV_PROFILE_H264_CONSTRAINED_BASELINE
++        m_avCodecContext->profile = AV_PROFILE_H264_CONSTRAINED_BASELINE;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
++#endif
+         break;
+     case H264Profile::Main:
++#ifdef AV_PROFILE_H264_MAIN
++        m_avCodecContext->profile = AV_PROFILE_H264_MAIN;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_MAIN;
++#endif
+         break;
+     case H264Profile::High:
++#ifdef AV_PROFILE_H264_HIGH
++        m_avCodecContext->profile = AV_PROFILE_H264_HIGH;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_HIGH;
++#endif
+         break;
+     }
+ 
Index: x11/kde-plasma/kpipewire/patches/patch-src_libx264encoder_cpp
===================================================================
RCS file: x11/kde-plasma/kpipewire/patches/patch-src_libx264encoder_cpp
diff -N x11/kde-plasma/kpipewire/patches/patch-src_libx264encoder_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/kde-plasma/kpipewire/patches/patch-src_libx264encoder_cpp	4 Sep 2025 11:07:28 -0000
@@ -0,0 +1,29 @@
+Index: src/libx264encoder.cpp
+--- src/libx264encoder.cpp.orig
++++ src/libx264encoder.cpp
+@@ -68,13 +68,25 @@ bool LibX264Encoder::initialize(const QSize &size)
+ 
+     switch (m_profile) {
+     case H264Profile::Baseline:
++#ifdef AV_PROFILE_H264_BASELINE
++        m_avCodecContext->profile = AV_PROFILE_H264_BASELINE;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_BASELINE;
++#endif
+         break;
+     case H264Profile::Main:
++#ifdef AV_PROFILE_H264_MAIN
++        m_avCodecContext->profile = AV_PROFILE_H264_MAIN;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_MAIN;
++#endif
+         break;
+     case H264Profile::High:
++#ifdef AV_PROFILE_H264_HIGH
++        m_avCodecContext->profile = AV_PROFILE_H264_HIGH;
++#else
+         m_avCodecContext->profile = FF_PROFILE_H264_HIGH;
++#endif
+         break;
+     }
+ 
Index: x11/mplayer/patches/patch-libaf_af_lavcac3enc_c
===================================================================
RCS file: x11/mplayer/patches/patch-libaf_af_lavcac3enc_c
diff -N x11/mplayer/patches/patch-libaf_af_lavcac3enc_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libaf_af_lavcac3enc_c	12 Sep 2025 12:29:06 -0000
@@ -0,0 +1,21 @@
+Index: libaf/af_lavcac3enc.c
+--- libaf/af_lavcac3enc.c.orig
++++ libaf/af_lavcac3enc.c
+@@ -101,7 +101,7 @@ static int control(struct af_instance_s *af, int cmd, 
+                 s->lavc_actx->bit_rate != bit_rate) {
+ 
+             if (s->lavc_actx->codec)
+-                avcodec_close(s->lavc_actx);
++                avcodec_free_context(&s->lavc_actx);
+ 
+             // Put sample parameters
+             s->lavc_actx->ch_layout.nb_channels = af->data->nch;
+@@ -158,7 +158,7 @@ static void uninit(struct af_instance_s* af)
+         af->setup = NULL;
+         if(s->lavc_actx) {
+             if (s->lavc_actx->codec)
+-                avcodec_close(s->lavc_actx);
++                avcodec_free_context(&s->lavc_actx);
+             free(s->lavc_actx);
+         }
+         free(s->pending_data);
Index: x11/mplayer/patches/patch-libmpcodecs_ad_ffmpeg_c
===================================================================
RCS file: x11/mplayer/patches/patch-libmpcodecs_ad_ffmpeg_c
diff -N x11/mplayer/patches/patch-libmpcodecs_ad_ffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libmpcodecs_ad_ffmpeg_c	12 Sep 2025 12:27:15 -0000
@@ -0,0 +1,12 @@
+Index: libmpcodecs/ad_ffmpeg.c
+--- libmpcodecs/ad_ffmpeg.c.orig
++++ libmpcodecs/ad_ffmpeg.c
+@@ -196,7 +196,7 @@ static void uninit(sh_audio_t *sh)
+ {
+     AVCodecContext *lavc_context = sh->context;
+ 
+-    if (avcodec_close(lavc_context) < 0)
++    avcodec_free_context(&lavc_context);
+ 	mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec);
+     av_freep(&lavc_context->opaque);
+     av_freep(&lavc_context->extradata);
Index: x11/mplayer/patches/patch-libmpcodecs_vd_ffmpeg_c
===================================================================
RCS file: x11/mplayer/patches/patch-libmpcodecs_vd_ffmpeg_c
diff -N x11/mplayer/patches/patch-libmpcodecs_vd_ffmpeg_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libmpcodecs_vd_ffmpeg_c	12 Sep 2025 12:51:28 -0000
@@ -0,0 +1,26 @@
+Index: libmpcodecs/vd_ffmpeg.c
+--- libmpcodecs/vd_ffmpeg.c.orig
++++ libmpcodecs/vd_ffmpeg.c
+@@ -511,9 +511,6 @@ static void uninit(sh_video_t *sh){
+     }
+ 
+     if (avctx) {
+-        if (avctx->codec && avcodec_close(avctx) < 0)
+-            mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_CantCloseCodec);
+-
+         av_freep(&avctx->extradata);
+         av_freep(&avctx->hwaccel_context);
+     }
+@@ -1060,8 +1057,10 @@ static mp_image_t *decode(sh_video_t *sh, void *data, 
+ //    mpi->qscale = av_frame_get_qp_table(pic, &mpi->qstride, &mpi->qscale_type);
+     mpi->pict_type=pic->pict_type;
+     mpi->fields = MP_IMGFIELD_ORDERED;
+-    if(pic->interlaced_frame) mpi->fields |= MP_IMGFIELD_INTERLACED;
+-    if(pic->top_field_first ) mpi->fields |= MP_IMGFIELD_TOP_FIRST;
++    if(pic->flags & AV_FRAME_FLAG_INTERLACED)
++        mpi->fields |= MP_IMGFIELD_INTERLACED;
++    if(pic->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)
++        mpi->fields |= MP_IMGFIELD_TOP_FIRST;
+     if(pic->repeat_pict == 1) mpi->fields |= MP_IMGFIELD_REPEAT_FIRST;
+ 
+     return mpi;
Index: x11/mplayer/patches/patch-libmpcodecs_ve_lavc_c
===================================================================
RCS file: x11/mplayer/patches/patch-libmpcodecs_ve_lavc_c
diff -N x11/mplayer/patches/patch-libmpcodecs_ve_lavc_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libmpcodecs_ve_lavc_c	12 Sep 2025 12:53:07 -0000
@@ -0,0 +1,49 @@
+Index: libmpcodecs/ve_lavc.c
+--- libmpcodecs/ve_lavc.c.orig
++++ libmpcodecs/ve_lavc.c
+@@ -152,7 +152,7 @@ static int lavc_param_video_global_header= 0;
+ static int lavc_param_mv0_threshold = 256;
+ static int lavc_param_refs = 1;
+ static int lavc_param_b_sensitivity = 40;
+-static int lavc_param_level = FF_LEVEL_UNKNOWN;
++static int lavc_param_level = AV_LEVEL_UNKNOWN;
+ 
+ char *lavc_param_acodec = "mp2";
+ int lavc_param_atag = 0;
+@@ -721,13 +721,21 @@ static int put_image(struct vf_instance *vf, mp_image_
+     pic->pict_type = is_forced_key_frame(pts) ? AV_PICTURE_TYPE_I : 0;
+ 
+     if(lavc_param_interlaced_dct){
+-        if((mpi->fields & MP_IMGFIELD_ORDERED) && (mpi->fields & MP_IMGFIELD_INTERLACED))
+-            pic->top_field_first= !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
+-        else
+-            pic->top_field_first= 1;
++        if((mpi->fields & MP_IMGFIELD_ORDERED) && (mpi->fields & MP_IMGFIELD_INTERLACED)) {
++			if (!!(mpi->fields & MP_IMGFIELD_TOP_FIRST))
++				pic->flags |= MP_IMGFIELD_TOP_FIRST;
++			else
++				pic->flags &= ~MP_IMGFIELD_TOP_FIRST;
++        } else {
++			pic->flags |= MP_IMGFIELD_TOP_FIRST;
++		}
+ 
+-        if(lavc_param_top!=-1)
+-            pic->top_field_first= lavc_param_top;
++        if(lavc_param_top!=-1) {
++			if (lavc_param_top)
++				pic->flags |= MP_IMGFIELD_TOP_FIRST;
++			else
++				pic->flags &= ~MP_IMGFIELD_TOP_FIRST;
++		}
+     }
+ 
+     return encode_frame(vf, pic, pts) >= 0;
+@@ -853,7 +861,7 @@ static void uninit(struct vf_instance *vf){
+     av_freep(&lavc_venc_context->inter_matrix);
+ 
+     if (lavc_venc_context->codec)
+-        avcodec_close(lavc_venc_context);
++        avcodec_free_context(&lavc_venc_context);
+ 
+     if(stats_file) fclose(stats_file);
+ 
Index: x11/mplayer/patches/patch-libmpcodecs_vf_screenshot_c
===================================================================
RCS file: x11/mplayer/patches/patch-libmpcodecs_vf_screenshot_c
diff -N x11/mplayer/patches/patch-libmpcodecs_vf_screenshot_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libmpcodecs_vf_screenshot_c	12 Sep 2025 12:26:10 -0000
@@ -0,0 +1,12 @@
+Index: libmpcodecs/vf_screenshot.c
+--- libmpcodecs/vf_screenshot.c.orig
++++ libmpcodecs/vf_screenshot.c
+@@ -279,7 +279,7 @@ static int query_format(struct vf_instance *vf, unsign
+ 
+ static void uninit(vf_instance_t *vf)
+ {
+-    avcodec_close(vf->priv->avctx);
++    avcodec_free_context(&vf->priv->avctx);
+     av_freep(&vf->priv->avctx);
+     if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
+     av_freep(&vf->priv->pic->data[0]);
Index: x11/mplayer/patches/patch-libmpdemux_demux_lavf_c
===================================================================
RCS file: x11/mplayer/patches/patch-libmpdemux_demux_lavf_c
diff -N x11/mplayer/patches/patch-libmpdemux_demux_lavf_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libmpdemux_demux_lavf_c	16 Sep 2025 00:19:08 -0000
@@ -0,0 +1,29 @@
+Index: libmpdemux/demux_lavf.c
+--- libmpdemux/demux_lavf.c.orig
++++ libmpdemux/demux_lavf.c
+@@ -366,9 +366,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormat
+             if (demuxer->audio->id != i)
+                 st->discard= AVDISCARD_ALL;
+             if (priv->audio_streams == 0) {
+-                size_t rg_size;
+-                AVReplayGain *rg = (AVReplayGain*)av_stream_get_side_data(st, AV_PKT_DATA_REPLAYGAIN, &rg_size);
+-                if (rg && rg_size >= sizeof(*rg)) {
++                AVReplayGain *rg;
++                AVPacketSideData *sd = av_packet_side_data_get(st->codecpar->coded_side_data,
++                    st->codecpar->nb_coded_side_data, AV_PKT_DATA_REPLAYGAIN);
++                if (sd && sd->size >= sizeof(*rg)) {
++                    rg = (AVReplayGain *)sd->data;
+                     priv->r_gain = rg->track_gain / 10000;
+                 }
+             } else
+@@ -378,7 +380,9 @@ static void handle_stream(demuxer_t *demuxer, AVFormat
+         }
+         case AVMEDIA_TYPE_VIDEO:{
+             AVDictionaryEntry *rot = av_dict_get(st->metadata, "rotate",   NULL, 0);
+-            const int32_t *disp_matrix = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
++            const AVPacketSideData *side_data = av_packet_side_data_get(st->codecpar->coded_side_data,
++                st->codecpar->nb_coded_side_data, AV_PKT_DATA_DISPLAYMATRIX);
++            const int32_t *disp_matrix = side_data ? (int32_t *)side_data->data : NULL;
+             sh_video_t* sh_video;
+             BITMAPINFOHEADER *bih;
+             sh_video=new_sh_video_vid(demuxer, i, priv->video_streams);
Index: x11/mplayer/patches/patch-libvo_vo_png_c
===================================================================
RCS file: x11/mplayer/patches/patch-libvo_vo_png_c
diff -N x11/mplayer/patches/patch-libvo_vo_png_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-libvo_vo_png_c	12 Sep 2025 12:30:04 -0000
@@ -0,0 +1,21 @@
+Index: libvo/vo_png.c
+--- libvo/vo_png.c.orig
++++ libvo/vo_png.c
+@@ -126,7 +126,7 @@ config(uint32_t width, uint32_t height, uint32_t d_wid
+ 
+ 
+     if (avctx && png_format != format) {
+-        avcodec_close(avctx);
++        avcodec_free_context(&avctx);
+         av_freep(&avctx);
+     }
+ 
+@@ -214,7 +214,7 @@ query_format(uint32_t format)
+ }
+ 
+ static void uninit(void){
+-    avcodec_close(avctx);
++    avcodec_free_context(&avctx);
+     av_freep(&avctx);
+     av_freep(&outbuffer);
+     outbuffer_size = 0;
Index: x11/mplayer/patches/patch-sub_av_sub_c
===================================================================
RCS file: x11/mplayer/patches/patch-sub_av_sub_c
diff -N x11/mplayer/patches/patch-sub_av_sub_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/mplayer/patches/patch-sub_av_sub_c	12 Sep 2025 12:25:24 -0000
@@ -0,0 +1,12 @@
+Index: sub/av_sub.c
+--- sub/av_sub.c.orig
++++ sub/av_sub.c
+@@ -30,7 +30,7 @@ void reset_avsub(struct sh_sub *sh)
+         AVCodecContext *ctx = sh->context;
+         ctx->extradata = NULL;
+         ctx->extradata_size = 0;
+-        avcodec_close(sh->context);
++        avcodec_free_context(&sh->context);
+         av_freep(&sh->context);
+     }
+ }
Index: x11/qt6/qtmultimedia/patches/patch-src_plugins_multimedia_ffmpeg_qffmpegcodecstorage_cpp
===================================================================
RCS file: x11/qt6/qtmultimedia/patches/patch-src_plugins_multimedia_ffmpeg_qffmpegcodecstorage_cpp
diff -N x11/qt6/qtmultimedia/patches/patch-src_plugins_multimedia_ffmpeg_qffmpegcodecstorage_cpp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/qt6/qtmultimedia/patches/patch-src_plugins_multimedia_ffmpeg_qffmpegcodecstorage_cpp	2 Sep 2025 13:39:10 -0000
@@ -0,0 +1,13 @@
+Index: src/plugins/multimedia/ffmpeg/qffmpegcodecstorage.cpp
+--- src/plugins/multimedia/ffmpeg/qffmpegcodecstorage.cpp.orig
++++ src/plugins/multimedia/ffmpeg/qffmpegcodecstorage.cpp
+@@ -99,7 +99,9 @@ void dumpCodecInfo(const Codec &codec)
+         { AV_CODEC_CAP_DR1, "DRAW_HORIZ_DR1" },
+         { AV_CODEC_CAP_DELAY, "DELAY" },
+         { AV_CODEC_CAP_SMALL_LAST_FRAME, "SMALL_LAST_FRAME" },
++#ifdef AV_CODEC_CAP_SUBFRAMES
+         { AV_CODEC_CAP_SUBFRAMES, "SUBFRAMES" },
++#endif
+         { AV_CODEC_CAP_EXPERIMENTAL, "EXPERIMENTAL" },
+         { AV_CODEC_CAP_CHANNEL_CONF, "CHANNEL_CONF" },
+         { AV_CODEC_CAP_FRAME_THREADS, "FRAME_THREADS" },
Index: x11/vlc/patches/patch-modules_codec_avcodec_audio_c
===================================================================
RCS file: x11/vlc/patches/patch-modules_codec_avcodec_audio_c
diff -N x11/vlc/patches/patch-modules_codec_avcodec_audio_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_codec_avcodec_audio_c	4 Sep 2025 23:18:57 -0000
@@ -0,0 +1,154 @@
+https://code.videolan.org/videolan/vlc/-/merge_requests/2814
+https://code.videolan.org/videolan/vlc/-/merge_requests/3872
+
+Index: modules/codec/avcodec/audio.c
+--- modules/codec/avcodec/audio.c.orig
++++ modules/codec/avcodec/audio.c
+@@ -139,7 +139,11 @@ static int OpenAudioCodec( decoder_t *p_dec )
+     }
+ 
+     ctx->sample_rate = p_dec->fmt_in.audio.i_rate;
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100))
++    av_channel_layout_default( &ctx->ch_layout, p_dec->fmt_in.audio.i_channels );
++#else
+     ctx->channels = p_dec->fmt_in.audio.i_channels;
++#endif
+     ctx->block_align = p_dec->fmt_in.audio.i_blockalign;
+     ctx->bit_rate = p_dec->fmt_in.i_bitrate;
+     ctx->bits_per_coded_sample = p_dec->fmt_in.audio.i_bitspersample;
+@@ -261,12 +265,6 @@ int InitAudioDec( vlc_object_t *obj )
+     p_dec->pf_decode = DecodeAudio;
+     p_dec->pf_flush  = Flush;
+ 
+-    /* XXX: Writing input format makes little sense. */
+-    if( avctx->profile != FF_PROFILE_UNKNOWN )
+-        p_dec->fmt_in.i_profile = avctx->profile;
+-    if( avctx->level != FF_LEVEL_UNKNOWN )
+-        p_dec->fmt_in.i_level = avctx->level;
+-
+     return VLC_SUCCESS;
+ }
+ 
+@@ -395,12 +393,17 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp
+         ret = avcodec_receive_frame( ctx, frame );
+         if( ret == 0 )
+         {
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100))
++            int channels = frame->ch_layout.nb_channels;
++#else
++            int channels = ctx->channels;
++#endif
+             /* checks and init from first decoded frame */
+-            if( ctx->channels <= 0 || ctx->channels > INPUT_CHAN_MAX
++            if( channels <= 0 || channels > INPUT_CHAN_MAX
+              || ctx->sample_rate <= 0 )
+             {
+                 msg_Warn( p_dec, "invalid audio properties channels count %d, sample rate %d",
+-                          ctx->channels, ctx->sample_rate );
++                          channels, ctx->sample_rate );
+                 goto drop;
+             }
+             else if( p_dec->fmt_out.audio.i_rate != (unsigned int)ctx->sample_rate )
+@@ -484,15 +487,15 @@ static block_t * ConvertAVFrame( decoder_t *p_dec, AVF
+     /* Interleave audio if required */
+     if( av_sample_fmt_is_planar( ctx->sample_fmt ) )
+     {
+-        p_block = block_Alloc(frame->linesize[0] * ctx->channels);
++        p_block = block_Alloc(frame->linesize[0] * p_dec->fmt_out.audio.i_channels );
+         if ( likely(p_block) )
+         {
+-            const void *planes[ctx->channels];
+-            for (int i = 0; i < ctx->channels; i++)
++            const void *planes[p_dec->fmt_out.audio.i_channels];
++            for (int i = 0; i < p_dec->fmt_out.audio.i_channels; i++)
+                 planes[i] = frame->extended_data[i];
+ 
+             aout_Interleave(p_block->p_buffer, planes, frame->nb_samples,
+-                            ctx->channels, p_dec->fmt_out.audio.i_format);
++                            p_dec->fmt_out.audio.i_channels, p_dec->fmt_out.audio.i_format);
+             p_block->i_nb_samples = frame->nb_samples;
+         }
+         av_frame_free(&frame);
+@@ -511,7 +514,7 @@ static block_t * ConvertAVFrame( decoder_t *p_dec, AVF
+         {
+             aout_ChannelExtract( p_buffer->p_buffer,
+                                  p_dec->fmt_out.audio.i_channels,
+-                                 p_block->p_buffer, ctx->channels,
++                                 p_block->p_buffer, p_dec->fmt_out.audio.i_channels,
+                                  p_block->i_nb_samples, p_sys->pi_extraction,
+                                  p_dec->fmt_out.audio.i_bitspersample );
+             p_buffer->i_nb_samples = p_block->i_nb_samples;
+@@ -568,6 +571,7 @@ static const uint64_t pi_channels_map[][2] =
+     { AV_CH_TOP_BACK_RIGHT,    0 },
+     { AV_CH_STEREO_LEFT,       0 },
+     { AV_CH_STEREO_RIGHT,      0 },
++    { 0, 0 },
+ };
+ 
+ static void SetupOutputFormat( decoder_t *p_dec, bool b_trust )
+@@ -580,6 +584,16 @@ static void SetupOutputFormat( decoder_t *p_dec, bool 
+     p_dec->fmt_out.audio.i_rate = p_sys->p_context->sample_rate;
+ 
+     /* */
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100))
++    if( p_sys->i_previous_channels == p_sys->p_context->ch_layout.nb_channels &&
++        p_sys->i_previous_layout == p_sys->p_context->ch_layout.u.mask )
++        return;
++    if( b_trust )
++    {
++        p_sys->i_previous_channels = p_sys->p_context->ch_layout.nb_channels;
++        p_sys->i_previous_layout = p_sys->p_context->ch_layout.u.mask;
++    }
++#else
+     if( p_sys->i_previous_channels == p_sys->p_context->channels &&
+         p_sys->i_previous_layout == p_sys->p_context->channel_layout )
+         return;
+@@ -588,25 +602,31 @@ static void SetupOutputFormat( decoder_t *p_dec, bool 
+         p_sys->i_previous_channels = p_sys->p_context->channels;
+         p_sys->i_previous_layout = p_sys->p_context->channel_layout;
+     }
++#endif
+ 
+-    const unsigned i_order_max = sizeof(pi_channels_map)/sizeof(*pi_channels_map);
+-    uint32_t pi_order_src[i_order_max];
++    uint32_t pi_order_src[AOUT_CHAN_MAX] = { 0 };
+ 
+     int i_channels_src = 0;
+-    int64_t channel_layout =
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100))
++    uint64_t channel_layout_mask = p_sys->p_context->ch_layout.u.mask;
++    int channel_count = p_sys->p_context->ch_layout.nb_channels;
++#else
++    uint64_t channel_layout_mask =
+         p_sys->p_context->channel_layout ? p_sys->p_context->channel_layout :
+         av_get_default_channel_layout( p_sys->p_context->channels );
++    int channel_count = p_sys->p_context->channels;
++#endif
+ 
+-    if( channel_layout )
++    if( channel_layout_mask )
+     {
+-        for( unsigned i = 0; i < i_order_max
+-         && i_channels_src < p_sys->p_context->channels; i++ )
++        for( unsigned i = 0; pi_channels_map[i][0]
++         && i_channels_src < channel_count; i++ )
+         {
+-            if( channel_layout & pi_channels_map[i][0] )
++            if( channel_layout_mask & pi_channels_map[i][0] )
+                 pi_order_src[i_channels_src++] = pi_channels_map[i][1];
+         }
+ 
+-        if( i_channels_src != p_sys->p_context->channels && b_trust )
++        if( i_channels_src != channel_count && b_trust )
+             msg_Err( p_dec, "Channel layout not understood" );
+ 
+         /* Detect special dual mono case */
+@@ -638,7 +658,7 @@ static void SetupOutputFormat( decoder_t *p_dec, bool 
+     {
+         msg_Warn( p_dec, "no channel layout found");
+         p_dec->fmt_out.audio.i_physical_channels = 0;
+-        p_dec->fmt_out.audio.i_channels = p_sys->p_context->channels;
++        p_dec->fmt_out.audio.i_channels = channel_count;
+     }
+ 
+     aout_FormatPrepare( &p_dec->fmt_out.audio );
Index: x11/vlc/patches/patch-modules_codec_avcodec_avcommon_compat_h
===================================================================
RCS file: x11/vlc/patches/patch-modules_codec_avcodec_avcommon_compat_h
diff -N x11/vlc/patches/patch-modules_codec_avcodec_avcommon_compat_h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_codec_avcodec_avcommon_compat_h	5 Sep 2025 08:36:09 -0000
@@ -0,0 +1,18 @@
+ffmpeg8 removes it without any replacment
+
+Index: modules/codec/avcodec/avcommon_compat.h
+--- modules/codec/avcodec/avcommon_compat.h.orig
++++ modules/codec/avcodec/avcommon_compat.h
+@@ -71,8 +71,11 @@
+ #ifndef AV_CODEC_CAP_SMALL_LAST_FRAME
+ # define AV_CODEC_CAP_SMALL_LAST_FRAME CODEC_CAP_SMALL_LAST_FRAME
+ #endif
+-#ifndef AV_INPUT_BUFFER_MIN_SIZE
++#if !defined(AV_INPUT_BUFFER_MIN_SIZE) && defined(FF_MIN_BUFFER_SIZE)
+ # define AV_INPUT_BUFFER_MIN_SIZE FF_MIN_BUFFER_SIZE
++#endif
++#ifndef AV_INPUT_BUFFER_MIN_SIZE
++# define AV_INPUT_BUFFER_MIN_SIZE 16384
+ #endif
+ #ifndef  FF_MAX_B_FRAMES
+ # define  FF_MAX_B_FRAMES 16 // FIXME: remove this
Index: x11/vlc/patches/patch-modules_codec_avcodec_encoder_c
===================================================================
RCS file: x11/vlc/patches/patch-modules_codec_avcodec_encoder_c
diff -N x11/vlc/patches/patch-modules_codec_avcodec_encoder_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_codec_avcodec_encoder_c	5 Sep 2025 08:30:32 -0000
@@ -0,0 +1,422 @@
+https://code.videolan.org/videolan/vlc/-/merge_requests/6657
+https://code.videolan.org/videolan/vlc/-/merge_requests/3854
+
+Index: modules/codec/avcodec/encoder.c
+--- modules/codec/avcodec/encoder.c.orig
++++ modules/codec/avcodec/encoder.c
+@@ -181,6 +181,7 @@ static const uint64_t pi_channels_map[][2] =
+     { AV_CH_STEREO_RIGHT,      0 },
+ };
+ 
++#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 59, 24, 100 ))
+ static const uint32_t channel_mask[][2] = {
+     {0,0},
+     {AOUT_CHAN_CENTER, AV_CH_LAYOUT_MONO},
+@@ -193,6 +194,7 @@ static const uint32_t channel_mask[][2] = {
+     {AOUT_CHANS_7_1, AV_CH_LAYOUT_7POINT1},
+     {AOUT_CHANS_8_1, AV_CH_LAYOUT_OCTAGONAL},
+ };
++#endif
+ 
+ static const char *const ppsz_enc_options[] = {
+     "keyint", "bframes", "vt", "qmin", "qmax", "codec", "hq",
+@@ -252,19 +254,29 @@ static void probe_video_frame_rate( encoder_t *p_enc, 
+                                   ( p_enc->fmt_out.i_codec == VLC_CODEC_MP4V ? 25 : CLOCK_FREQ );
+ 
+     msg_Dbg( p_enc, "Time base for probing set to %d/%d", p_context->time_base.num, p_context->time_base.den );
+-    if( p_codec->supported_framerates )
++
++    const AVRational *supported_framerates;
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 61, 13, 100 ))
++    if (avcodec_get_supported_config(p_context, p_codec, AV_CODEC_CONFIG_FRAME_RATE, 0,
++                                     (const void **)&supported_framerates, NULL) < 0)
++        supported_framerates = NULL;
++#else
++    supported_framerates = p_codec->supported_framerates;
++#endif
++
++    if( supported_framerates )
+     {
+         /* We are finding fps values so 1/time_base */
+         AVRational target = {
+             .num = p_context->time_base.den,
+             .den = p_context->time_base.num
+         };
+-        int idx = av_find_nearest_q_idx(target, p_codec->supported_framerates);
++        int idx = av_find_nearest_q_idx(target, supported_framerates);
+ 
+-        p_context->time_base.num = p_codec->supported_framerates[idx].den ?
+-                                    p_codec->supported_framerates[idx].den : 1;
+-        p_context->time_base.den = p_codec->supported_framerates[idx].den ?
+-                                    p_codec->supported_framerates[idx].num : CLOCK_FREQ;
++        p_context->time_base.num = supported_framerates[idx].den ?
++                                    supported_framerates[idx].den : 1;
++        p_context->time_base.den = supported_framerates[idx].den ?
++                                    supported_framerates[idx].num : CLOCK_FREQ;
+ 
+         /* If we have something reasonable on supported framerates, use that*/
+         if( p_context->time_base.den && p_context->time_base.den < CLOCK_FREQ )
+@@ -468,30 +480,30 @@ int InitVideoEnc( vlc_object_t *p_this )
+     psz_val = var_GetString( p_enc, ENC_CFG_PREFIX "aac-profile" );
+     /* libavcodec uses faac encoder atm, and it has issues with
+      * other than low-complexity profile, so default to that */
+-    p_sys->i_aac_profile = FF_PROFILE_AAC_LOW;
++    p_sys->i_aac_profile = AV_PROFILE_AAC_LOW;
+     if( psz_val && *psz_val )
+     {
+         if( !strncmp( psz_val, "main", 4 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_MAIN;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_MAIN;
+         else if( !strncmp( psz_val, "low", 3 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_LOW;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_LOW;
+         else if( !strncmp( psz_val, "ssr", 3 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_SSR;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_SSR;
+         else if( !strncmp( psz_val, "ltp", 3 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_LTP;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_LTP;
+ /* These require libavcodec with libfdk-aac */
+         else if( !strncmp( psz_val, "hev2", 4 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_HE_V2;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_HE_V2;
+         else if( !strncmp( psz_val, "hev1", 4 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_HE;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_HE;
+         else if( !strncmp( psz_val, "ld", 2 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_LD;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_LD;
+         else if( !strncmp( psz_val, "eld", 3 ) )
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_ELD;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_ELD;
+         else
+         {
+             msg_Warn( p_enc, "unknown AAC profile requested, setting it to low" );
+-            p_sys->i_aac_profile = FF_PROFILE_AAC_LOW;
++            p_sys->i_aac_profile = AV_PROFILE_AAC_LOW;
+         }
+     }
+     free( psz_val );
+@@ -553,7 +565,16 @@ int InitVideoEnc( vlc_object_t *p_this )
+         p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec;
+         GetFfmpegChroma( &p_context->pix_fmt, &p_enc->fmt_in.video );
+ 
+-        if( p_codec->pix_fmts )
++        const enum AVPixelFormat *pix_fmts;
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 61, 13, 100 ))
++        if (avcodec_get_supported_config(p_context, p_codec, AV_CODEC_CONFIG_PIX_FORMAT, 0,
++                                        (const void **)&pix_fmts, NULL) < 0)
++            pix_fmts = NULL;
++#else
++        pix_fmts = p_codec->pix_fmts;
++#endif
++
++        if( pix_fmts )
+         {
+             static const enum AVPixelFormat vlc_pix_fmts[] = {
+                 AV_PIX_FMT_YUV420P,
+@@ -561,8 +582,8 @@ int InitVideoEnc( vlc_object_t *p_this )
+                 AV_PIX_FMT_RGB24,
+             };
+             bool found = false;
+-            const enum PixelFormat *p = p_codec->pix_fmts;
+-            for( ; !found && *p != -1; p++ )
++            const enum AVPixelFormat *p = pix_fmts;
++            for( ; !found && *p != AV_PIX_FMT_NONE; p++ )
+             {
+                 for( size_t i = 0; i < ARRAY_SIZE(vlc_pix_fmts); ++i )
+                 {
+@@ -574,7 +595,7 @@ int InitVideoEnc( vlc_object_t *p_this )
+                     }
+                 }
+             }
+-            if (!found) p_context->pix_fmt = p_codec->pix_fmts[0];
++            if (!found) p_context->pix_fmt = pix_fmts[0];
+             GetVlcChroma( &p_enc->fmt_in.video, p_context->pix_fmt );
+             p_enc->fmt_in.i_codec = p_enc->fmt_in.video.i_chroma;
+         }
+@@ -699,22 +720,29 @@ int InitVideoEnc( vlc_object_t *p_this )
+     }
+     else if( p_enc->fmt_in.i_cat == AUDIO_ES )
+     {
++        const enum AVSampleFormat *sample_fmts;
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 61, 13, 100 ))
++        if (avcodec_get_supported_config(p_context, p_codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
++                                        (const void **)&sample_fmts, NULL) < 0)
++            sample_fmts = NULL;
++#else
++        sample_fmts = p_codec->sample_fmts;
++#endif
++
+         p_context->codec_type  = AVMEDIA_TYPE_AUDIO;
+-        p_context->sample_fmt  = p_codec->sample_fmts ?
+-                                    p_codec->sample_fmts[0] :
+-                                    AV_SAMPLE_FMT_S16;
++        p_context->sample_fmt  = sample_fmts ? sample_fmts[0] : AV_SAMPLE_FMT_S16;
+ 
+         /* Try to match avcodec input format to vlc format so we could avoid one
+            format conversion */
+         if( GetVlcAudioFormat( p_context->sample_fmt ) != p_enc->fmt_in.i_codec
+-            && p_codec->sample_fmts )
++            && sample_fmts )
+         {
+             msg_Dbg( p_enc, "Trying to find more suitable sample format instead of %s", av_get_sample_fmt_name( p_context->sample_fmt ) );
+-            for( unsigned int i=0; p_codec->sample_fmts[i] != -1; i++ )
++            for( unsigned int i=0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++ )
+             {
+-                if( GetVlcAudioFormat( p_codec->sample_fmts[i] ) == p_enc->fmt_in.i_codec )
++                if( GetVlcAudioFormat( sample_fmts[i] ) == p_enc->fmt_in.i_codec )
+                 {
+-                    p_context->sample_fmt = p_codec->sample_fmts[i];
++                    p_context->sample_fmt = sample_fmts[i];
+                     msg_Dbg( p_enc, "Using %s as new sample format", av_get_sample_fmt_name( p_context->sample_fmt ) );
+                     break;
+                 }
+@@ -723,14 +751,14 @@ int InitVideoEnc( vlc_object_t *p_this )
+         p_sys->b_planar = av_sample_fmt_is_planar( p_context->sample_fmt );
+         // Try if we can use interleaved format for codec input as VLC doesn't really do planar audio yet
+         // FIXME: Remove when planar/interleaved audio in vlc is equally supported
+-        if( p_sys->b_planar && p_codec->sample_fmts )
++        if( p_sys->b_planar && sample_fmts )
+         {
+             msg_Dbg( p_enc, "Trying to find packet sample format instead of planar %s", av_get_sample_fmt_name( p_context->sample_fmt ) );
+-            for( unsigned int i=0; p_codec->sample_fmts[i] != -1; i++ )
++            for( unsigned int i=0; sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++ )
+             {
+-                if( !av_sample_fmt_is_planar( p_codec->sample_fmts[i] ) )
++                if( !av_sample_fmt_is_planar( sample_fmts[i] ) )
+                 {
+-                    p_context->sample_fmt = p_codec->sample_fmts[i];
++                    p_context->sample_fmt = sample_fmts[i];
+                     msg_Dbg( p_enc, "Changing to packet format %s as new sample format", av_get_sample_fmt_name( p_context->sample_fmt ) );
+                     break;
+                 }
+@@ -745,58 +773,43 @@ int InitVideoEnc( vlc_object_t *p_this )
+         date_Set( &p_sys->buffer_date, AV_NOPTS_VALUE );
+         p_context->time_base.num = 1;
+         p_context->time_base.den = p_context->sample_rate;
+-        p_context->channels      = p_enc->fmt_out.audio.i_channels;
+-#if LIBAVUTIL_VERSION_CHECK( 52, 2, 6, 0, 0)
+-        p_context->channel_layout = channel_mask[p_context->channels][1];
+ 
+-        /* Setup Channel ordering for multichannel audio
++        /* Setup Channel ordering for audio
+          * as VLC channel order isn't same as libavcodec expects
+          */
+ 
+         p_sys->i_channels_to_reorder = 0;
+ 
+-        /* Specified order
++        /* Create channel layout for avcodec
+          * Copied from audio.c
+          */
+-        const unsigned i_order_max = 8 * sizeof(p_context->channel_layout);
+         uint32_t pi_order_dst[AOUT_CHAN_MAX] = { };
+         uint32_t order_mask = 0;
+         int i_channels_src = 0;
+ 
+-        if( p_context->channel_layout )
+-        {
+-            msg_Dbg( p_enc, "Creating channel order for reordering");
+-            for( unsigned i = 0; i < sizeof(pi_channels_map)/sizeof(*pi_channels_map); i++ )
++        msg_Dbg( p_enc, "Creating channel order for reordering");
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 ))
++        av_channel_layout_default( &p_context->ch_layout, p_enc->fmt_out.audio.i_channels );
++        uint64_t channel_mask = p_context->ch_layout.u.mask;
++#else
++        p_context->channels = p_enc->fmt_out.audio.i_channels;
++        p_context->channel_layout = channel_mask[p_context->channels][1];
++        uint64_t channel_mask = p_context->channel_layout;
++#endif
++        for( unsigned i = 0; i < sizeof(pi_channels_map)/sizeof(*pi_channels_map); i++ )
++            if( channel_mask & pi_channels_map[i][0] )
+             {
+-                if( p_context->channel_layout & pi_channels_map[i][0] )
+-                {
+-                    msg_Dbg( p_enc, "%d %"PRIx64" mapped to %"PRIx64"", i_channels_src, pi_channels_map[i][0], pi_channels_map[i][1]);
+-                    pi_order_dst[i_channels_src++] = pi_channels_map[i][1];
+-                    order_mask |= pi_channels_map[i][1];
+-                }
++                msg_Dbg( p_enc, "%d %"PRIx64" mapped to %"PRIx64"", i_channels_src, pi_channels_map[i][0], pi_channels_map[i][1]);
++                pi_order_dst[i_channels_src++] = pi_channels_map[i][1];
++                order_mask |= pi_channels_map[i][1];
+             }
+-        }
+-        else
+-        {
+-            msg_Dbg( p_enc, "Creating default channel order for reordering");
+-            /* Create default order  */
+-            for( unsigned int i = 0; i < __MIN( i_order_max, (unsigned)p_sys->p_context->channels ); i++ )
+-            {
+-                if( i < sizeof(pi_channels_map)/sizeof(*pi_channels_map) )
+-                {
+-                    msg_Dbg( p_enc, "%d channel is %"PRIx64"", i_channels_src, pi_channels_map[i][1]);
+-                    pi_order_dst[i_channels_src++] = pi_channels_map[i][1];
+-                    order_mask |= pi_channels_map[i][1];
+-                }
+-            }
+-        }
+-        if( i_channels_src != p_context->channels )
++
++        if( i_channels_src != p_enc->fmt_out.audio.i_channels )
+             msg_Err( p_enc, "Channel layout not understood" );
+ 
+         p_sys->i_channels_to_reorder =
+             aout_CheckChannelReorder( NULL, pi_order_dst, order_mask,
+                                       p_sys->pi_reorder_layout );
+-#endif
+ 
+         if ( p_enc->fmt_out.i_codec == VLC_CODEC_MP4A )
+         {
+@@ -897,7 +910,7 @@ int InitVideoEnc( vlc_object_t *p_this )
+     if( ret )
+     {
+         if( p_enc->fmt_in.i_cat != AUDIO_ES ||
+-                (p_context->channels <= 2 && i_codec_id != AV_CODEC_ID_MP2
++                (p_enc->fmt_out.audio.i_channels <= 2 && i_codec_id != AV_CODEC_ID_MP2
+                  && i_codec_id != AV_CODEC_ID_MP3) )
+ errmsg:
+         {
+@@ -922,10 +935,14 @@ errmsg:
+             goto error;
+         }
+ 
+-        if( p_context->channels > 2 )
++        if( p_enc->fmt_out.audio.i_channels > 2 )
+         {
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 ))
++            av_channel_layout_default( &p_context->ch_layout, 2 );
++#else
+             p_context->channels = 2;
+             p_context->channel_layout = channel_mask[p_context->channels][1];
++#endif
+ 
+             /* Change fmt_in in order to ask for a channels conversion */
+             p_enc->fmt_in.audio.i_channels =
+@@ -1028,7 +1045,7 @@ errmsg:
+                                     p_context->frame_size :
+                                     AV_INPUT_BUFFER_MIN_SIZE;
+         p_sys->i_buffer_out = av_samples_get_buffer_size(NULL,
+-                p_sys->p_context->channels, p_sys->i_frame_size,
++                p_enc->fmt_out.audio.i_channels, p_sys->i_frame_size,
+                 p_sys->p_context->sample_fmt, DEFAULT_ALIGN);
+         p_sys->p_buffer = av_malloc( p_sys->i_buffer_out );
+         if ( unlikely( p_sys->p_buffer == NULL ) )
+@@ -1227,8 +1244,19 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture
+         frame->pict_type = 0;
+ 
+         frame->repeat_pict = p_pict->i_nb_fields - 2;
++#if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( 58, 7, 100 ))
++        if (p_pict->b_progressive)
++            frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
++        else
++            frame->flags |= AV_FRAME_FLAG_INTERLACED;
++        if (p_pict->b_top_field_first)
++            frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
++        else
++            frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
++#else
+         frame->interlaced_frame = !p_pict->b_progressive;
+         frame->top_field_first = !!p_pict->b_top_field_first;
++#endif
+ 
+         frame->format = p_sys->p_context->pix_fmt;
+         frame->width = p_sys->p_context->width;
+@@ -1278,13 +1306,17 @@ static block_t *handle_delay_buffer( encoder_t *p_enc,
+ {
+     block_t *p_block = NULL;
+     //How much we need to copy from new packet
+-    const size_t leftover = leftover_samples * p_sys->p_context->channels * p_sys->i_sample_bytes;
++    const size_t leftover = leftover_samples * p_enc->fmt_out.audio.i_channels * p_sys->i_sample_bytes;
+ 
+     av_frame_unref( p_sys->frame );
+     p_sys->frame->format     = p_sys->p_context->sample_fmt;
+     p_sys->frame->nb_samples = leftover_samples + p_sys->i_samples_delay;
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 ))
++    av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
++#else
+     p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
+     p_sys->frame->channels = p_sys->p_context->channels;
++#endif
+ 
+     p_sys->frame->pts        = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
+                                 CLOCK_FREQ / p_sys->p_context->time_base.num;
+@@ -1301,7 +1333,7 @@ static block_t *handle_delay_buffer( encoder_t *p_enc,
+         // We need to deinterleave from p_aout_buf to p_buffer the leftover bytes
+         if( p_sys->b_planar )
+             aout_Deinterleave( p_sys->p_interleave_buf, p_sys->p_buffer,
+-                p_sys->i_frame_size, p_sys->p_context->channels, p_enc->fmt_in.i_codec );
++                p_sys->i_frame_size, p_enc->fmt_out.audio.i_channels, p_enc->fmt_in.i_codec );
+         else
+             memcpy( p_sys->p_buffer + buffer_delay, p_aout_buf->p_buffer, leftover);
+ 
+@@ -1319,7 +1351,7 @@ static block_t *handle_delay_buffer( encoder_t *p_enc,
+         memset( p_sys->p_buffer + (leftover+buffer_delay), 0, padding_size );
+         buffer_delay += padding_size;
+     }
+-    if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->channels,
++    if( avcodec_fill_audio_frame( p_sys->frame, p_enc->fmt_out.audio.i_channels,
+             p_sys->p_context->sample_fmt, p_sys->b_planar ? p_sys->p_interleave_buf : p_sys->p_buffer,
+             p_sys->i_buffer_out,
+             DEFAULT_ALIGN) < 0 )
+@@ -1349,7 +1381,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t
+ 
+     //i_bytes_left is amount of bytes we get
+     i_samples_left = p_aout_buf ? p_aout_buf->i_nb_samples : 0;
+-    buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_sys->p_context->channels;
++    buffer_delay = p_sys->i_samples_delay * p_sys->i_sample_bytes * p_enc->fmt_out.audio.i_channels;
+ 
+     //p_sys->i_buffer_out = p_sys->i_frame_size * chan * p_sys->i_sample_bytes
+     //Calculate how many bytes we would need from current buffer to fill frame
+@@ -1414,16 +1446,20 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t
+         p_sys->frame->pts        = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
+                                     CLOCK_FREQ / p_sys->p_context->time_base.num;
+ 
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 ))
++        av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
++#else
+         p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
+         p_sys->frame->channels = p_sys->p_context->channels;
++#endif
+ 
+         const int in_bytes = p_sys->frame->nb_samples *
+-            p_sys->p_context->channels * p_sys->i_sample_bytes;
++            p_enc->fmt_out.audio.i_channels* p_sys->i_sample_bytes;
+ 
+         if( p_sys->b_planar )
+         {
+             aout_Deinterleave( p_sys->p_buffer, p_aout_buf->p_buffer,
+-                               p_sys->frame->nb_samples, p_sys->p_context->channels, p_enc->fmt_in.i_codec );
++                               p_sys->frame->nb_samples, p_enc->fmt_out.audio.i_channels, p_enc->fmt_in.i_codec );
+ 
+         }
+         else
+@@ -1431,7 +1467,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t
+             memcpy(p_sys->p_buffer, p_aout_buf->p_buffer, in_bytes);
+         }
+ 
+-        if( avcodec_fill_audio_frame( p_sys->frame, p_sys->p_context->channels,
++        if( avcodec_fill_audio_frame( p_sys->frame, p_enc->fmt_out.audio.i_channels,
+                                     p_sys->p_context->sample_fmt,
+                                     p_sys->p_buffer,
+                                     p_sys->i_buffer_out,
+@@ -1457,7 +1493,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t
+     if( p_aout_buf->i_nb_samples > 0 )
+     {
+        memcpy( p_sys->p_buffer + buffer_delay, p_aout_buf->p_buffer,
+-               p_aout_buf->i_nb_samples * p_sys->i_sample_bytes * p_sys->p_context->channels);
++               p_aout_buf->i_nb_samples * p_sys->i_sample_bytes * p_enc->fmt_out.audio.i_channels);
+        p_sys->i_samples_delay += p_aout_buf->i_nb_samples;
+     }
+ 
+@@ -1475,9 +1511,8 @@ void EndVideoEnc( vlc_object_t *p_this )
+     av_frame_free( &p_sys->frame );
+ 
+     vlc_avcodec_lock();
+-    avcodec_close( p_sys->p_context );
+-    vlc_avcodec_unlock();
+     avcodec_free_context( &p_sys->p_context );
++    vlc_avcodec_unlock();
+ 
+ 
+     av_free( p_sys->p_interleave_buf );
Index: x11/vlc/patches/patch-modules_codec_avcodec_fourcc_c
===================================================================
RCS file: x11/vlc/patches/patch-modules_codec_avcodec_fourcc_c
diff -N x11/vlc/patches/patch-modules_codec_avcodec_fourcc_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_codec_avcodec_fourcc_c	5 Sep 2025 10:20:55 -0000
@@ -0,0 +1,16 @@
+https://code.videolan.org/videolan/vlc/-/merge_requests/5304
+Index: modules/codec/avcodec/fourcc.c
+--- modules/codec/avcodec/fourcc.c.orig
++++ modules/codec/avcodec/fourcc.c
+@@ -183,7 +183,11 @@ static const struct vlc_avcodec_fourcc video_codecs[] 
+     { VLC_CODEC_TMV, AV_CODEC_ID_TMV },
+     { VLC_CODEC_V210, AV_CODEC_ID_V210 },
+ #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 54, 50, 100 ) && LIBAVCODEC_VERSION_MICRO >= 100
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 142, 100 )
++    { VLC_CODEC_VUYA, AV_CODEC_ID_RAWVIDEO },
++#else
+     { VLC_CODEC_VUYA, AV_CODEC_ID_AYUV },
++#endif
+ #endif
+     /* AV_CODEC_ID_DPX */
+     { VLC_CODEC_MAD, AV_CODEC_ID_MAD },
Index: x11/vlc/patches/patch-modules_codec_avcodec_video_c
===================================================================
RCS file: x11/vlc/patches/patch-modules_codec_avcodec_video_c
diff -N x11/vlc/patches/patch-modules_codec_avcodec_video_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_codec_avcodec_video_c	4 Sep 2025 22:38:07 -0000
@@ -0,0 +1,72 @@
+https://code.videolan.org/videolan/vlc/-/merge_requests/6656
+https://code.videolan.org/videolan/vlc/-/merge_requests/6659
+https://code.videolan.org/videolan/vlc/-/merge_requests/2814
+
+Index: modules/codec/avcodec/video.c
+--- modules/codec/avcodec/video.c.orig
++++ modules/codec/avcodec/video.c
+@@ -204,8 +204,7 @@ static int lavc_GetVideoFormat(decoder_t *dec, video_f
+     else if (ctx->time_base.num > 0 && ctx->time_base.den > 0)
+     {
+         fmt->i_frame_rate = ctx->time_base.den;
+-        fmt->i_frame_rate_base = ctx->time_base.num
+-                                 * __MAX(ctx->ticks_per_frame, 1);
++        fmt->i_frame_rate_base = ctx->time_base.num;
+     }
+ 
+     /* FIXME we should only set the known values and let the core decide
+@@ -327,12 +326,10 @@ static int lavc_UpdateVideoFormat(decoder_t *dec, AVCo
+ 
+     /* always have date in fields/ticks units */
+     if(dec->p_sys->pts.i_divider_num)
+-        date_Change(&dec->p_sys->pts, fmt_out.i_frame_rate *
+-                                      __MAX(ctx->ticks_per_frame, 1),
++        date_Change(&dec->p_sys->pts, fmt_out.i_frame_rate,
+                                       fmt_out.i_frame_rate_base);
+     else
+-        date_Init(&dec->p_sys->pts, fmt_out.i_frame_rate *
+-                                    __MAX(ctx->ticks_per_frame, 1),
++        date_Init(&dec->p_sys->pts, fmt_out.i_frame_rate,
+                                     fmt_out.i_frame_rate_base);
+ 
+     fmt_out.p_palette = dec->fmt_out.video.p_palette;
+@@ -625,11 +622,6 @@ static int InitVideoDecCommon( decoder_t *p_dec )
+     p_dec->pf_decode = DecodeVideo;
+     p_dec->pf_flush  = Flush;
+ 
+-    /* XXX: Writing input format makes little sense. */
+-    if( p_context->profile != FF_PROFILE_UNKNOWN )
+-        p_dec->fmt_in.i_profile = p_context->profile;
+-    if( p_context->level != FF_LEVEL_UNKNOWN )
+-        p_dec->fmt_in.i_level = p_context->level;
+     return VLC_SUCCESS;
+ }
+ 
+@@ -945,9 +937,11 @@ static vlc_tick_t interpolate_next_pts( decoder_t *p_d
+         p_sys->pts.i_divider_num == 0 )
+         return VLC_TICK_INVALID;
+ 
++#if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(60, 12, 100))
++    int i_tick = p_context->codec_descriptor->props & AV_CODEC_PROP_FIELDS ? 2 : 1;
++#else
+     int i_tick = p_context->ticks_per_frame;
+-    if( i_tick <= 0 )
+-        i_tick = 1;
++#endif
+ 
+     /* interpolate the next PTS */
+     return date_Increment( &p_sys->pts, i_tick + frame->repeat_pict );
+@@ -1426,8 +1420,13 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block
+         /* Hack to force display of still pictures */
+         p_pic->b_force = p_sys->b_first_frame;
+         p_pic->i_nb_fields = 2 + frame->repeat_pict;
++#if (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58, 7, 100))
++        p_pic->b_progressive = !(frame->flags & AV_FRAME_FLAG_INTERLACED);
++        p_pic->b_top_field_first = !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST);
++#else
+         p_pic->b_progressive = !frame->interlaced_frame;
+         p_pic->b_top_field_first = frame->top_field_first;
++#endif
+ 
+         if (DecodeSidedata(p_dec, frame, p_pic))
+             i_pts = VLC_TICK_INVALID;
Index: x11/vlc/patches/patch-modules_demux_avformat_demux_c
===================================================================
RCS file: x11/vlc/patches/patch-modules_demux_avformat_demux_c
diff -N x11/vlc/patches/patch-modules_demux_avformat_demux_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_demux_avformat_demux_c	5 Sep 2025 10:19:19 -0000
@@ -0,0 +1,46 @@
+https://code.videolan.org/videolan/vlc/-/merge_requests/6658
+https://code.videolan.org/videolan/vlc/-/merge_requests/5304
+
+Index: modules/demux/avformat/demux.c
+--- modules/demux/avformat/demux.c.orig
++++ modules/demux/avformat/demux.c
+@@ -112,6 +112,18 @@ static vlc_fourcc_t CodecTagToFourcc( uint32_t codec_t
+ #endif
+ }
+ 
++static inline void* GetStreamSideData(const AVStream *s, enum AVPacketSideDataType type)
++{
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 60, 29, 100 )
++    const AVCodecParameters *cp = s->codecpar;
++    const AVPacketSideData *psd =
++        av_packet_side_data_get(cp->coded_side_data, cp->nb_coded_side_data, type);
++    return psd ? psd->data : NULL;
++#else
++    return av_stream_get_side_data(s, type, NULL);
++#endif
++}
++
+ /*****************************************************************************
+  * Open
+  *****************************************************************************/
+@@ -138,7 +150,7 @@ static void get_rotation(es_format_t *fmt, AVStream *s
+         else
+             fmt->video.orientation = ORIENT_NORMAL;
+     }
+-    int32_t *matrix = (int32_t *)av_stream_get_side_data(s, AV_PKT_DATA_DISPLAYMATRIX, NULL);
++    int32_t *matrix = GetStreamSideData(s, AV_PKT_DATA_DISPLAYMATRIX);
+     if( matrix ) {
+         angle = lround(av_display_rotation_get(matrix));
+ 
+@@ -401,7 +413,11 @@ int avformat_OpenDemux( vlc_object_t *p_this )
+             es_format_Init( &es_fmt, AUDIO_ES, fcc );
+             es_fmt.i_original_fourcc = CodecTagToFourcc( cp->codec_tag );
+             es_fmt.i_bitrate = cp->bit_rate;
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 )
++            es_fmt.audio.i_channels = cp->ch_layout.nb_channels;
++#else
+             es_fmt.audio.i_channels = cp->channels;
++#endif
+             es_fmt.audio.i_rate = cp->sample_rate;
+             es_fmt.audio.i_bitspersample = cp->bits_per_coded_sample;
+             es_fmt.audio.i_blockalign = cp->block_align;
Index: x11/vlc/patches/patch-modules_demux_avformat_mux_c
===================================================================
RCS file: x11/vlc/patches/patch-modules_demux_avformat_mux_c
diff -N x11/vlc/patches/patch-modules_demux_avformat_mux_c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ x11/vlc/patches/patch-modules_demux_avformat_mux_c	5 Sep 2025 10:22:50 -0000
@@ -0,0 +1,17 @@
+https://code.videolan.org/videolan/vlc/-/merge_requests/5304
+
+Index: modules/demux/avformat/mux.c
+--- modules/demux/avformat/mux.c.orig
++++ modules/demux/avformat/mux.c
+@@ -267,7 +267,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t 
+     {
+     case AUDIO_ES:
+         codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( 59, 24, 100 )
++        av_channel_layout_default( &codecpar->ch_layout, fmt->audio.i_channels );
++#else
+         codecpar->channels = fmt->audio.i_channels;
++#endif
+         codecpar->sample_rate = fmt->audio.i_rate;
+         stream->time_base = (AVRational){1, codecpar->sample_rate};
+         if (fmt->i_bitrate == 0) {
