[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14801] trunk/blender/source/blender: == FFMPEG ==

Peter Schlaile peter at schlaile.de
Sun May 11 22:40:55 CEST 2008


Revision: 14801
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14801
Author:   schlaile
Date:     2008-05-11 22:40:55 +0200 (Sun, 11 May 2008)

Log Message:
-----------
== FFMPEG ==

Add ffmpeg expert option (meaning _all_ ffmpeg option) to render dialog
using properties.

Also adds: H264 preset, that doesn't screw up output.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_idprop.h
    trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h
    trunk/blender/source/blender/blenkernel/intern/scene.c
    trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/src/buttons_scene.c

Modified: trunk/blender/source/blender/blenkernel/BKE_idprop.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_idprop.h	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/blenkernel/BKE_idprop.h	2008-05-11 20:40:55 UTC (rev 14801)
@@ -171,4 +171,9 @@
 /*Unlinks any struct IDProperty<->ID linkage that might be going on.*/
 void IDP_UnlinkProperty(struct IDProperty *prop);
 
+#define IDP_Int(prop) (prop->data.val)
+#define IDP_Float(prop) (*(float*)&prop->data.val)
+#define IDP_String(prop) ((char*)prop->data.pointer)
+#define IDP_Array(prop) (prop->data.pointer)
+
 #endif /* _BKE_IDPROP_H */

Modified: trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h	2008-05-11 20:40:55 UTC (rev 14801)
@@ -58,6 +58,7 @@
 #define FFMPEG_PRESET_SVCD 2
 #define FFMPEG_PRESET_VCD  3
 #define FFMPEG_PRESET_DV   4
+#define FFMPEG_PRESET_H264 5
 
 struct RenderData;	
 

Modified: trunk/blender/source/blender/blenkernel/intern/scene.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/scene.c	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/blenkernel/intern/scene.c	2008-05-11 20:40:55 UTC (rev 14801)
@@ -67,6 +67,7 @@
 #include "BKE_global.h"
 #include "BKE_group.h"
 #include "BKE_ipo.h"
+#include "BKE_idprop.h"
 #include "BKE_image.h"
 #include "BKE_key.h"
 #include "BKE_library.h"
@@ -149,6 +150,11 @@
 		MEM_freeN(sce->r.qtcodecdata);
 		sce->r.qtcodecdata = NULL;
 	}
+	if (sce->r.ffcodecdata.properties) {
+		IDP_FreeProperty(sce->r.ffcodecdata.properties);
+		MEM_freeN(sce->r.ffcodecdata.properties);
+		sce->r.ffcodecdata.properties = NULL;
+	}
 	
 	BLI_freelistN(&sce->markers);
 	BLI_freelistN(&sce->transform_spaces);

Modified: trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2008-05-11 20:40:55 UTC (rev 14801)
@@ -33,6 +33,7 @@
 #include <ffmpeg/avcodec.h>
 #include <ffmpeg/rational.h>
 #include <ffmpeg/swscale.h>
+#include <ffmpeg/opt.h>
 
 #if LIBAVFORMAT_VERSION_INT < (49 << 16)
 #define FFMPEG_OLD_FRAME_RATE 1
@@ -58,6 +59,7 @@
 
 #include "BKE_bad_level_calls.h"
 #include "BKE_global.h"
+#include "BKE_idprop.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
@@ -337,6 +339,75 @@
 	return current_frame;
 }
 
+static void set_ffmpeg_property_option(AVCodecContext* c, IDProperty * prop)
+{
+	char name[128];
+	char * param;
+
+	fprintf(stderr, "FFMPEG expert option: %s: ", prop->name);
+
+	strncpy(name, prop->name, 128);
+
+	param = strchr(name, ':');
+
+	if (param) {
+		*param++ = 0;
+	}
+
+	const AVOption * rv = NULL;
+	switch(prop->type) {
+	case IDP_STRING:
+		fprintf(stderr, "%s.\n", IDP_String(prop));
+		rv = av_set_string(c, prop->name, IDP_String(prop));
+		break;
+	case IDP_FLOAT:
+		fprintf(stderr, "%g.\n", IDP_Float(prop));
+		rv = av_set_double(c, prop->name, IDP_Float(prop));
+		break;
+	case IDP_INT:
+		fprintf(stderr, "%d.\n", IDP_Int(prop));
+		
+		if (param) {
+			if (IDP_Int(prop)) {
+				rv = av_set_string(c, name, param);
+			} else {
+				return;
+			}
+		} else {
+			rv = av_set_int(c, prop->name, IDP_Int(prop));
+		}
+		break;
+	}
+
+	if (!rv) {
+		fprintf(stderr, "ffmpeg-option not supported: %s! Skipping.\n",
+			prop->name);
+	}
+}
+
+static void set_ffmpeg_properties(AVCodecContext* c, const char * prop_name)
+{
+	IDProperty * prop;
+	void * iter;
+	IDProperty * curr;
+
+	if (!G.scene->r.ffcodecdata.properties) {
+		return;
+	}
+	
+	prop = IDP_GetPropertyFromGroup(
+		G.scene->r.ffcodecdata.properties, (char*) prop_name);
+	if (!prop) {
+		return;
+	}
+
+	iter = IDP_GetGroupIterator(prop);
+
+	while ((curr = IDP_GroupIterNext(iter)) != NULL) {
+		set_ffmpeg_property_option(c, curr);
+	}
+}
+
 /* prepare a video stream for the output file */
 
 static AVStream* alloc_video_stream(int codec_id, AVFormatContext* of,
@@ -423,13 +494,18 @@
 	}
 	
 	/* Determine whether we are encoding interlaced material or not */
-	if (G.scene->r.mode & (1 << 6)) {
+	if (G.scene->r.mode & R_FIELDS) {
 		fprintf(stderr, "Encoding interlaced video\n");
 		c->flags |= CODEC_FLAG_INTERLACED_DCT;
 		c->flags |= CODEC_FLAG_INTERLACED_ME;
-	}	
-	c->sample_aspect_ratio.num = G.scene->r.xasp;
-	c->sample_aspect_ratio.den = G.scene->r.yasp;
+	}
+
+	/* xasp & yasp got float lately... */
+
+	c->sample_aspect_ratio = av_d2q(
+		((double) G.scene->r.xasp / (double) G.scene->r.yasp), 255);
+
+	set_ffmpeg_properties(c, "video");
 	
 	if (avcodec_open(c, codec) < 0) {
 		error("Couldn't initialize codec");
@@ -474,6 +550,9 @@
 		error("Couldn't find a valid audio codec");
 		return NULL;
 	}
+
+	set_ffmpeg_properties(c, "audio");
+
 	if (avcodec_open(c, codec) < 0) {
 		error("Couldn't initialize audio codec");
 		return NULL;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2008-05-11 20:40:55 UTC (rev 14801)
@@ -3601,7 +3601,16 @@
 	if (sce->r.qtcodecdata) {
 		sce->r.qtcodecdata->cdParms = newdataadr(fd, sce->r.qtcodecdata->cdParms);
 	}
-	
+	if (sce->r.ffcodecdata.properties) {
+		sce->r.ffcodecdata.properties = newdataadr(
+			fd, sce->r.ffcodecdata.properties);
+		if (sce->r.ffcodecdata.properties) { 
+			IDP_DirectLinkProperty(
+				sce->r.ffcodecdata.properties, 
+				(fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+		}
+	}
+
 	link_list(fd, &(sce->markers));
 	link_list(fd, &(sce->transform_spaces));
 	link_list(fd, &(sce->r.layers));

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2008-05-11 20:40:55 UTC (rev 14801)
@@ -1532,6 +1532,9 @@
 			writestruct(wd, DATA, "QuicktimeCodecData", 1, sce->r.qtcodecdata);
 			if (sce->r.qtcodecdata->cdParms) writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms);
 		}
+		if (sce->r.ffcodecdata.properties) {
+			IDP_WriteProperty(sce->r.ffcodecdata.properties, wd);
+		}
 
 		/* writing dynamic list of TimeMarkers to the blend file */
 		for(marker= sce->markers.first; marker; marker= marker->next)

Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h	2008-05-11 20:40:55 UTC (rev 14801)
@@ -98,6 +98,7 @@
 	int rc_buffer_size;
 	int mux_packet_size;
 	int mux_rate;
+	IDProperty *properties;
 } FFMpegCodecData;
 
 

Modified: trunk/blender/source/blender/src/buttons_scene.c
===================================================================
--- trunk/blender/source/blender/src/buttons_scene.c	2008-05-11 20:28:47 UTC (rev 14800)
+++ trunk/blender/source/blender/src/buttons_scene.c	2008-05-11 20:40:55 UTC (rev 14801)
@@ -50,6 +50,7 @@
 #include "BKE_sound.h"
 #include "BKE_packedFile.h"
 #include "BKE_utildefines.h"
+#include "BKE_idprop.h"
 
 #include "BLI_blenlib.h"
 
@@ -109,6 +110,7 @@
 
 #include <ffmpeg/avcodec.h> /* for PIX_FMT_* and CODEC_ID_* */
 #include <ffmpeg/avformat.h>
+#include <ffmpeg/opt.h>
 
 static int ffmpeg_preset_sel = 0;
 
@@ -1833,13 +1835,14 @@
 	static char string[2048];
 	char formatstring[2048];
 
-       strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
+       strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
        sprintf(string, formatstring,
                "", FFMPEG_PRESET_NONE,
                "DVD", FFMPEG_PRESET_DVD,
                "SVCD", FFMPEG_PRESET_SVCD,
                "VCD", FFMPEG_PRESET_VCD,
-               "DV", FFMPEG_PRESET_DV);
+               "DV", FFMPEG_PRESET_DV,
+	       "H264", FFMPEG_PRESET_H264);
        return string;
 }
 
@@ -2274,6 +2277,406 @@
 }
 
 #ifdef WITH_FFMPEG
+
+static void ffmpeg_property_del(void *type, void *prop_)
+{
+	struct IDProperty *prop = (struct IDProperty *) prop_;
+	IDProperty * group;
+	
+	if (!G.scene->r.ffcodecdata.properties) {
+		return;
+	}
+
+	group = IDP_GetPropertyFromGroup(
+		G.scene->r.ffcodecdata.properties, (char*) type);
+	if (group && prop) {
+		IDP_RemFromGroup(group, prop);
+		IDP_FreeProperty(prop);
+		MEM_freeN(prop);
+	}
+	allqueue(REDRAWBUTSSCENE, 0);
+}
+
+static IDProperty * ffmpeg_property_add(
+	char * type, int opt_index, int parent_index)
+{
+	AVCodecContext c;
+	const AVOption * o;
+	const AVOption * parent;
+	IDProperty * group;
+	IDProperty * prop;
+	IDPropertyTemplate val;
+	int idp_type;
+	char name[256];
+
+	avcodec_get_context_defaults(&c);
+
+	o = c.av_class->option + opt_index;
+	parent = c.av_class->option + parent_index;
+
+	if (!G.scene->r.ffcodecdata.properties) {
+		IDPropertyTemplate val;
+
+		G.scene->r.ffcodecdata.properties 
+			= IDP_New(IDP_GROUP, val, "ffmpeg"); 
+	}
+
+	group = IDP_GetPropertyFromGroup(
+		G.scene->r.ffcodecdata.properties, (char*) type);
+	
+	if (!group) {
+		IDPropertyTemplate val;
+		
+		group = IDP_New(IDP_GROUP, val, (char*) type); 
+		IDP_AddToGroup(G.scene->r.ffcodecdata.properties, group);
+	}
+
+	if (parent_index) {
+		sprintf(name, "%s:%s", parent->name, o->name);
+	} else {
+		strcpy(name, o->name);
+	}
+
+	fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n",
+		type, parent_index, opt_index, name);
+
+	prop = IDP_GetPropertyFromGroup(group, name);
+	if (prop) {
+		return prop;
+	}
+
+	switch (o->type) {
+	case FF_OPT_TYPE_INT:
+	case FF_OPT_TYPE_INT64:
+		val.i = o->default_val;
+		idp_type = IDP_INT;
+		break;
+	case FF_OPT_TYPE_DOUBLE:
+	case FF_OPT_TYPE_FLOAT:
+		val.f = o->default_val;
+		idp_type = IDP_FLOAT;
+		break;
+	case FF_OPT_TYPE_STRING:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list