[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15384] trunk/blender/source/blender/imbuf /intern: == FFMPEG / ImBuf ==

Peter Schlaile peter at schlaile.de
Sun Jun 29 17:11:35 CEST 2008


Revision: 15384
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15384
Author:   schlaile
Date:     2008-06-29 17:11:35 +0200 (Sun, 29 Jun 2008)

Log Message:
-----------
== FFMPEG / ImBuf ==

Fixed deinterlacing (inplace deinterlacing didn't work out properly...).

[#14672] Sequencer: deinterlace filter artifacts

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/IMB_anim.h
    trunk/blender/source/blender/imbuf/intern/anim.c

Modified: trunk/blender/source/blender/imbuf/intern/IMB_anim.h
===================================================================
--- trunk/blender/source/blender/imbuf/intern/IMB_anim.h	2008-06-29 12:53:42 UTC (rev 15383)
+++ trunk/blender/source/blender/imbuf/intern/IMB_anim.h	2008-06-29 15:11:35 UTC (rev 15384)
@@ -183,8 +183,9 @@
 	AVFormatContext *pFormatCtx;
 	AVCodecContext *pCodecCtx;
 	AVCodec *pCodec;
+	AVFrame *pFrame;
 	AVFrame *pFrameRGB;
-	AVFrame *pFrame;
+	AVFrame *pFrameDeinterlaced;
 	struct SwsContext *img_convert_ctx;
 	int videoStream;
 #endif

Modified: trunk/blender/source/blender/imbuf/intern/anim.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/anim.c	2008-06-29 12:53:42 UTC (rev 15383)
+++ trunk/blender/source/blender/imbuf/intern/anim.c	2008-06-29 15:11:35 UTC (rev 15384)
@@ -600,6 +600,7 @@
 	anim->videoStream = videoStream;
 
 	anim->pFrame = avcodec_alloc_frame();
+	anim->pFrameDeinterlaced = avcodec_alloc_frame();
 	anim->pFrameRGB = avcodec_alloc_frame();
 
 	if (avpicture_get_size(PIX_FMT_BGR32, anim->x, anim->y)
@@ -609,10 +610,20 @@
 		avcodec_close(anim->pCodecCtx);
 		av_close_input_file(anim->pFormatCtx);
 		av_free(anim->pFrameRGB);
+		av_free(anim->pFrameDeinterlaced);
 		av_free(anim->pFrame);
 		return -1;
 	}
 
+	if (anim->ib_flags & IB_animdeinterlace) {
+		avpicture_fill((AVPicture*) anim->pFrameDeinterlaced, 
+			       MEM_callocN(avpicture_get_size(
+						   anim->pCodecCtx->pix_fmt,
+						   anim->x, anim->y), 
+					   "ffmpeg deinterlace"), 
+			       anim->pCodecCtx->pix_fmt, anim->x, anim->y);
+	}
+
 	if (pCodecCtx->has_b_frames) {
 		anim->preseek = 25; /* FIXME: detect gopsize ... */
 	} else {
@@ -644,7 +655,7 @@
 
 	ibuf = IMB_allocImBuf(anim->x, anim->y, 24, IB_rect, 0);
 
-	avpicture_fill((AVPicture *)anim->pFrameRGB, 
+	avpicture_fill((AVPicture*) anim->pFrameRGB, 
 		       (unsigned char*) ibuf->rect, 
 		       PIX_FMT_BGR32, anim->x, anim->y);
 
@@ -723,15 +734,29 @@
 			} 
 
 			if(frameFinished && pos_found == 1) {
+				AVFrame * input = anim->pFrame;
+
+				/* This means the data wasnt read properly, 
+				   this check stops crashing */
+				if (input->data[0]==0 && input->data[1]==0 
+				    && input->data[2]==0 && input->data[3]==0){
+					av_free_packet(&packet);
+					break;
+				}
+
 				if (anim->ib_flags & IB_animdeinterlace) {
 					if (avpicture_deinterlace(
+						    (AVPicture*) 
+						    anim->pFrameDeinterlaced,
+						    (const AVPicture*)
 						    anim->pFrame,
-						    anim->pFrame,
 						    anim->pCodecCtx->pix_fmt,
 						    anim->pCodecCtx->width,
 						    anim->pCodecCtx->height)
 					    < 0) {
 						filter_y = 1;
+					} else {
+						input = anim->pFrameDeinterlaced;
 					}
 				}
 
@@ -748,8 +773,8 @@
 					unsigned char* top;
 
 					sws_scale(anim->img_convert_ctx,
-						  anim->pFrame->data,
-						  anim->pFrame->linesize,
+						  input->data,
+						  input->linesize,
 						  0,
 						  anim->pCodecCtx->height,
 						  dst2,
@@ -806,27 +831,25 @@
 					int i;
 					unsigned char* r;
 					
-					/* This means the data wasnt read properly, this check stops crashing */
-					if (anim->pFrame->data[0]!=0 || anim->pFrame->data[1]!=0 || anim->pFrame->data[2]!=0 || anim->pFrame->data[3]!=0) {
 						
-						sws_scale(anim->img_convert_ctx,
-							  anim->pFrame->data,
-							  anim->pFrame->linesize,
-							  0,
-							  anim->pCodecCtx->height,
-							  dst2,
-							  dstStride2);
+					sws_scale(anim->img_convert_ctx,
+						  input->data,
+						  input->linesize,
+						  0,
+						  anim->pCodecCtx->height,
+						  dst2,
+						  dstStride2);
 					
-						/* workaround: sws_scale 
-						   sets alpha = 0... */
+					/* workaround: sws_scale 
+					   sets alpha = 0... */
 					
-						r = (unsigned char*) ibuf->rect;
-	
-						for (i = 0; i < ibuf->x * ibuf->y;i++){
-							r[3] = 0xff;
-							r+=4;
-						}
+					r = (unsigned char*) ibuf->rect;
+					
+					for (i = 0; i < ibuf->x * ibuf->y;i++){
+						r[3] = 0xff;
+						r+=4;
 					}
+					
 					av_free_packet(&packet);
 					break;
 				}
@@ -851,6 +874,11 @@
 		av_close_input_file(anim->pFormatCtx);
 		av_free(anim->pFrameRGB);
 		av_free(anim->pFrame);
+
+		if (anim->ib_flags & IB_animdeinterlace) {
+			MEM_freeN(anim->pFrameDeinterlaced->data[0]);
+		}
+		av_free(anim->pFrameDeinterlaced);
 		sws_freeContext(anim->img_convert_ctx);
 	}
 	anim->duration = 0;





More information about the Bf-blender-cvs mailing list