[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53741] trunk/blender: Patch #33837: ffmpeg1.1 and libav9.1 compatibility update

Sergey Sharybin sergey.vfx at gmail.com
Sat Jan 12 13:51:14 CET 2013


Revision: 53741
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53741
Author:   nazgul
Date:     2013-01-12 12:51:10 +0000 (Sat, 12 Jan 2013)
Log Message:
-----------
Patch #33837: ffmpeg1.1 and libav9.1 compatibility update

Patch makes it possible to compile blender with recent ffmpeg
and libav libraries, mainly by getting rid of deprecated API.

Original patch by Campbell Barton with own modifications to
support compilation with older ffmpeg versions.

This patch could break compatibility of FFV1 videos playing
back in older players, mainly because of alpha support changes.
Preserving compatibility with such players became a headache
and think it's high time to get rid of workarounds here.

Modified Paths:
--------------
    trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
    trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
    trunk/blender/intern/ffmpeg/ffmpeg_compat.h
    trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
    trunk/blender/source/blender/imbuf/intern/anim_movie.c
    trunk/blender/source/blender/imbuf/intern/indexer.c
    trunk/blender/source/blender/imbuf/intern/util.c
    trunk/blender/source/gameengine/VideoTexture/VideoFFmpeg.cpp

Modified: trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp
===================================================================
--- trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp	2013-01-12 12:46:25 UTC (rev 53740)
+++ trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGReader.cpp	2013-01-12 12:51:10 UTC (rev 53741)
@@ -107,7 +107,7 @@
 	m_position = 0;
 	m_pkgbuf_left = 0;
 
-	if(av_find_stream_info(m_formatCtx)<0)
+	if(avformat_find_stream_info(m_formatCtx, NULL) < 0)
 		AUD_THROW(AUD_ERROR_FFMPEG, streaminfo_error);
 
 	// find audio stream and codec
@@ -133,7 +133,7 @@
 	if(!aCodec)
 		AUD_THROW(AUD_ERROR_FFMPEG, nodecoder_error);
 
-	if(avcodec_open(m_codecCtx, aCodec)<0)
+	if(avcodec_open2(m_codecCtx, aCodec, NULL) < 0)
 		AUD_THROW(AUD_ERROR_FFMPEG, codecopen_error);
 
 	// XXX this prints file information to stdout:
@@ -236,14 +236,7 @@
 AUD_FFMPEGReader::~AUD_FFMPEGReader()
 {
 	avcodec_close(m_codecCtx);
-
-	if(m_aviocontext)
-	{
-		avformat_close_input(&m_formatCtx);
-		av_free(m_aviocontext);
-	}
-	else
-		av_close_input_file(m_formatCtx);
+	avformat_close_input(&m_formatCtx);
 }
 
 int AUD_FFMPEGReader::read_packet(void* opaque, uint8_t* buf, int buf_size)

Modified: trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp
===================================================================
--- trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp	2013-01-12 12:46:25 UTC (rev 53740)
+++ trunk/blender/intern/audaspace/ffmpeg/AUD_FFMPEGWriter.cpp	2013-01-12 12:51:10 UTC (rev 53741)
@@ -55,11 +55,16 @@
 {
 	static const char* formats[] = { NULL, "ac3", "flac", "matroska", "mp2", "mp3", "ogg", "wav" };
 
-	if(avformat_alloc_output_context2(&m_formatCtx, NULL, formats[format], filename.c_str()))
+	m_formatCtx = avformat_alloc_context();
+	if (!m_formatCtx) AUD_THROW(AUD_ERROR_FFMPEG, context_error);
+
+	strcpy(m_formatCtx->filename, filename.c_str());
+	m_outputFmt = m_formatCtx->oformat = av_guess_format(formats[format], filename.c_str(), NULL);
+	if (!m_outputFmt) {
+		avformat_free_context(m_formatCtx);
 		AUD_THROW(AUD_ERROR_FFMPEG, context_error);
+	}
 
-	m_outputFmt = m_formatCtx->oformat;
-
 	switch(codec)
 	{
 	case AUD_CODEC_AAC:
@@ -116,7 +121,7 @@
 		if(m_outputFmt->audio_codec == CODEC_ID_NONE)
 			AUD_THROW(AUD_ERROR_SPECS, codec_error);
 
-		m_stream = av_new_stream(m_formatCtx, 0);
+		m_stream = avformat_new_stream(m_formatCtx, NULL);
 		if(!m_stream)
 			AUD_THROW(AUD_ERROR_FFMPEG, stream_error);
 
@@ -164,7 +169,7 @@
 			if(!codec)
 				AUD_THROW(AUD_ERROR_FFMPEG, codec_error);
 
-			if(avcodec_open(m_codecCtx, codec))
+			if(avcodec_open2(m_codecCtx, codec, NULL))
 				AUD_THROW(AUD_ERROR_FFMPEG, codec_error);
 
 			m_output_buffer.resize(FF_MIN_BUFFER_SIZE);

Modified: trunk/blender/intern/ffmpeg/ffmpeg_compat.h
===================================================================
--- trunk/blender/intern/ffmpeg/ffmpeg_compat.h	2013-01-12 12:46:25 UTC (rev 53740)
+++ trunk/blender/intern/ffmpeg/ffmpeg_compat.h	2013-01-12 12:51:10 UTC (rev 53741)
@@ -33,6 +33,7 @@
 #include <libavcodec/avcodec.h>
 #include <libavutil/rational.h>
 #include <libavutil/opt.h>
+#include <libavutil/mathematics.h>
 
 #if (LIBAVFORMAT_VERSION_MAJOR > 52) || ((LIBAVFORMAT_VERSION_MAJOR >= 52) && (LIBAVFORMAT_VERSION_MINOR >= 101))
 #define FFMPEG_HAVE_PARSE_UTILS 1
@@ -73,12 +74,68 @@
 
 #if ((LIBAVUTIL_VERSION_MAJOR > 51) || (LIBAVUTIL_VERSION_MAJOR == 51) && (LIBAVUTIL_VERSION_MINOR >= 32))
 #define FFMPEG_FFV1_ALPHA_SUPPORTED
+#else
+static inline
+int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
+{
+	const AVOption *rv = NULL;
+	av_set_string3(obj, name, val, 1, &rv);
+	return rv != NULL;
+}
+
+static inline
+int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
+{
+	const AVOption *rv = NULL;
+	rv = av_set_int(obj, name, val);
+	return rv != NULL;
+}
+
+static inline
+int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
+{
+	const AVOption *rv = NULL;
+	rv = av_set_double(obj, name, val);
+	return rv != NULL;
+}
+
+#define AV_OPT_TYPE_INT     FF_OPT_TYPE_INT
+#define AV_OPT_TYPE_INT64   FF_OPT_TYPE_INT64
+#define AV_OPT_TYPE_STRING  FF_OPT_TYPE_STRING
+#define AV_OPT_TYPE_CONST   FF_OPT_TYPE_CONST
+#define AV_OPT_TYPE_DOUBLE  FF_OPT_TYPE_DOUBLE
+#define AV_OPT_TYPE_FLOAT   FF_OPT_TYPE_FLOAT
 #endif
 
 #if ((LIBAVFORMAT_VERSION_MAJOR < 53) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR < 24)) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR < 24) && (LIBAVFORMAT_VERSION_MICRO < 2)))
 #define avformat_close_input(x) av_close_input_file(*(x))
 #endif
 
+#if ((LIBAVCODEC_VERSION_MAJOR < 53) || (LIBAVCODEC_VERSION_MAJOR == 53 && LIBAVCODEC_VERSION_MINOR < 42))
+static inline
+int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)
+{
+	/* TODO: no options are taking into account */
+	return avcodec_open(avctx, codec);
+}
+#endif
+
+#if ((LIBAVFORMAT_VERSION_MAJOR < 53) || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR < 24))
+static inline
+AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)
+{
+	/* TODO: no codec is taking into account */
+	return av_new_stream(s, 0);
+}
+
+static inline
+int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
+{
+	/* TODO: no options are taking into account */
+	return av_find_stream_info(ic);
+}
+#endif
+
 #if ((LIBAVFORMAT_VERSION_MAJOR > 53) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR > 32)) || ((LIBAVFORMAT_VERSION_MAJOR == 53) && (LIBAVFORMAT_VERSION_MINOR == 24) && (LIBAVFORMAT_VERSION_MICRO >= 100)))
 static inline
 void my_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)

Modified: trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2013-01-12 12:46:25 UTC (rev 53740)
+++ trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2013-01-12 12:51:10 UTC (rev 53741)
@@ -373,7 +373,7 @@
 {
 	char name[128];
 	char *param;
-	const AVOption *rv = NULL;
+	int fail = TRUE;
 
 	PRINT("FFMPEG expert option: %s: ", prop->name);
 
@@ -388,30 +388,30 @@
 	switch (prop->type) {
 		case IDP_STRING:
 			PRINT("%s.\n", IDP_String(prop));
-			av_set_string3(c, prop->name, IDP_String(prop), 1, &rv);
+			fail = av_opt_set(c, prop->name, IDP_String(prop), 0);
 			break;
 		case IDP_FLOAT:
 			PRINT("%g.\n", IDP_Float(prop));
-			rv = av_set_double(c, prop->name, IDP_Float(prop));
+			fail = av_opt_set_double(c, prop->name, IDP_Float(prop), 0);
 			break;
 		case IDP_INT:
 			PRINT("%d.\n", IDP_Int(prop));
 
 			if (param) {
 				if (IDP_Int(prop)) {
-					av_set_string3(c, name, param, 1, &rv);
+					fail = av_opt_set(c, name, param, 0);
 				}
 				else {
 					return;
 				}
 			}
 			else {
-				rv = av_set_int(c, prop->name, IDP_Int(prop));
+				fail = av_opt_set_int(c, prop->name, IDP_Int(prop), 0);
 			}
 			break;
 	}
 
-	if (!rv) {
+	if (fail) {
 		PRINT("ffmpeg-option not supported: %s! Skipping.\n", prop->name);
 	}
 }
@@ -464,8 +464,9 @@
 
 	error[0] = '\0';
 
-	st = av_new_stream(of, 0);
+	st = avformat_new_stream(of, NULL);
 	if (!st) return NULL;
+	st->id = 0;
 
 	/* Set up the codec context */
 	
@@ -541,16 +542,7 @@
 	}
 
 	if (codec_id == CODEC_ID_FFV1) {
-#ifdef FFMPEG_FFV1_ALPHA_SUPPORTED
-		if (rd->im_format.planes == R_IMF_PLANES_RGBA) {
-			c->pix_fmt = PIX_FMT_RGB32;
-		}
-		else {
-			c->pix_fmt = PIX_FMT_BGR0;
-		}
-#else
 		c->pix_fmt = PIX_FMT_RGB32;
-#endif
 	}
 
 	if (codec_id == CODEC_ID_QTRLE) {
@@ -582,7 +574,7 @@
 
 	set_ffmpeg_properties(rd, c, "video");
 	
-	if (avcodec_open(c, codec) < 0) {
+	if (avcodec_open2(c, codec, NULL) < 0) {
 		BLI_strncpy(error, IMB_ffmpeg_last_error(), error_size);
 		return NULL;
 	}
@@ -619,8 +611,9 @@
 
 	error[0] = '\0';
 
-	st = av_new_stream(of, 1);
+	st = avformat_new_stream(of, NULL);
 	if (!st) return NULL;
+	st->id = 1;
 
 	c = st->codec;
 	c->codec_id = codec_id;
@@ -642,7 +635,7 @@
 
 	set_ffmpeg_properties(rd, c, "audio");
 
-	if (avcodec_open(c, codec) < 0) {
+	if (avcodec_open2(c, codec, NULL) < 0) {
 		//XXX error("Couldn't initialize audio codec");
 		BLI_strncpy(error, IMB_ffmpeg_last_error(), error_size);
 		return NULL;
@@ -1151,7 +1144,7 @@
 	
 	val.i = 0;
 
-	avcodec_get_context_defaults(&c);
+	avcodec_get_context_defaults3(&c, NULL);
 
 	o = c.av_class->option + opt_index;
 	parent = c.av_class->option + parent_index;
@@ -1182,23 +1175,23 @@
 	}
 
 	switch (o->type) {
-		case FF_OPT_TYPE_INT:
-		case FF_OPT_TYPE_INT64:
+		case AV_OPT_TYPE_INT:
+		case AV_OPT_TYPE_INT64:
 			val.i = FFMPEG_DEF_OPT_VAL_INT(o);
 			idp_type = IDP_INT;
 			break;
-		case FF_OPT_TYPE_DOUBLE:
-		case FF_OPT_TYPE_FLOAT:
+		case AV_OPT_TYPE_DOUBLE:
+		case AV_OPT_TYPE_FLOAT:
 			val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o);
 			idp_type = IDP_FLOAT;
 			break;
-		case FF_OPT_TYPE_STRING:
+		case AV_OPT_TYPE_STRING:
 			val.string.str = (char *)"                                                                               ";
 			val.string.len = 80;
 /*		val.str = (char *)"                                                                               ";*/
 			idp_type = IDP_STRING;
 			break;
-		case FF_OPT_TYPE_CONST:
+		case AV_OPT_TYPE_CONST:
 			val.i = 1;
 			idp_type = IDP_INT;
 			break;
@@ -1238,7 +1231,7 @@
 	char *param;
 	IDProperty *prop = NULL;
 	
-	avcodec_get_context_defaults(&c);
+	avcodec_get_context_defaults3(&c, NULL);
 
 	strncpy(name_, str, sizeof(name_));
 
@@ -1259,10 +1252,10 @@
 	if (!o) {
 		return 0;
 	}
-	if (param && o->type == FF_OPT_TYPE_CONST) {
+	if (param && o->type == AV_OPT_TYPE_CONST) {
 		return 0;
 	}
-	if (param && o->type != FF_OPT_TYPE_CONST && o->unit) {
+	if (param && o->type != AV_OPT_TYPE_CONST && o->unit) {
 		p = my_av_find_opt(&c, param, o->unit, 0, 0);
 		if (p) {
 			prop = BKE_ffmpeg_property_add(rd, (char *) type, p - c.av_class->option, o - c.av_class->option);

Modified: trunk/blender/source/blender/imbuf/intern/anim_movie.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/anim_movie.c	2013-01-12 12:46:25 UTC (rev 53740)
+++ trunk/blender/source/blender/imbuf/intern/anim_movie.c	2013-01-12 12:51:10 UTC (rev 53741)
@@ -486,7 +486,7 @@
 		return -1;
 	}
 
-	if (av_find_stream_info(pFormatCtx) < 0) {
+	if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list