[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43353] trunk/blender: Added Lossless Output option for h264 codec.

Sergey Sharybin sergey.vfx at gmail.com
Fri Jan 13 13:34:26 CET 2012


Revision: 43353
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43353
Author:   nazgul
Date:     2012-01-13 12:34:23 +0000 (Fri, 13 Jan 2012)
Log Message:
-----------
Added Lossless Output option for h264 codec.

This will fix #26943: render image to video problem

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_render.py
    trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h
    trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/makesrna/intern/rna_scene.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_render.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_render.py	2012-01-13 11:36:32 UTC (rev 43352)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_render.py	2012-01-13 12:34:23 UTC (rev 43353)
@@ -522,6 +522,8 @@
         split.prop(rd, "ffmpeg_format")
         if rd.ffmpeg_format in {'AVI', 'QUICKTIME', 'MKV', 'OGG'}:
             split.prop(rd, "ffmpeg_codec")
+        elif rd.ffmpeg_format == 'H264':
+            split.prop(rd, 'ffmpeg_lossless_output')
         else:
             split.label()
 

Modified: trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h	2012-01-13 11:36:32 UTC (rev 43352)
+++ trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h	2012-01-13 12:34:23 UTC (rev 43353)
@@ -74,6 +74,7 @@
 
 extern void ffmpeg_set_preset(struct RenderData *rd, int preset);
 extern void ffmpeg_verify_image_type(struct RenderData *rd, struct ImageFormatData *imf);
+extern void ffmpeg_verify_lossless_format(struct RenderData *rd, struct ImageFormatData *imf);
 
 extern struct IDProperty *ffmpeg_property_add(struct RenderData *Rd, const char *type, int opt_index, int parent_index);
 extern int ffmpeg_property_add_string(struct RenderData *rd, const char *type, const char *str);

Modified: trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2012-01-13 11:36:32 UTC (rev 43352)
+++ trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2012-01-13 12:34:23 UTC (rev 43353)
@@ -1200,6 +1200,56 @@
 	return 1;
 }
 
+static void ffmpeg_set_expert_options(RenderData *rd, int preset)
+{
+	if(rd->ffcodecdata.properties)
+		IDP_FreeProperty(rd->ffcodecdata.properties);
+
+	if(preset == FFMPEG_PRESET_H264) {
+		/*
+		 * All options here are for x264, but must be set via ffmpeg.
+		 * The names are therefore different - Search for "x264 to FFmpeg option mapping"
+		 * to get a list.
+		 */
+
+		/*
+		 * Use CABAC coder. Using "coder:1", which should be equivalent,
+		 * crashes Blender for some reason. Either way - this is no big deal.
+		 */
+		ffmpeg_property_add_string(rd, "video", "coder:vlc");
+
+		/*
+		 * The other options were taken from the libx264-default.preset
+		 * included in the ffmpeg distribution.
+		 */
+		ffmpeg_property_add_string(rd, "video", "flags:loop");
+		ffmpeg_property_add_string(rd, "video", "cmp:chroma");
+		ffmpeg_property_add_string(rd, "video", "partitions:parti4x4");
+		ffmpeg_property_add_string(rd, "video", "partitions:partp8x8");
+		ffmpeg_property_add_string(rd, "video", "partitions:partb8x8");
+		ffmpeg_property_add_string(rd, "video", "me:hex");
+		ffmpeg_property_add_string(rd, "video", "subq:6");
+		ffmpeg_property_add_string(rd, "video", "me_range:16");
+		ffmpeg_property_add_string(rd, "video", "qdiff:4");
+		ffmpeg_property_add_string(rd, "video", "keyint_min:25");
+		ffmpeg_property_add_string(rd, "video", "sc_threshold:40");
+		ffmpeg_property_add_string(rd, "video", "i_qfactor:0.71");
+		ffmpeg_property_add_string(rd, "video", "b_strategy:1");
+		ffmpeg_property_add_string(rd, "video", "bf:3");
+		ffmpeg_property_add_string(rd, "video", "refs:2");
+		ffmpeg_property_add_string(rd, "video", "qcomp:0.6");
+		ffmpeg_property_add_string(rd, "video", "directpred:3");
+		ffmpeg_property_add_string(rd, "video", "trellis:0");
+		ffmpeg_property_add_string(rd, "video", "flags2:wpred");
+		ffmpeg_property_add_string(rd, "video", "flags2:dct8x8");
+		ffmpeg_property_add_string(rd, "video", "flags2:fastpskip");
+		ffmpeg_property_add_string(rd, "video", "wpredp:2");
+
+		if(rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT)
+			ffmpeg_property_add_string(rd, "video", "cqp:0");
+	}
+}
+
 void ffmpeg_set_preset(RenderData *rd, int preset)
 {
 	int isntsc = (rd->frs_sec != 25);
@@ -1267,47 +1317,7 @@
 		rd->ffcodecdata.mux_packet_size = 2048;
 		rd->ffcodecdata.mux_rate = 10080000;
 
-		/*
-		 * All options here are for x264, but must be set via ffmpeg.
-		 * The names are therefore different - Search for "x264 to FFmpeg option mapping"
-		 * to get a list.
-		 */
-		
-		/*
-		 * Use CABAC coder. Using "coder:1", which should be equivalent,
-		 * crashes Blender for some reason. Either way - this is no big deal.
-		 */
-		ffmpeg_property_add_string(rd, "video", "coder:vlc");
-		
-		/* 
-		 * The other options were taken from the libx264-default.preset
-		 * included in the ffmpeg distribution.
-		 */
-		ffmpeg_property_add_string(rd, "video", "flags:loop");
-		ffmpeg_property_add_string(rd, "video", "cmp:chroma");
-		ffmpeg_property_add_string(rd, "video", "partitions:parti4x4");
-		ffmpeg_property_add_string(rd, "video", "partitions:partp8x8");
-		ffmpeg_property_add_string(rd, "video", "partitions:partb8x8");
-		ffmpeg_property_add_string(rd, "video", "me:hex");
-		ffmpeg_property_add_string(rd, "video", "subq:6");
-		ffmpeg_property_add_string(rd, "video", "me_range:16");
-		ffmpeg_property_add_string(rd, "video", "qdiff:4");
-		ffmpeg_property_add_string(rd, "video", "keyint_min:25");
-		ffmpeg_property_add_string(rd, "video", "sc_threshold:40");
-		ffmpeg_property_add_string(rd, "video", "i_qfactor:0.71");
-		ffmpeg_property_add_string(rd, "video", "b_strategy:1");
-		ffmpeg_property_add_string(rd, "video", "bf:3");
-		ffmpeg_property_add_string(rd, "video", "refs:2");
-		ffmpeg_property_add_string(rd, "video", "qcomp:0.6");
-		ffmpeg_property_add_string(rd, "video", "directpred:3");
-		ffmpeg_property_add_string(rd, "video", "trellis:0");
-		ffmpeg_property_add_string(rd, "video", "flags2:wpred");
-		ffmpeg_property_add_string(rd, "video", "flags2:dct8x8");
-		ffmpeg_property_add_string(rd, "video", "flags2:fastpskip");
-		ffmpeg_property_add_string(rd, "video", "wpredp:2");
-		
-		// This makes x264 output lossless. Will be a separate option later.
-		//ffmpeg_property_add_string(rd, "video", "cqp:0");
+		ffmpeg_set_expert_options(rd, preset);
 		break;
 
 	case FFMPEG_PRESET_THEORA:
@@ -1378,4 +1388,11 @@
 	}
 }
 
+void ffmpeg_verify_lossless_format(RenderData *rd, ImageFormatData *imf)
+{
+	if(imf->imtype == R_IMF_IMTYPE_H264) {
+		ffmpeg_set_expert_options(rd, FFMPEG_PRESET_H264);
+	}
+}
+
 #endif

Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h	2012-01-13 11:36:32 UTC (rev 43352)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h	2012-01-13 12:34:23 UTC (rev 43353)
@@ -1380,6 +1380,7 @@
 
 #define FFMPEG_MULTIPLEX_AUDIO  1 /* deprecated, you can choose none as audiocodec now */
 #define FFMPEG_AUTOSPLIT_OUTPUT 2
+#define FFMPEG_LOSSLESS_OUTPUT  4
 
 /* Paint.flags */
 typedef enum {

Modified: trunk/blender/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_scene.c	2012-01-13 11:36:32 UTC (rev 43352)
+++ trunk/blender/source/blender/makesrna/intern/rna_scene.c	2012-01-13 12:34:23 UTC (rev 43353)
@@ -869,6 +869,19 @@
 #endif
 #endif
 
+static void rna_RenderSettings_ffmpegsettings_lossless_output_set(PointerRNA *ptr, int value)
+{
+	RenderData *rd = (RenderData*)ptr->data;
+
+	if (value)
+		rd->ffcodecdata.flags |= FFMPEG_LOSSLESS_OUTPUT;
+	else
+		rd->ffcodecdata.flags &= ~FFMPEG_LOSSLESS_OUTPUT;
+#ifdef WITH_FFMPEG
+	ffmpeg_verify_lossless_format(rd, &rd->im_format);
+#endif
+}
+
 static int rna_RenderSettings_active_layer_index_get(PointerRNA *ptr)
 {
 	RenderData *rd= (RenderData*)ptr->data;
@@ -2996,7 +3009,13 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "ffcodecdata.flags", FFMPEG_AUTOSPLIT_OUTPUT);
 	RNA_def_property_ui_text(prop, "Autosplit Output", "Autosplit output at 2GB boundary");
 	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
-	
+
+	prop= RNA_def_property(srna, "ffmpeg_lossless_output", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "ffcodecdata.flags", FFMPEG_LOSSLESS_OUTPUT);
+	RNA_def_property_boolean_funcs(prop, NULL, "rna_RenderSettings_ffmpegsettings_lossless_output_set");
+	RNA_def_property_ui_text(prop, "Lossless Output", "Use losslecc output for video streams");
+	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
+
 	/* FFMPEG Audio*/
 	prop= RNA_def_property(srna, "ffmpeg_audio_codec", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_bitflag_sdna(prop, NULL, "ffcodecdata.audio_codec");



More information about the Bf-blender-cvs mailing list