- vd_lavc: update to handle deprecation of `pkt_duration`
  83257be693967415f1160f2fa37de9de677c1cab
- ffmpeg: update to handle deprecation of `av_init_packet`
  4574dd5dc6ff75b1fc693afceec59fbcd51ccd4c

Index: video/decode/vd_lavc.c
--- video/decode/vd_lavc.c.orig
+++ video/decode/vd_lavc.c
@@ -23,6 +23,7 @@
 #include <stdbool.h>
 
 #include <libavcodec/avcodec.h>
+#include <libavformat/version.h>
 #include <libavutil/common.h>
 #include <libavutil/hwcontext.h>
 #include <libavutil/opt.h>
@@ -173,6 +174,7 @@ typedef struct lavc_ctx {
     struct mp_codec_params *codec;
     AVCodecContext *avctx;
     AVFrame *pic;
+    AVPacket *avpkt;
     bool use_hwdec;
     struct hwdec_info hwdec; // valid only if use_hwdec==true
     AVRational codec_timebase;
@@ -651,6 +653,10 @@ static void init_avctx(struct mp_filter *vd)
     if (!ctx->pic)
         goto error;
 
+    ctx->avpkt = av_packet_alloc();
+    if (!ctx->avpkt)
+        goto error;
+
     if (ctx->use_hwdec) {
         avctx->opaque = vd;
         avctx->thread_count = 1;
@@ -752,9 +758,8 @@ static void init_avctx(struct mp_filter *vd)
     // x264 build number (encoded in a SEI element), needed to enable a
     // workaround for broken 4:4:4 streams produced by older x264 versions.
     if (lavc_codec->id == AV_CODEC_ID_H264 && c->first_packet) {
-        AVPacket avpkt;
-        mp_set_av_packet(&avpkt, c->first_packet, &ctx->codec_timebase);
-        avcodec_send_packet(avctx, &avpkt);
+        mp_set_av_packet(ctx->avpkt, c->first_packet, &ctx->codec_timebase);
+        avcodec_send_packet(avctx, ctx->avpkt);
         avcodec_receive_frame(avctx, ctx->pic);
         av_frame_unref(ctx->pic);
         avcodec_flush_buffers(ctx->avctx);
@@ -802,6 +807,7 @@ static void uninit_avctx(struct mp_filter *vd)
 
     flush_all(vd);
     av_frame_free(&ctx->pic);
+    mp_free_av_packet(&ctx->avpkt);
     av_buffer_unref(&ctx->cached_hw_frames_ctx);
 
     avcodec_free_context(&ctx->avctx);
@@ -1069,10 +1075,9 @@ static int send_packet(struct mp_filter *vd, struct de
     if (avctx->skip_frame == AVDISCARD_ALL)
         return 0;
 
-    AVPacket avpkt;
-    mp_set_av_packet(&avpkt, pkt, &ctx->codec_timebase);
+    mp_set_av_packet(ctx->avpkt, pkt, &ctx->codec_timebase);
 
-    int ret = avcodec_send_packet(avctx, pkt ? &avpkt : NULL);
+    int ret = avcodec_send_packet(avctx, pkt ? ctx->avpkt : NULL);
     if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
         return ret;
 
@@ -1156,7 +1161,11 @@ static int decode_frame(struct mp_filter *vd)
     mpi->dts = mp_pts_from_av(ctx->pic->pkt_dts, &ctx->codec_timebase);
 
     mpi->pkt_duration =
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 30, 100)
+        mp_pts_from_av(ctx->pic->duration, &ctx->codec_timebase);
+#else
         mp_pts_from_av(ctx->pic->pkt_duration, &ctx->codec_timebase);
+#endif
 
     av_frame_unref(ctx->pic);
 
