[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43349] trunk/blender/source/blender: Fix #29824: Error writing frame if 3D scene starts after first frame of animation and output is H264

Sergey Sharybin sergey.vfx at gmail.com
Fri Jan 13 10:20:21 CET 2012


Revision: 43349
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43349
Author:   nazgul
Date:     2012-01-13 09:20:13 +0000 (Fri, 13 Jan 2012)
Log Message:
-----------
Fix #29824: Error writing frame if 3D scene starts after first frame of animation and output is H264

Issue was caused by incorrectly set PTS value frames came form Scene strip renderer.
This value used to be calculated from RenderData current and start frame which
lead to non-uniformuly counting which totally confuses encoder.

Switch append_avi and append_ffmpeg to use current frame from rendering scene
(which was already passing to this functions and was used mostly for logging)
and start frame of rendering scene (it's new parameter added). This allowed to
calculate correct PTS value easily and get rid of global static sframe variable
in writeavi.c file.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_writeavi.h
    trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h
    trunk/blender/source/blender/blenkernel/BKE_writeframeserver.h
    trunk/blender/source/blender/blenkernel/intern/writeavi.c
    trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
    trunk/blender/source/blender/blenkernel/intern/writeframeserver.c
    trunk/blender/source/blender/editors/render/render_opengl.c
    trunk/blender/source/blender/editors/screen/screendump.c
    trunk/blender/source/blender/render/intern/source/pipeline.c

Modified: trunk/blender/source/blender/blenkernel/BKE_writeavi.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_writeavi.h	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/blenkernel/BKE_writeavi.h	2012-01-13 09:20:13 UTC (rev 43349)
@@ -44,7 +44,8 @@
 
 typedef struct bMovieHandle {
 	int (*start_movie)(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports);
-	int (*append_movie)(struct RenderData *rd, int frame, int *pixels, int rectx, int recty, struct ReportList *reports);
+	int (*append_movie)(struct RenderData *rd, int start_frame, int frame, int *pixels,
+	                    int rectx, int recty, struct ReportList *reports);
 	void (*end_movie)(void);
 	int (*get_next_frame)(struct RenderData *rd, struct ReportList *reports); /* optional */
 	void (*get_movie_path)(char *string, struct RenderData *rd); /* optional */

Modified: trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/blenkernel/BKE_writeffmpeg.h	2012-01-13 09:20:13 UTC (rev 43349)
@@ -68,7 +68,8 @@
 
 extern int start_ffmpeg(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports);
 extern void end_ffmpeg(void);
-extern int append_ffmpeg(struct RenderData *rd, int frame, int *pixels, int rectx, int recty, struct ReportList *reports);
+extern int append_ffmpeg(struct RenderData *rd, int start_frame, int frame, int *pixels,
+                         int rectx, int recty, struct ReportList *reports);
 void filepath_ffmpeg(char* string, struct RenderData* rd);
 
 extern void ffmpeg_set_preset(struct RenderData *rd, int preset);

Modified: trunk/blender/source/blender/blenkernel/BKE_writeframeserver.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_writeframeserver.h	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/blenkernel/BKE_writeframeserver.h	2012-01-13 09:20:13 UTC (rev 43349)
@@ -42,7 +42,8 @@
 
 extern int start_frameserver(struct Scene *scene, struct RenderData *rd, int rectx, int recty, struct ReportList *reports);
 extern void end_frameserver(void);
-extern int append_frameserver(struct RenderData *rd, int frame, int *pixels, int rectx, int recty, struct ReportList *reports);
+extern int append_frameserver(struct RenderData *rd, int start_frame, int frame, int *pixels,
+                              int rectx, int recty, struct ReportList *reports);
 extern int frameserver_loop(struct RenderData *rd, struct ReportList *reports);
 
 #ifdef __cplusplus

Modified: trunk/blender/source/blender/blenkernel/intern/writeavi.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeavi.c	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/blenkernel/intern/writeavi.c	2012-01-13 09:20:13 UTC (rev 43349)
@@ -52,7 +52,8 @@
 /* callbacks */
 static int start_avi(Scene *scene, RenderData *rd, int rectx, int recty, ReportList *reports);
 static void end_avi(void);
-static int append_avi(RenderData *rd, int frame, int *pixels, int rectx, int recty, ReportList *reports);
+static int append_avi(RenderData *rd, int start_frame, int frame, int *pixels,
+                      int rectx, int recty, ReportList *reports);
 static void filepath_avi(char *string, RenderData *rd);
 
 /* ********************** general blender movie support ***************************** */
@@ -121,7 +122,6 @@
 
 
 static AviMovie *avi=NULL;
-static int sframe;
 
 static void filepath_avi (char *string, RenderData *rd)
 {
@@ -150,7 +150,6 @@
 	
 	filepath_avi(name, rd);
 
-	sframe = (rd->sfra);
 	x = rectx;
 	y = recty;
 
@@ -183,7 +182,8 @@
 	return 1;
 }
 
-static int append_avi(RenderData *UNUSED(rd), int frame, int *pixels, int rectx, int recty, ReportList *UNUSED(reports))
+static int append_avi(RenderData *UNUSED(rd), int start_frame, int frame, int *pixels,
+                      int rectx, int recty, ReportList *UNUSED(reports))
 {
 	unsigned int *rt1, *rt2, *rectot;
 	int x, y;
@@ -212,8 +212,8 @@
 		}
 	}
 	
-	AVI_write_frame (avi, (frame-sframe), AVI_FORMAT_RGB32, rectot, rectx*recty*4);
-//	printf ("added frame %3d (frame %3d in avi): ", frame, frame-sframe);
+	AVI_write_frame (avi, (frame-start_frame), AVI_FORMAT_RGB32, rectot, rectx*recty*4);
+//	printf ("added frame %3d (frame %3d in avi): ", frame, frame-start_frame);
 
 	return 1;
 }

Modified: trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/blenkernel/intern/writeffmpeg.c	2012-01-13 09:20:13 UTC (rev 43349)
@@ -236,13 +236,13 @@
 }
 
 /* Write a frame to the output file */
-static int write_video_frame(RenderData *rd, AVFrame* frame, ReportList *reports)
+static int write_video_frame(RenderData *rd, int cfra, AVFrame* frame, ReportList *reports)
 {
 	int outsize = 0;
 	int ret, success= 1;
 	AVCodecContext* c = video_stream->codec;
 
-	frame->pts = rd->cfra - rd->sfra;
+	frame->pts = cfra;
 
 	if (rd->mode & R_FIELDS) {
 		frame->top_field_first = ((rd->mode & R_ODDFIELD) != 0);
@@ -918,7 +918,7 @@
 }
 #endif
 
-int append_ffmpeg(RenderData *rd, int frame, int *pixels, int rectx, int recty, ReportList *reports) 
+int append_ffmpeg(RenderData *rd, int start_frame, int frame, int *pixels, int rectx, int recty, ReportList *reports)
 {
 	AVFrame* avframe;
 	int success = 1;
@@ -933,7 +933,7 @@
 	if(video_stream)
 	{
 		avframe= generate_video_frame((unsigned char*) pixels, reports);
-		success= (avframe && write_video_frame(rd, avframe, reports));
+		success= (avframe && write_video_frame(rd, frame - start_frame, avframe, reports));
 
 		if (ffmpeg_autosplit) {
 			if (avio_tell(outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) {

Modified: trunk/blender/source/blender/blenkernel/intern/writeframeserver.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/writeframeserver.c	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/blenkernel/intern/writeframeserver.c	2012-01-13 09:20:13 UTC (rev 43349)
@@ -362,7 +362,8 @@
 	connsock = -1;
 }
 
-int append_frameserver(RenderData *UNUSED(rd), int frame, int *pixels, int rectx, int recty, ReportList *UNUSED(reports))
+int append_frameserver(RenderData *UNUSED(rd), int UNUSED(start_frame), int frame, int *pixels,
+                       int rectx, int recty, ReportList *UNUSED(reports))
 {
 	fprintf(stderr, "Serving frame: %d\n", frame);
 	if (write_ppm) {

Modified: trunk/blender/source/blender/editors/render/render_opengl.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_opengl.c	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/editors/render/render_opengl.c	2012-01-13 09:20:13 UTC (rev 43349)
@@ -488,7 +488,8 @@
 		}
 
 		if(BKE_imtype_is_movie(scene->r.im_format.imtype)) {
-			ok= oglrender->mh->append_movie(&scene->r, CFRA, (int*)ibuf->rect, oglrender->sizex, oglrender->sizey, oglrender->reports);
+			ok= oglrender->mh->append_movie(&scene->r, SFRA, CFRA, (int*)ibuf->rect,
+			                                oglrender->sizex, oglrender->sizey, oglrender->reports);
 			if(ok) {
 				printf("Append frame %d", scene->r.cfra);
 				BKE_reportf(op->reports, RPT_INFO, "Appended frame: %d", scene->r.cfra);

Modified: trunk/blender/source/blender/editors/screen/screendump.c
===================================================================
--- trunk/blender/source/blender/editors/screen/screendump.c	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/editors/screen/screendump.c	2012-01-13 09:20:13 UTC (rev 43349)
@@ -302,7 +302,9 @@
 		if(sj->dumprect) {
 			
 			if(mh) {
-				if(mh->append_movie(&rd, rd.cfra, (int *)sj->dumprect, sj->dumpsx, sj->dumpsy, &sj->reports)) {
+				if(mh->append_movie(&rd, rd.sfra, rd.cfra, (int *)sj->dumprect,
+				                    sj->dumpsx, sj->dumpsy, &sj->reports))
+				{
 					BKE_reportf(&sj->reports, RPT_INFO, "Appended frame: %d", rd.cfra);
 					printf("Appended frame %d\n", rd.cfra);
 				} else

Modified: trunk/blender/source/blender/render/intern/source/pipeline.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/pipeline.c	2012-01-13 08:58:12 UTC (rev 43348)
+++ trunk/blender/source/blender/render/intern/source/pipeline.c	2012-01-13 09:20:13 UTC (rev 43349)
@@ -2047,7 +2047,8 @@
 			dofree = 1;
 		}
 
-		ok= mh->append_movie(&re->r, scene->r.cfra, (int *)rect32, rres.rectx, rres.recty, re->reports);
+		ok= mh->append_movie(&re->r, scene->r.sfra, scene->r.cfra, (int *)rect32,
+		                     rres.rectx, rres.recty, re->reports);
 		if(dofree) {
 			MEM_freeN(rect32);
 		}



More information about the Bf-blender-cvs mailing list