Skip to content

Commit

Permalink
Make QtAV build with newer versions of FFmpeg
Browse files Browse the repository at this point in the history
Some defines changed their name in newer versions of FFmpeg, this
patch uses preprocessor instructions in AVCompat.h to use the
correct define names. Also filter names retrieved by
'avfilter_get_by_name' should be used as const variables in
libavfilter versions starting at 7.0.0.
  • Loading branch information
0xFelix committed Nov 11, 2017
1 parent d59fec6 commit 7f6929b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AVMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ AVStream *AVMuxer::Private::addStream(AVFormatContext* ctx, const QString &codec
c->time_base = s->time_base;
/* Some formats want stream headers to be separate. */
if (ctx->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
// expose avctx to encoder and set properties in encoder?
// list codecs for a given format in ui
return s;
Expand Down
12 changes: 12 additions & 0 deletions src/QtAV/private/AVCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,15 @@ const char *get_codec_long_name(AVCodecID id);
} } while(0)

#endif //QTAV_COMPAT_H

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,33,0)
#define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER
#endif

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,56,100)
#define AV_INPUT_BUFFER_MIN_SIZE FF_MIN_BUFFER_SIZE
#endif

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,56,100)
#define AV_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
#endif
4 changes: 2 additions & 2 deletions src/codec/audio/AudioEncoderFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ bool AudioEncoderFFmpegPrivate::open()
} else {
buffer_size = frame_size*format_used.bytesPerSample()*format_used.channels()*2+200;
}
if (buffer_size < FF_MIN_BUFFER_SIZE)
buffer_size = FF_MIN_BUFFER_SIZE;
if (buffer_size < AV_INPUT_BUFFER_MIN_SIZE)
buffer_size = AV_INPUT_BUFFER_MIN_SIZE;
buffer.resize(buffer_size);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/codec/video/VideoEncoderFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ bool VideoEncoderFFmpegPrivate::open()
applyOptionsForContext();
AV_ENSURE_OK(avcodec_open2(avctx, codec, &dict), false);
// from mpv ao_lavc
const int buffer_size = qMax<int>(qMax<int>(width*height*6+200, FF_MIN_BUFFER_SIZE), sizeof(AVPicture));//??
const int buffer_size = qMax<int>(qMax<int>(width*height*6+200, AV_INPUT_BUFFER_MIN_SIZE), sizeof(AVPicture));//??
buffer.resize(buffer_size);
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion src/filter/LibAVFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,20 @@ class LibAVFilter::Private
// pixel_aspect==sar, pixel_aspect is more compatible
QString buffersrc_args = args;
qDebug("buffersrc_args=%s", buffersrc_args.toUtf8().constData());
AVFilter *buffersrc = avfilter_get_by_name(video ? "buffer" : "abuffer");
#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(7,0,0)
const
#endif
AVFilter *buffersrc = avfilter_get_by_name(video ? "buffer" : "abuffer");
Q_ASSERT(buffersrc);
AV_ENSURE_OK(avfilter_graph_create_filter(&in_filter_ctx,
buffersrc,
"in", buffersrc_args.toUtf8().constData(), NULL,
filter_graph)
, false);
/* buffer video sink: to terminate the filter chain. */
#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(7,0,0)
const
#endif
AVFilter *buffersink = avfilter_get_by_name(video ? "buffersink" : "abuffersink");
Q_ASSERT(buffersink);
AV_ENSURE_OK(avfilter_graph_create_filter(&out_filter_ctx, buffersink, "out",
Expand Down
2 changes: 1 addition & 1 deletion src/subtitle/SubtitleProcessorFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool SubtitleProcessorFFmpeg::processHeader(const QByteArray &codec, const QByte
codec_ctx->time_base.den = 1000;
if (!data.isEmpty()) {
av_free(codec_ctx->extradata);
codec_ctx->extradata = (uint8_t*)av_mallocz(data.size() + FF_INPUT_BUFFER_PADDING_SIZE);
codec_ctx->extradata = (uint8_t*)av_mallocz(data.size() + AV_INPUT_BUFFER_PADDING_SIZE);
if (!codec_ctx->extradata)
return false;
codec_ctx->extradata_size = data.size();
Expand Down

0 comments on commit 7f6929b

Please sign in to comment.