QTfrontend/util/LibavInteraction.cpp
branch1.0.0
changeset 15856 8fd36e1b66ed
parent 14652 92ebe33c5eb6
--- a/QTfrontend/util/LibavInteraction.cpp	Mon Aug 10 12:56:53 2020 +0300
+++ b/QTfrontend/util/LibavInteraction.cpp	Sat Feb 05 10:42:50 2022 -0500
@@ -73,7 +73,11 @@
 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 @@
 
 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 @@
     }
 
     // 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 @@
         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)
         {