[FFmpeg-devel] [PATCH] h264 bitstream filter

Michael Niedermayer michaelni
Thu Aug 30 15:49:42 CEST 2007


Hi

On Thu, Aug 30, 2007 at 02:09:19PM +0200, Benoit Fouet wrote:
> Benoit Fouet wrote:
> > M?ns Rullg?rd wrote:
> >   
> >> Benoit Fouet wrote:
> >>     
> >>> i also think that i can "construct" the sps/pps NALU only once, instead
> >>> of doing it every time, but i don't know how to do it, as bsfs don't
> >>> have a cleanup function...
> >>>     
> >>>       
> >> Well, prepending 00 00 00 01 isn't all that much work...
> >>
> >>   
> >>     
> >
> > i was more thinking of (re)allocation, copying...
> > i think i'll try to use private data allocated by the bsf, as it will be
> > released by av_bitstream_filter_close
> > i'll come back soon with an updated patch, to illustrate.
> >
> >   
> 
> here it is...

in addition to baptistes comments ...

[...]
> +            /* sps unit(s) */
> +            unit_nb = *extradata++ & 0x1f;
> +            while (unit_nb--) {
> +                unit_size = AV_RB16(extradata);
> +                priv_data_size += unit_size+4;
> +                if (extradata+2+unit_size > avctx->extradata+avctx->extradata_size) {
> +                    av_free(out);
> +                    priv_data_size = 0;
> +                    return -1;
> +                }
> +                out = av_realloc(out, priv_data_size);
> +                memcpy(out+priv_data_size-unit_size-4, nalu_header, 4);
> +                memcpy(out+priv_data_size-unit_size,   extradata+2, unit_size);
> +                extradata += 2+unit_size;
> +            }
> +
> +            /* pps unit(s) */
> +            unit_nb = *extradata++;
> +            while (unit_nb--) {
> +                unit_size = AV_RB16(extradata);
> +                priv_data_size += unit_size+4;
> +                if (extradata+2+unit_size > avctx->extradata+avctx->extradata_size) {
> +                    av_free(out);
> +                    priv_data_size = 0;
> +                    return -1;
> +                }
> +                out = av_realloc(out, priv_data_size);
> +                memcpy(out+priv_data_size-unit_size-4, nalu_header, 4);
> +                memcpy(out+priv_data_size-unit_size,   extradata+2, unit_size);
> +                extradata += 2+unit_size;

code duplication

[...]

> +            /* change nal unit header */
> +            (*poutbuf)[priv_data_size  ] = 0;
> +            (*poutbuf)[priv_data_size+1] = 0;
> +            (*poutbuf)[priv_data_size+2] = 0;
> +            (*poutbuf)[priv_data_size+3] = 1;
> +        } else if (unit_type == 6 /* SEI */ || unit_type == 9 /* AUD */) {
> +            /* sps and pps have to be appended to NAL unit */
> +            *poutbuf = av_malloc(priv_data_size+buf_size);
> +            *poutbuf_size = priv_data_size + buf_size;
> +            memcpy(*poutbuf, buf, buf_size);
> +            memcpy(*poutbuf+buf_size, bsfc->priv_data, priv_data_size);
> +
> +            /* change nal unit header */
> +            (*poutbuf)[0] = 0;
> +            (*poutbuf)[1] = 0;
> +            (*poutbuf)[2] = 0;
> +            (*poutbuf)[3] = 1;
> +        } else {
> +            *poutbuf = av_malloc(buf_size);
> +            *poutbuf_size = buf_size;
> +            memcpy(*poutbuf, buf, buf_size);
> +
> +            /* change nal unit header */
> +            (*poutbuf)[0] = 0;
> +            (*poutbuf)[1] = 0;
> +            (*poutbuf)[2] = 0;
> +            (*poutbuf)[3] = 1;

code duplication


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

When the tyrant has disposed of foreign enemies by conquest or treaty, and
there is nothing more to fear from them, then he is always stirring up
some war or other, in order that the people may require a leader. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070830/034dd0f4/attachment.pgp>



More information about the ffmpeg-devel mailing list