2 * MPEG4 Video frame extraction
3 * Copyright (c) 2003 Fabrice Bellard.
4 * Copyright (c) 2003 Michael Niedermayer.
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "mpegvideo.h"
27 /* XXX: make it use less memory */
28 static int av_mpeg4_decode_header(AVCodecParserContext *s1,
29 AVCodecContext *avctx,
30 const uint8_t *buf, int buf_size)
32 ParseContext1 *pc = s1->priv_data;
33 MpegEncContext *s = pc->enc;
34 GetBitContext gb1, *gb = &gb1;
38 s->current_picture_ptr = &s->current_picture;
40 if (avctx->extradata_size && pc->first_picture){
41 init_get_bits(gb, avctx->extradata, avctx->extradata_size*8);
42 ret = ff_mpeg4_decode_picture_header(s, gb);
45 init_get_bits(gb, buf, 8 * buf_size);
46 ret = ff_mpeg4_decode_picture_header(s, gb);
48 avcodec_set_dimensions(avctx, s->width, s->height);
50 s1->pict_type= s->pict_type;
51 pc->first_picture = 0;
55 static int mpeg4video_parse_init(AVCodecParserContext *s)
57 ParseContext1 *pc = s->priv_data;
59 pc->enc = av_mallocz(sizeof(MpegEncContext));
62 pc->first_picture = 1;
66 static int mpeg4video_parse(AVCodecParserContext *s,
67 AVCodecContext *avctx,
68 uint8_t **poutbuf, int *poutbuf_size,
69 const uint8_t *buf, int buf_size)
71 ParseContext *pc = s->priv_data;
74 if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){
77 next= ff_mpeg4_find_frame_end(pc, buf, buf_size);
79 if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) {
85 av_mpeg4_decode_header(s, avctx, buf, buf_size);
87 *poutbuf = (uint8_t *)buf;
88 *poutbuf_size = buf_size;
93 AVCodecParser mpeg4video_parser = {
95 sizeof(ParseContext1),
96 mpeg4video_parse_init,