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

Benjamin Larsson banan
Sat May 12 20:26:32 CEST 2007


Hi.

Jason Askew wrote:
> 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

The stuff above doesn't belong to a bug fix patch.

> 
>     /* 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

This looks almost good, but it isn't gcc2.95 safe, move the pfptr
declaration.

>     //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]));
> +    }

Doesn't p->data[0] point to the beginning of the buffer even if linesize
is negative ? If so the only thing to add is the abs.

MvH
Benjamin Larsson




More information about the ffmpeg-devel mailing list