[FFmpeg-devel] [PATCH] png parser
Peter Holik
peter
Thu Jun 4 10:40:55 CEST 2009
> On Mon, Jun 01, 2009 at 12:27:52PM +0200, Peter Holik wrote:
>> Hi!
>>
>> I've now reworked my patch to really parse a png for end of frame.
>>
>> Now you can filter out png's of any stream like
>>
>> cat garbage a.png garbage b.png garbage | ffmpeg -f image2pipe -vcodec png -i - c%d.png
>>
>> cu Peter
>> Makefile | 1
>> allcodecs.c | 1
>> png_parser.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 126 insertions(+)
>> 63f7cd1bb826726f1d2a9e7254410cd7ec98a81c png-parser.patch
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index 14ef9f4..189231b 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -411,6 +411,7 @@ OBJS-$(CONFIG_MLP_PARSER) += mlp_parser.o mlp.o
>> OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o h263.o mpeg12data.o mpegvideo.o
>> error_resilience.o
>> OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o mpegaudiodecheader.o
>> mpegaudiodata.o
>> OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o mpeg12.o mpeg12data.o mpegvideo.o
>> error_resilience.o
>> +OBJS-$(CONFIG_PNG_PARSER) += png_parser.o
>> OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o
>> OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o
>> OBJS-$(CONFIG_VP3_PARSER) += vp3_parser.o
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index e8d5d27..362021f 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -334,6 +334,7 @@ void avcodec_register_all(void)
>> REGISTER_PARSER (MPEG4VIDEO, mpeg4video);
>> REGISTER_PARSER (MPEGAUDIO, mpegaudio);
>> REGISTER_PARSER (MPEGVIDEO, mpegvideo);
>> + REGISTER_PARSER (PNG, png);
>> REGISTER_PARSER (PNM, pnm);
>> REGISTER_PARSER (VC1, vc1);
>> REGISTER_PARSER (VP3, vp3);
>> diff --git a/libavcodec/png_parser.c b/libavcodec/png_parser.c
>> new file mode 100644
>> index 0000000..64f2356
>> --- /dev/null
>> +++ b/libavcodec/png_parser.c
>> @@ -0,0 +1,124 @@
>> +/*
>> + * PNG parser
>> + * Copyright (c) 2009 Peter Holik
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * 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 libavcodec/png_parser.c
>> + * PNG parser
>> + */
>> +
>> +#include "parser.h"
>> +#include "bytestream.h"
>> +#include "png.h"
>> +
>> +static int png_parse(AVCodecParserContext *s, AVCodecContext *avctx,
>> + const uint8_t **poutbuf, int *poutbuf_size,
>> + const uint8_t *buf, int buf_size)
>> +{
>> + ParseContext *pc = s->priv_data;
>> + uint8_t *bytestream;
>> + uint8_t *bytestream_start;
>> + uint8_t *bytestream_end;
>> +
>> + /* EOF considered as end of frame */
>> + if (buf_size == 0)
>> + goto flush;
>> +
>> + *poutbuf = NULL;
>> + *poutbuf_size = 0;
>> +
>> + /* first add new buffer to parsebuffer */
>> + bytestream_start = av_fast_realloc(pc->buffer, &pc->buffer_size,
>> + pc->index + buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
>> + if(!bytestream_start)
>> + goto fail;
>> + pc->buffer = bytestream_start;
>> + memcpy(&pc->buffer[pc->index], buf, buf_size);
>
> mandatory copying is unacceptable
> the case where each input is exactly a png frame for example should
> be free of any timeconsuming operation
>
> maybe ff_combine_frame() would be usefull
But ff_combine_frame also does memcpy, so there is no difference to my approach.
cu Peter
More information about the ffmpeg-devel
mailing list