From 0ac6f0862c61b1d49a1cfb97c8189dc763085b2e Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 17 Sep 2016 01:23:27 -0700 Subject: [PATCH] FFmpeg: Use max of libav and FFmpeg version numbers --- src/feature/ffmpeg/ffmpeg-encoder.c | 14 ++++++++++++-- src/feature/ffmpeg/ffmpeg-encoder.h | 9 ++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/feature/ffmpeg/ffmpeg-encoder.c b/src/feature/ffmpeg/ffmpeg-encoder.c index e5d77794c..dbae10c11 100644 --- a/src/feature/ffmpeg/ffmpeg-encoder.c +++ b/src/feature/ffmpeg/ffmpeg-encoder.c @@ -214,8 +214,13 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { #endif if (acodec) { +#ifdef FFMPEG_USE_CODECPAR encoder->audioStream = avformat_new_stream(encoder->context, NULL); encoder->audio = avcodec_alloc_context3(acodec); +#else + encoder->audioStream = avformat_new_stream(encoder->context, acodec); + encoder->audio = encoder->audioStream->codec; +#endif encoder->audio->bit_rate = encoder->audioBitrate; encoder->audio->channels = 2; encoder->audio->channel_layout = AV_CH_LAYOUT_STEREO; @@ -266,13 +271,18 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { encoder->absf = av_bitstream_filter_init("aac_adtstoasc"); #endif } -#ifdef FFMPEG_USE_NEW_BSF +#ifdef FFMPEG_USE_CODECPAR avcodec_parameters_from_context(encoder->audioStream->codecpar, encoder->audio); #endif } +#ifdef FFMPEG_USE_CODECPAR encoder->videoStream = avformat_new_stream(encoder->context, NULL); encoder->video = avcodec_alloc_context3(vcodec); +#else + encoder->videoStream = avformat_new_stream(encoder->context, vcodec); + encoder->video = encoder->videoStream->codec; +#endif encoder->video->bit_rate = encoder->videoBitrate; encoder->video->width = encoder->width; encoder->video->height = encoder->height; @@ -306,7 +316,7 @@ bool FFmpegEncoderOpen(struct FFmpegEncoder* encoder, const char* outfile) { encoder->videoFrame->pts = 0; _ffmpegSetVideoDimensions(&encoder->d, encoder->iwidth, encoder->iheight); av_image_alloc(encoder->videoFrame->data, encoder->videoFrame->linesize, encoder->video->width, encoder->video->height, encoder->video->pix_fmt, 32); -#ifdef FFMPEG_USE_NEW_BSF +#ifdef FFMPEG_USE_CODECPAR avcodec_parameters_from_context(encoder->videoStream->codecpar, encoder->video); #endif diff --git a/src/feature/ffmpeg/ffmpeg-encoder.h b/src/feature/ffmpeg/ffmpeg-encoder.h index efd8f3fee..b892daf5d 100644 --- a/src/feature/ffmpeg/ffmpeg-encoder.h +++ b/src/feature/ffmpeg/ffmpeg-encoder.h @@ -11,14 +11,21 @@ #include #include +// Version 57.16 in FFmpeg #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100) #define FFMPEG_USE_PACKETS #endif -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 15, 0) +// Version 57.15 in libav +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 35, 0) #define FFMPEG_USE_NEW_BSF #endif +// Version 57.14 in libav +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 0) +#define FFMPEG_USE_CODECPAR +#endif + #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 8, 0) #define FFMPEG_USE_PACKET_UNREF #endif