summaryrefslogtreecommitdiff
path: root/media-video/ffmpegthumbnailer/files/ffmpeg5-8.patch
blob: d160cbb2404fbdd1922d79b644a06577d1c8a442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 3ffdd65cbda6ef21d36c96013db1b0f4dc9fc57b Mon Sep 17 00:00:00 2001
From: Zane van Iperen <zane@zanevaniperen.com>
Date: Mon, 15 Mar 2021 17:52:01 +1000
Subject: [PATCH] lib/movedecoder: don't rely on avformat to allocate a context

---
 libffmpegthumbnailer/moviedecoder.cpp | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/libffmpegthumbnailer/moviedecoder.cpp b/libffmpegthumbnailer/moviedecoder.cpp
index e58904e..da5f32a 100644
--- a/libffmpegthumbnailer/moviedecoder.cpp
+++ b/libffmpegthumbnailer/moviedecoder.cpp
@@ -90,8 +90,7 @@ void MovieDecoder::destroy()
 {
     if (m_pVideoCodecContext)
     {
-        avcodec_close(m_pVideoCodecContext);
-        m_pVideoCodecContext = nullptr;
+        avcodec_free_context(&m_pVideoCodecContext);
     }
 
     if ((!m_FormatContextWasGiven) && m_pFormatContext)
@@ -196,8 +195,7 @@ void MovieDecoder::initializeVideo(bool preferEmbeddedMetadata)
     }
 
     m_pVideoStream = m_pFormatContext->streams[m_VideoStream];
-    m_pVideoCodecContext = m_pVideoStream->codec;
-    m_pVideoCodec = avcodec_find_decoder(m_pVideoCodecContext->codec_id);
+    m_pVideoCodec = avcodec_find_decoder(m_pVideoStream->codecpar->codec_id);
 
     if (m_pVideoCodec == nullptr)
     {
@@ -207,6 +205,20 @@ void MovieDecoder::initializeVideo(bool preferEmbeddedMetadata)
         throw logic_error("Video Codec not found");
     }
 
+    m_pVideoCodecContext = avcodec_alloc_context3(m_pVideoCodec);
+
+    if (m_pVideoCodecContext == nullptr)
+    {
+        destroy();
+        throw logic_error("Could not allocate video codec context");
+    }
+
+    if (avcodec_parameters_to_context(m_pVideoCodecContext, m_pVideoStream->codecpar) < 0)
+    {
+        destroy();
+        throw logic_error("Could not configure video codec context");
+    }
+
     m_pVideoCodecContext->workaround_bugs = 1;
 
     if (avcodec_open2(m_pVideoCodecContext, m_pVideoCodec, nullptr) < 0)