-
Notifications
You must be signed in to change notification settings - Fork 0
/
0007-Fix-compilation-FFmpeg-Libav.patch
204 lines (170 loc) · 7.04 KB
/
0007-Fix-compilation-FFmpeg-Libav.patch
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
From: =?utf-8?q?Martin_Stegh=C3=B6fer?= <martin@steghoefer.eu>
Date: Sat, 12 Apr 2014 15:19:48 +0200
Subject: Fix compilation: FFmpeg/Libav
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Author: Martin Steghöfer <martin@steghoefer.eu>
Forwarded: not-needed
The upstream developers compile Karlyriceditor against FFmpeg, but in Debian
there is only Libav available, whose API is slowly drifting away from
FFmpeg's. This patch adapts the code to several of those differences:
* The second parameters of "avformat_new_stream" is of non-const pointer
type, but the code tries to pass a const pointer to it.
* There is no AV_ROUND_PASS_MINMAX flag for the rounding parameter of
av_rescale_q_rnd in Libav.
* The member r_frame_rate is no longer present in AVStream. The recommended
replacement is avg_frame_rate.
* The enums CODEC_ID_MP3 and CODEC_ID_AC3 have been prefixed with AV_.
* The function avcodec_alloc_frame was removed in favor of av_frame_alloc.
The corresponding deallocation function is av_frame_free (not the generic
av_free).
---
src/audioplayerprivate.cpp | 4 ++--
src/ffmpeg_headers.h | 10 ++++++++++
src/ffmpegvideodecoder.cpp | 8 ++++----
src/ffmpegvideoencoder.cpp | 32 ++++++++++++++++++++------------
4 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/src/audioplayerprivate.cpp b/src/audioplayerprivate.cpp
index 1b6b32d..a6536cd 100644
--- a/src/audioplayerprivate.cpp
+++ b/src/audioplayerprivate.cpp
@@ -118,7 +118,7 @@ void AudioPlayerPrivate::close()
}
if ( m_frame )
- av_free( m_frame );
+ av_frame_free( &m_frame );
m_frame = 0;
pFormatCtx = 0;
@@ -227,7 +227,7 @@ bool AudioPlayerPrivate::open( const QString& filename )
}
// Allocate the buffer
- m_frame = avcodec_alloc_frame();
+ m_frame = av_frame_alloc();
if ( !m_frame )
{
diff --git a/src/ffmpeg_headers.h b/src/ffmpeg_headers.h
index 3d18808..c108c86 100644
--- a/src/ffmpeg_headers.h
+++ b/src/ffmpeg_headers.h
@@ -34,6 +34,7 @@ extern "C"
#include <libswscale/swscale.h>
#include <libavresample/avresample.h>
#include <libavutil/opt.h>
+#include <libavutil/version.h>
};
@@ -41,4 +42,13 @@ void ffmpeg_init_once();
#define FFMPEG_FILENAME(string) ( qPrintable(string) )
+/*
+ * Functions were renamed in interface version 53 (=10.0), but are
+ * essentially the same (documentation literally says the same).
+ */
+#if LIBAVUTIL_VERSION_MAJOR < 53
+# define av_frame_alloc avcodec_alloc_frame
+# define av_frame_free avcodec_free_frame
+#endif
+
#endif // FFMPEG_HEADERS_H
diff --git a/src/ffmpegvideodecoder.cpp b/src/ffmpegvideodecoder.cpp
index 2ec5969..7820f72 100644
--- a/src/ffmpegvideodecoder.cpp
+++ b/src/ffmpegvideodecoder.cpp
@@ -113,8 +113,8 @@ bool FFMpegVideoDecoder::openFile( const QString& filename, unsigned int seekto
if ( d->videoStream == -1 )
return false; // Didn't find a video stream
- d->m_fps_den = d->pFormatCtx->streams[d->videoStream]->r_frame_rate.den;
- d->m_fps_num = d->pFormatCtx->streams[d->videoStream]->r_frame_rate.num;
+ d->m_fps_den = d->pFormatCtx->streams[d->videoStream]->avg_frame_rate.den;
+ d->m_fps_num = d->pFormatCtx->streams[d->videoStream]->avg_frame_rate.num;
if ( d->m_fps_den == 60000 )
d->m_fps_den = 30000;
@@ -139,10 +139,10 @@ bool FFMpegVideoDecoder::openFile( const QString& filename, unsigned int seekto
}
// Allocate video frame
- d->pFrame = avcodec_alloc_frame();
+ d->pFrame = av_frame_alloc();
// Allocate an AVFrame structure
- d->pFrameRGB = avcodec_alloc_frame();
+ d->pFrameRGB = av_frame_alloc();
if ( !d->pFrame || !d->pFrameRGB )
{
diff --git a/src/ffmpegvideoencoder.cpp b/src/ffmpegvideoencoder.cpp
index 49182b5..bdf1730 100644
--- a/src/ffmpegvideoencoder.cpp
+++ b/src/ffmpegvideoencoder.cpp
@@ -174,10 +174,10 @@ bool FFMpegVideoEncoderPriv::close()
delete[] audioSampleBuffer;
if ( videoFrame )
- av_free(videoFrame);
+ av_frame_free( &videoFrame );
if ( audioFrame )
- av_free( audioFrame );
+ av_frame_free( &audioFrame );
outputFormatCtx = 0;
outputFormat = 0;
@@ -383,7 +383,11 @@ av_log_set_level(AV_LOG_VERBOSE);
}
// Create the video stream, index
- videoStream = avformat_new_stream( outputFormatCtx, videoCodecCtx->codec );
+ // Use a block to keep the helper variable "codec" local to avoid conflict with gotos
+ {
+ AVCodec codec = *videoCodecCtx->codec;
+ videoStream = avformat_new_stream( outputFormatCtx, &codec );
+ }
if ( !videoStream )
{
@@ -425,10 +429,10 @@ av_log_set_level(AV_LOG_VERBOSE);
// We're copying the stream
memcpy( newCtx, m_aplayer->aCodecCtx, sizeof(AVCodecContext) );
- if ( newCtx->block_align == 1 && newCtx->codec_id == CODEC_ID_MP3 )
+ if ( newCtx->block_align == 1 && newCtx->codec_id == AV_CODEC_ID_MP3 )
newCtx->block_align= 0;
- if ( newCtx->codec_id == CODEC_ID_AC3 )
+ if ( newCtx->codec_id == AV_CODEC_ID_AC3 )
newCtx->block_align= 0;
}
else
@@ -443,7 +447,7 @@ av_log_set_level(AV_LOG_VERBOSE);
}
// Hack to use the fixed AC3 codec if available
- if ( audioCodec->id == CODEC_ID_AC3 && avcodec_find_encoder_by_name( "ac3_fixed" ) )
+ if ( audioCodec->id == AV_CODEC_ID_AC3 && avcodec_find_encoder_by_name( "ac3_fixed" ) )
audioCodec = avcodec_find_encoder_by_name( "ac3_fixed" );
// Allocate the audio context
@@ -544,7 +548,7 @@ av_log_set_level(AV_LOG_VERBOSE);
goto cleanup;
}
- audioFrame = avcodec_alloc_frame();
+ audioFrame = av_frame_alloc();
if ( !audioFrame )
{
@@ -573,10 +577,10 @@ av_log_set_level(AV_LOG_VERBOSE);
goto cleanup;
}
- if ( audioStream->codec->block_align == 1 && audioStream->codec->codec_id == CODEC_ID_MP3 )
+ if ( audioStream->codec->block_align == 1 && audioStream->codec->codec_id == AV_CODEC_ID_MP3 )
audioStream->codec->block_align= 0;
- if ( audioStream->codec->codec_id == CODEC_ID_AC3 )
+ if ( audioStream->codec->codec_id == AV_CODEC_ID_AC3 )
audioStream->codec->block_align= 0;
}
@@ -595,7 +599,7 @@ av_log_set_level(AV_LOG_VERBOSE);
}
// Allocate the YUV frame
- videoFrame = avcodec_alloc_frame();
+ videoFrame = av_frame_alloc();
if ( !videoFrame )
{
@@ -753,8 +757,12 @@ int FFMpegVideoEncoderPriv::encodeImage( const QImage &img, qint64 )
pkt.flags |= AV_PKT_FLAG_KEY;
// Rescale output packet timestamp values from codec to stream timebase
- pkt.pts = av_rescale_q_rnd( pkt.pts, audioCodecCtx->time_base, audioStream->time_base, (AVRounding) (AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX) );
- pkt.dts = av_rescale_q_rnd( pkt.dts, audioCodecCtx->time_base, audioStream->time_base, (AVRounding) (AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX) );
+ if ( pkt.pts != AV_NOPTS_VALUE ) {
+ pkt.pts = av_rescale_q_rnd( pkt.pts, audioCodecCtx->time_base, audioStream->time_base, AV_ROUND_NEAR_INF );
+ }
+ if ( pkt.dts != AV_NOPTS_VALUE ) {
+ pkt.dts = av_rescale_q_rnd( pkt.dts, audioCodecCtx->time_base, audioStream->time_base, AV_ROUND_NEAR_INF );
+ }
pkt.duration = av_rescale_q( pkt.duration, audioCodecCtx->time_base, audioStream->time_base);
// And write the file