[FFmpeg-devel] flashsvenc.c path - fix ability to handle negative linesize

Jason Askew jason.askew
Fri May 11 20:13:31 CEST 2007


Michael:

>
> none of this has any relation to a negative linesize fix
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Here's a much cleaner diff.

--- flashsvenc_c.c	Fri May 11 13:01:07 2007
+++ flashsvenc.c	Fri May 11 13:09:22 2007
@@ -27,6 +27,7 @@
  * Flash Screen Video encoder
  * @author Alex Beregszaszi
  * @author Benjamin Larsson
+ * @author Jason Askew - jason dot askew at gmail dot com
  */

 /* Bitstream description
@@ -49,6 +50,15 @@
  * block sizes should give a better result than to just use a fixed size.
  */

+/*
+ * Jason Askew (2007/5/10):
+ * Added support for instances where linesize[0] is negative
+ *
+ * Basicaly changed the previous frame buffer pointer to behave the
same as the current frame pointer,
+ * i.e., move from the last row to first row when linesize is negative
+ * Also used abs(linesize) value when allocating memory
+ */
+
 /* TODO:
  * Don't reencode the frame in brute force mode if the frame is a
dupe. Speed up.
  * Make the difference check faster.
@@ -241,7 +251,7 @@ static int flashsv_encode_frame(AVCodecC

     /* First frame needs to be a keyframe */
     if (avctx->frame_number == 0) {
-        s->previous_frame = av_mallocz(p->linesize[0]*s->image_height);
+        s->previous_frame = av_mallocz(abs(p->linesize[0])*s->image_height);
         if (!s->previous_frame) {
             av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n");
             return -1;
@@ -297,10 +307,22 @@ static int flashsv_encode_frame(AVCodecC
         return -1;
     }

-    res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16,
s->previous_frame, &I_frame);
+	uint8_t *pfptr;
+	pfptr = s->previous_frame;
+	//if linesize is negative, prep pointer to match upside down ptr
movement of data[0]
+	if(p->linesize[0] < 0) {
+		pfptr = pfptr - ((s->image_height-1) * p->linesize[0]);
+	}
+
+    res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16,
pfptr, &I_frame);
 #endif
     //save the current frame
-    memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]);
+	if(p->linesize[0] > 0) {
+	    memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]);
+	} else {
+	    //with negative linesize, ptr goes to last row of frame, need to
calc pointer to begin of frame mem
+		memcpy(s->previous_frame, p->data[0] + p->linesize[0] *
(s->image_height-1), s->image_height*abs(p->linesize[0]));
+	}

     //mark the frame type so the muxer can mux it correctly
     if (I_frame) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: flashsvenc.c.diff
Type: application/octet-stream
Size: 2328 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070511/0aa2d159/attachment.obj>



More information about the ffmpeg-devel mailing list