Add compatibility with new ffmpeg 5.0, based on patch available here:
authorDebian Games Team <pkg-games-devel@lists.alioth.debian.org>
Sat, 19 Mar 2022 17:39:38 +0000 (17:39 +0000)
committerGianfranco Costamagna <locutusofborg@debian.org>
Sat, 19 Mar 2022 17:39:38 +0000 (17:39 +0000)
https://github.com/opencv/opencv/issues/21455

Author: Gianfranco Costamagna <locutusofborg@debian.org>
Origin: other
Bug-Debian: https://bugs.debian.org/1004825
Forwarded: irc
Last-Update: 2022-02-03

Gbp-Pq: Name ffmpeg-5.0-compat.patch

QTfrontend/util/LibavInteraction.cpp
hedgewars/avwrapper/avwrapper.c

index 23798668e6a6638c9c0b684c24ab1217b6b36dad..541526da51bac5eec9f470ae5114d12460b511cb 100644 (file)
@@ -73,7 +73,11 @@ QList<Codec> codecs;
 QMap<QString,Format> formats;
 
 // test if given format supports given codec
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+bool FormatQueryCodec(const AVOutputFormat *ofmt, enum AVCodecID codec_id)
+#else
 bool FormatQueryCodec(AVOutputFormat *ofmt, enum AVCodecID codec_id)
+#endif
 {
 #if LIBAVFORMAT_VERSION_MAJOR >= 54
     return avformat_query_codec(ofmt, codec_id, FF_COMPLIANCE_NORMAL) == 1;
@@ -86,12 +90,20 @@ bool FormatQueryCodec(AVOutputFormat *ofmt, enum AVCodecID codec_id)
 
 LibavInteraction::LibavInteraction() : QObject()
 {
+#if LIBAVCODEC_VERSION_MAJOR < 59
     // initialize libav and register all codecs and formats
     av_register_all();
+#endif
 
     // get list of all codecs
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+    const AVCodec* pCodec = NULL;
+    void* i = 0;
+    while ((pCodec = av_codec_iterate(&i)))
+#else
     AVCodec* pCodec = NULL;
     while ((pCodec = av_codec_next(pCodec)))
+#endif
     {
         if (!av_codec_is_encoder(pCodec))
             continue;
@@ -179,8 +191,14 @@ LibavInteraction::LibavInteraction() : QObject()
     }
 
     // get list of all formats
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+    const AVOutputFormat* pFormat = NULL;
+    i = 0;
+    while ((pFormat = av_muxer_iterate(&i)))
+#else
     AVOutputFormat* pFormat = NULL;
     while ((pFormat = av_oformat_next(pFormat)))
+#endif
     {
         if (!pFormat->extensions)
             continue;
@@ -296,12 +314,22 @@ QString LibavInteraction::getFileInfo(const QString & filepath)
         AVStream* pStream = pContext->streams[i];
         if (!pStream)
             continue;
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+        const AVCodec *st_codec = avcodec_find_decoder(pContext->streams[i]->codecpar->codec_id);
+        AVCodecContext* pCodec = avcodec_alloc_context3(st_codec);
+        avcodec_parameters_to_context(pCodec, pContext->streams[i]->codecpar);
+#else
         AVCodecContext* pCodec = pContext->streams[i]->codec;
+#endif
         if (!pCodec)
             continue;
 
 
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+        const AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id);
+#else
         AVCodec* pDecoder = avcodec_find_decoder(pCodec->codec_id);
+#endif
         QString decoderName = pDecoder ? pDecoder->name : tr("unknown");
         if (pCodec->codec_type == AVMEDIA_TYPE_VIDEO)
         {
index ac256fbba1062394870d93ef75afc1f39c7de16f..6c0fe739b49289271052ee2016cacb80087bcd5e 100644 (file)
 #include "libavutil/avutil.h"
 #include "libavutil/mathematics.h"
 
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+#include <libavcodec/bsf.h>
+#endif
+
 #if (defined _MSC_VER)
 #define AVWRAP_DECL __declspec(dllexport)
 #elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun))
@@ -171,7 +175,13 @@ static void AddAudioStream()
     }
     g_pAStream->id = 1;
 
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+    const AVCodec *audio_st_codec = avcodec_find_decoder(g_pAStream->codecpar->codec_id);
+    g_pAudio = avcodec_alloc_context3(audio_st_codec);
+    avcodec_parameters_to_context(g_pAudio, g_pAStream->codecpar);
+#else
     g_pAudio = g_pAStream->codec;
+#endif
 
     avcodec_get_context_defaults3(g_pAudio, g_pACodec);
     g_pAudio->codec_id = g_pACodec->id;
@@ -279,7 +289,13 @@ static int AddVideoStream()
     if (!g_pVStream)
         return FatalError("Could not allocate video stream");
 
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+    const AVCodec *video_st_codec = avcodec_find_decoder(g_pVStream->codecpar->codec_id);
+    g_pVideo = avcodec_alloc_context3(video_st_codec);
+    avcodec_parameters_to_context(g_pVideo, g_pVStream->codecpar);
+#else
     g_pVideo = g_pVStream->codec;
+#endif
 
     avcodec_get_context_defaults3(g_pVideo, g_pVCodec);
     g_pVideo->codec_id = g_pVCodec->id;
@@ -499,8 +515,10 @@ AVWRAP_DECL int AVWrapper_Init(
     g_Framerate.den = FramerateDen;
     g_VQuality = VQuality;
 
+#if LIBAVCODEC_VERSION_MAJOR < 59
     // initialize libav and register all codecs and formats
     av_register_all();
+#endif
 
     // find format
     g_pFormat = av_guess_format(pFormatName, NULL, NULL);
@@ -522,8 +540,11 @@ AVWRAP_DECL int AVWrapper_Init(
     strncpy(ext, g_pFormat->extensions, 16);
     ext[15] = 0;
     ext[strcspn(ext,",")] = 0;
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+    snprintf(g_pContainer->url, sizeof(g_pContainer->url), "%s.%s", pFilename, ext);
+#else
     snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext);
-
+#endif
     // find codecs
     g_pVCodec = avcodec_find_encoder_by_name(pVCodecName);
     g_pACodec = avcodec_find_encoder_by_name(pACodecName);
@@ -560,13 +581,22 @@ AVWRAP_DECL int AVWrapper_Init(
         return FatalError("No video, no audio, aborting...");
 
     // write format info to log
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+    av_dump_format(g_pContainer, 0, g_pContainer->url, 1);
+#else
     av_dump_format(g_pContainer, 0, g_pContainer->filename, 1);
+#endif
 
     // open the output file, if needed
     if (!(g_pFormat->flags & AVFMT_NOFILE))
     {
+#if LIBAVCODEC_VERSION_MAJOR >= 59
+        if (avio_open(&g_pContainer->pb, g_pContainer->url, AVIO_FLAG_WRITE) < 0)
+            return FatalError("Could not open output file (%s)", g_pContainer->url);
+#else
         if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0)
             return FatalError("Could not open output file (%s)", g_pContainer->filename);
+#endif
     }
 
     g_pVFrame->pts = -1;