From 3c72f622961eee2bdb825de89232e2db6444f53e Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Sun, 24 Jul 2022 03:15:13 +0300
Subject: [PATCH 3/3] Some patches move easily between ffmpeg 4.4 and 5.1

---
 .../thirdparty/src/ffmpeg-5.1.patch1          | 11 ++++++
 .../thirdparty/src/ffmpeg-5.1.patch10         | 36 +++++++++++++++++++
 .../thirdparty/src/ffmpeg-5.1.patch2          | 13 +++++++
 .../thirdparty/src/ffmpeg-5.1.patch7          | 12 +++++++
 .../thirdparty/src/ffmpeg-5.1.patch8          | 13 +++++++
 .../thirdparty/src/ffmpeg-5.1.patch9          | 16 +++++++++
 .../thirdparty/src/ffmpeg-5.1.patchB          | 24 +++++++++++++
 7 files changed, 125 insertions(+)
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch1
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch10
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch2
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch7
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch8
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch9
 create mode 100644 cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patchB

diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch1 b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch1
new file mode 100644
index 00000000..6f8ba6a7
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch1
@@ -0,0 +1,11 @@
+--- ./fftools/cmdutils.c.orig	2022-07-24 02:18:50.173283271 +0300
++++ ./fftools/cmdutils.c	2022-07-24 02:20:36.089283196 +0300
+@@ -59,7 +59,7 @@
+ AVDictionary *swr_opts;
+ AVDictionary *format_opts, *codec_opts;
+ 
+-int hide_banner = 0;
++int hide_banner = 1;
+ 
+ void uninit_opts(void)
+ {
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch10 b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch10
new file mode 100644
index 00000000..0cf24e74
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch10
@@ -0,0 +1,36 @@
+diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
+index 718a449b6e..84685fe1d9 100644
+--- a/libavutil/hwcontext_cuda.c
++++ b/libavutil/hwcontext_cuda.c
+@@ -269,9 +269,11 @@ static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
+         CudaFunctions *cu = hwctx->internal->cuda_dl;
+ 
+         if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
++#ifdef CUDA_PRIMARY_CTX
+             if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
+                 CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
+             else
++#endif
+                 CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
+ 
+             hwctx->cuda_ctx = NULL;
+@@ -321,7 +323,7 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
+     cu = hwctx->internal->cuda_dl;
+ 
+     hwctx->internal->flags = flags;
+-
++#ifdef CUDA_PRIMARY_CTX
+     if (flags & AV_CUDA_USE_PRIMARY_CONTEXT) {
+         ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
+                        &dev_flags, &dev_active));
+@@ -342,7 +344,9 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
+                                                     hwctx->internal->cuda_device));
+         if (ret < 0)
+             return ret;
+-    } else {
++    } else
++#endif
++    {
+         ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
+                                        hwctx->internal->cuda_device));
+         if (ret < 0)
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch2 b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch2
new file mode 100644
index 00000000..88631302
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch2
@@ -0,0 +1,13 @@
+diff --git a/libavformat/bluray.c b/libavformat/bluray.c
+index 635c4f1b87..80a2e2c3d2 100644
+--- a/libavformat/bluray.c
++++ b/libavformat/bluray.c
+@@ -28,7 +28,7 @@
+ #include "libavutil/opt.h"
+ 
+ #define BLURAY_PROTO_PREFIX     "bluray:"
+-#define MIN_PLAYLIST_LENGTH     180     /* 3 min */
++#define MIN_PLAYLIST_LENGTH     0
+ 
+ typedef struct {
+     const AVClass *class;
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch7 b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch7
new file mode 100644
index 00000000..e59a17cc
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch7
@@ -0,0 +1,12 @@
+diff --git a/libavcodec/vdpau_mpeg12.c b/libavcodec/vdpau_mpeg12.c
+index 72220ffb4e..5687c416c9 100644
+--- a/libavcodec/vdpau_mpeg12.c
++++ b/libavcodec/vdpau_mpeg12.c
+@@ -114,6 +114,7 @@ const AVHWAccel ff_mpeg1_vdpau_hwaccel = {
+     .frame_priv_data_size = sizeof(struct vdpau_picture_context),
+     .init           = vdpau_mpeg1_init,
+     .uninit         = ff_vdpau_common_uninit,
++    .frame_params   = ff_vdpau_common_frame_params,
+     .priv_data_size = sizeof(VDPAUContext),
+     .caps_internal  = HWACCEL_CAP_ASYNC_SAFE,
+ };
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch8 b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch8
new file mode 100644
index 00000000..05d3b1d0
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch8
@@ -0,0 +1,13 @@
+diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
+index 3b29a189e9..681a4187c5 100644
+--- a/libavcodec/h263dec.c
++++ b/libavcodec/h263dec.c
+@@ -684,7 +684,7 @@ frame_end:
+     if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
+         ff_mpeg4_frame_end(avctx, buf, buf_size);
+ 
+-    if (!s->divx_packed && avctx->hwaccel)
++    if (s->divx_packed && avctx->hwaccel)
+         ff_thread_finish_setup(avctx);
+ 
+     av_assert1(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch9 b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch9
new file mode 100644
index 00000000..51bc09e3
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patch9
@@ -0,0 +1,16 @@
+diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
+index 9bd0a555d4..111a9f3a46 100644
+--- a/libavformat/mpegenc.c
++++ b/libavformat/mpegenc.c
+@@ -976,9 +976,9 @@ static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr)
+         PacketDesc *pkt_desc;
+ 
+         while ((pkt_desc = stream->predecode_packet) &&
++               pkt_desc != stream->premux_packet &&
+                scr > pkt_desc->dts) { // FIXME: > vs >=
+-            if (stream->buffer_index < pkt_desc->size ||
+-                stream->predecode_packet == stream->premux_packet) {
++            if (stream->buffer_index < pkt_desc->size) {
+                 av_log(ctx, AV_LOG_ERROR,
+                        "buffer underflow st=%d bufi=%d size=%d\n",
+                        i, stream->buffer_index, pkt_desc->size);
diff --git a/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patchB b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patchB
new file mode 100644
index 00000000..6d181e3c
--- /dev/null
+++ b/cinelerra-5.1/thirdparty/src/ffmpeg-5.1.patchB
@@ -0,0 +1,24 @@
+diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
+index dbef5495af..fba06d8ccf 100644
+--- a/libavutil/hwcontext_vdpau.c
++++ b/libavutil/hwcontext_vdpau.c
+@@ -68,6 +68,11 @@ static const VDPAUPixFmtMap pix_fmts_420[] = {
+     { 0,                     AV_PIX_FMT_NONE,   },
+ };
+ 
++static const VDPAUPixFmtMap pix_fmts_420j[] = {
++    { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUVJ420P },
++    { 0,                     AV_PIX_FMT_NONE,   },
++};
++
+ static const VDPAUPixFmtMap pix_fmts_422[] = {
+     { VDP_YCBCR_FORMAT_NV12, AV_PIX_FMT_NV16    },
+     { VDP_YCBCR_FORMAT_YV12, AV_PIX_FMT_YUV422P },
+@@ -92,6 +97,7 @@ static const struct {
+     const VDPAUPixFmtMap *map;
+ } vdpau_pix_fmts[] = {
+     { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUV420P, pix_fmts_420 },
++    { VDP_CHROMA_TYPE_420, AV_PIX_FMT_YUVJ420P, pix_fmts_420j },
+     { VDP_CHROMA_TYPE_422, AV_PIX_FMT_YUV422P, pix_fmts_422 },
+     { VDP_CHROMA_TYPE_444, AV_PIX_FMT_YUV444P, pix_fmts_444 },
+ #ifdef VDP_YCBCR_FORMAT_P016
-- 
2.37.1

