[FFmpeg-devel] [PATCH] h264 bitstream filter
Benoit Fouet
benoit.fouet
Thu Aug 30 17:12:09 CEST 2007
Michael Niedermayer wrote:
> 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 ...
>
> [...]
>
i hope they're fixed and that the way i used is not too ugly...
>> + /* 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
>
> [...]
>
>
fixed
>> + /* 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
>
>
> [...]
>
>
fixed
updated patch attached
--
Ben
Purple Labs S.A.
www.purplelabs.com
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: h264_bsf.diff
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070830/e0f9bab8/attachment.txt>
More information about the ffmpeg-devel
mailing list