[Ffmpeg-devel] I'm giving up

Michael Niedermayer michaelni
Sat Dec 9 02:47:02 CET 2006


Hi

On Fri, Dec 08, 2006 at 11:00:48PM +0100, Panagiotis Issaris wrote:
[...]
> > > > [...]
> > > > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> > > > > index 03c1ae4..ac369eb 100644
> > > > > --- a/libavcodec/Makefile
> > > > > +++ b/libavcodec/Makefile
> > > > > @@ -86,6 +86,7 @@ OBJS-$(CONFIG_GIF_ENCODER)             +
> > > > >  OBJS-$(CONFIG_H261_DECODER)            += h261.o
> > > > >  OBJS-$(CONFIG_H261_ENCODER)            += h261.o
> > > > >  OBJS-$(CONFIG_H264_DECODER)            += h264.o
> > > > > +OBJS-$(CONFIG_H264_ENCODER)            += h264enc.o h264cavlc.o h264dsp.o
> > > > >  OBJS-$(CONFIG_HUFFYUV_DECODER)         += huffyuv.o
> > > > >  OBJS-$(CONFIG_HUFFYUV_ENCODER)         += huffyuv.o
> > > > >  OBJS-$(CONFIG_IDCIN_DECODER)           += idcinvideo.o
> > > > 
> > > > this can be commited if it does not break compilation
> > > By adding a stub for h264cavlc.c or by disabling compilation by default?
> > 
> > by waiting until h264cavlc.c is in svn IMHO
> Ok. Or what would you think about adding the line with only the currently added
> files? 

fine too


[...]
> Index: libavcodec/h264dsp.c
> ===================================================================
> --- libavcodec/h264dsp.c	(revision 0)
> +++ libavcodec/h264dsp.c	(revision 0)
> @@ -0,0 +1,122 @@
> +/*
> + * H.264/MPEG-4 Part 10 (Base profile) encoder.
> + *
> + * DSP functions
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file h264dsp.c
> + * H.264 encoder related DSP utils
> + *
> + */
> +
> +#include "dsputil.h"
> +
> +extern const uint8_t ff_div6[52];
> +extern const uint8_t ff_rem6[52];
> +
> +/**
> + * Transform the provided matrix using the H.264 modified DCT.
> + * @note
> + * we'll always work with transposed input blocks, to avoid having to make a
> + * distinction between C and mmx implementations.
> + *
> + * @param block transposed input block
> + */
> +static void h264_dct_c(DCTELEM block[4][4])
> +{
> +    DCTELEM pieces[4][4];
> +    DCTELEM a, b, c, d;
> +
> +    a = block[0][0]+block[3][0];
> +    c = block[0][0]-block[3][0];
> +    b = block[1][0]+block[2][0];
> +    d = block[1][0]-block[2][0];
> +    pieces[0][0] = a+b;
> +    pieces[2][0] = a-b;
> +    pieces[1][0] = (c<<1)+d;
> +    pieces[3][0] = c-(d<<1);
> +
> +    a = block[0][1]+block[3][1];
> +    c = block[0][1]-block[3][1];
> +    b = block[1][1]+block[2][1];
> +    d = block[1][1]-block[2][1];
> +    pieces[0][1] = a+b;
> +    pieces[2][1] = a-b;
> +    pieces[1][1] = (c<<1)+d;
> +    pieces[3][1] = c-(d<<1);
> +
> +    a = block[0][2]+block[3][2];
> +    b = block[1][2]+block[2][2];
> +    c = block[0][2]-block[3][2];
> +    d = block[1][2]-block[2][2];
> +    pieces[0][2] = a+b;
> +    pieces[2][2] = a-b;
> +    pieces[1][2] = (c<<1)+d;
> +    pieces[3][2] = c-(d<<1);
> +
> +    a = block[0][3]+block[3][3];
> +    b = block[1][3]+block[2][3];
> +    c = block[0][3]-block[3][3];
> +    d = block[1][3]-block[2][3];
> +    pieces[0][3] = a+b;
> +    pieces[1][3] = (c<<1)+d;
> +    pieces[2][3] = a-b;
> +    pieces[3][3] = c-(d<<1);
> +
> +    a = pieces[0][0]+pieces[0][3];
> +    c = pieces[0][0]-pieces[0][3];
> +    b = pieces[0][1]+pieces[0][2];
> +    d = pieces[0][1]-pieces[0][2];
> +    block[0][0] = a+b;
> +    block[2][0] = a-b;
> +    block[1][0] = (c<<1)+d;
> +    block[3][0] = c-(d<<1);
> +
> +    a = pieces[1][0]+pieces[1][3];
> +    c = pieces[1][0]-pieces[1][3];
> +    b = pieces[1][1]+pieces[1][2];
> +    d = pieces[1][1]-pieces[1][2];
> +    block[0][1] = a+b;
> +    block[2][1] = a-b;
> +    block[1][1] = (c<<1)+d;
> +    block[3][1] = c-(d<<1);
> +
> +    a = pieces[2][0]+pieces[2][3];
> +    c = pieces[2][0]-pieces[2][3];
> +    b = pieces[2][1]+pieces[2][2];
> +    d = pieces[2][1]-pieces[2][2];
> +    block[0][2] = a+b;
> +    block[2][2] = a-b;
> +    block[1][2] = (c<<1)+d;
> +    block[3][2] = c-(d<<1);
> +
> +    a = pieces[3][0]+pieces[3][3];
> +    c = pieces[3][0]-pieces[3][3];
> +    b = pieces[3][1]+pieces[3][2];
> +    d = pieces[3][1]-pieces[3][2];
> +    block[0][3] = a+b;
> +    block[2][3] = a-b;
> +    block[1][3] = (c<<1)+d;
> +    block[3][3] = c-(d<<1);
> +}

i assume that a for loop would slow this down significantly? if so a macro would
make that much smaller without speed loss ...


> +
> +void ff_h264dsp_init(DSPContext* c, AVCodecContext *avctx)
> +{
> +    c->h264_dct = h264_dct_c;
> +}

iam fine with adding h264dsp.c

[...]

> Index: libavcodec/h264enc.c
> ===================================================================
> --- libavcodec/h264enc.c	(revision 0)
> +++ libavcodec/h264enc.c	(revision 0)
> @@ -0,0 +1,107 @@
> +/*
> + * H.264 encoder
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +
> +#include "common.h"
> +#include "bitstream.h"
> +#include "mpegvideo.h"
> +#include "h264data.h"
> +
> +/**
> + * Write out the provided data into a NAL unit.
> + * @param nal_ref_idc NAL reference IDC
> + * @param nal_unit_type NAL unit payload type
> + * @param dest the target buffer, dst+1 == src is allowed as a special case
> + * @param destsize the length of the dst array
> + * @param b2 the data which should be escaped
> + * @returns pointer to current position in the output buffer or NULL if an error occured
> + */
> +static uint8_t *h264_write_nal_unit(int nal_ref_idc, int nal_unit_type, uint8_t *dest, int *destsize,
> +                          PutBitContext *b2)
> +{
> +    PutBitContext b;
> +    int i, destpos, rbsplen, escape_count;
> +    uint8_t *rbsp;
> +
> +    if (nal_unit_type != NAL_END_STREAM)
> +        put_bits(b2,1,1); // rbsp_stop_bit
> +
> +    // Align b2 on a byte boundary
> +    align_put_bits(b2);
> +    rbsplen = put_bits_count(b2)/8;
> +    flush_put_bits(b2);
> +    rbsp = b2->buf;
> +
> +    init_put_bits(&b,dest,*destsize);
> +
> +    put_bits(&b,16,0);
> +    put_bits(&b,16,0x01);
> +
> +    put_bits(&b,1,0); // forbidden zero bit
> +    put_bits(&b,2,nal_ref_idc); // nal_ref_idc
> +    put_bits(&b,5,nal_unit_type); // nal_unit_type
> +
> +    flush_put_bits(&b);
> +
> +    destpos = 5;
> +    escape_count= 0;
> +
> +    for (i=0; i<rbsplen; i+=2)
> +    {
> +        if (rbsp[i]) continue;
> +        if (i>0 && rbsp[i-1]==0)
> +            i--;
> +        if (i+2<rbsplen && rbsp[i+1]==0 && rbsp[i+2]<=3)
> +        {
> +            escape_count++;
> +            i+=2;
> +        }
> +    }
> +
> +    if(escape_count==0)
> +    {
> +        if(dest+destpos != rbsp)
> +        {
> +            memcpy(dest+destpos, rbsp, rbsplen);
> +            *destsize -= (rbsplen+destpos);
> +        }
> +        return dest+rbsplen+destpos;
> +    }
> +
> +    if(rbsplen + escape_count + 1> *destsize)
> +    {
> +        av_log(NULL, AV_LOG_ERROR, "Destination buffer too small!\n");
> +        return NULL;
> +    }
> +
> +    // this should be damn rare (hopefully)
> +    for (i = 0 ; i < rbsplen ; i++)
> +    {
> +        if (i + 2 < rbsplen && (rbsp[i] == 0 && rbsp[i+1] == 0 && rbsp[i+2] < 4))
> +        {
> +            dest[destpos++] = rbsp[i++];
> +            dest[destpos++] = rbsp[i];
> +            dest[destpos++] = 0x03; // emulation prevention byte
> +        }
> +        else
> +            dest[destpos++] = rbsp[i];
> +    }
> +    *destsize -= destpos;
> +    return dest+destpos;
> +}

fine too

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you really think that XML is the answer, then you definitly missunderstood
the question -- Attila Kinali




More information about the ffmpeg-devel mailing list