OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2009 Google Inc. | 2 * Copyright (c) 2009 Google Inc. |
3 * | 3 * |
4 * This file is part of FFmpeg. | 4 * This file is part of FFmpeg. |
5 * | 5 * |
6 * FFmpeg is free software; you can redistribute it and/or | 6 * FFmpeg is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2.1 of the License, or (at your option) any later version. | 9 * version 2.1 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 | 82 |
83 *poutbuf_size = outbuf_idx; | 83 *poutbuf_size = outbuf_idx; |
84 return 0; | 84 return 0; |
85 } | 85 } |
86 | 86 |
87 AVBitStreamFilter mpeg4video_es_bsf = { | 87 AVBitStreamFilter mpeg4video_es_bsf = { |
88 "mpeg4video_es", | 88 "mpeg4video_es", |
89 0, | 89 0, |
90 mpeg4video_es_filter, | 90 mpeg4video_es_filter, |
91 }; | 91 }; |
92 /* | |
Lei Zhang
2010/03/19 00:38:33
Oh this is bad merge!
| |
93 * Copyright (c) 2009 Google Inc. | |
94 * | |
95 * This file is part of FFmpeg. | |
96 * | |
97 * FFmpeg is free software; you can redistribute it and/or | |
98 * modify it under the terms of the GNU Lesser General Public | |
99 * License as published by the Free Software Foundation; either | |
100 * version 2.1 of the License, or (at your option) any later version. | |
101 * | |
102 * FFmpeg is distributed in the hope that it will be useful, | |
103 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
104 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
105 * Lesser General Public License for more details. | |
106 * | |
107 * You should have received a copy of the GNU Lesser General Public | |
108 * License along with FFmpeg; if not, write to the Free Software | |
109 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
110 */ | |
111 | |
112 #include "avcodec.h" | |
113 #include "mpegvideo.h" | |
114 | |
115 static int mpeg4video_es_filter(AVBitStreamFilterContext *bsfc, | |
116 AVCodecContext *avctx, const char *args, | |
117 uint8_t **poutbuf, int *poutbuf_size, | |
118 const uint8_t *buf, int buf_size, | |
119 int keyframe) { | |
120 AVCodecParserContext *cpc; | |
121 ParseContext1 *pc; | |
122 MpegEncContext *s; | |
123 int first_picture; | |
124 int ret; | |
125 uint8_t *frame_data; | |
126 int frame_size; | |
127 int outbuf_idx = 0; | |
128 int count = 0; | |
129 | |
130 if (avctx->codec_id != CODEC_ID_MPEG4) { | |
131 av_log(NULL, AV_LOG_ERROR, "Codec is not MPEG4\n"); | |
132 return -1; | |
133 } | |
134 | |
135 if (!bsfc->parser) { | |
136 bsfc->parser = av_parser_init(CODEC_ID_MPEG4); | |
137 } | |
138 cpc = bsfc->parser; | |
139 pc = cpc->priv_data; | |
140 s = pc->enc; | |
141 | |
142 *poutbuf = NULL; | |
143 *poutbuf_size = 0; | |
144 while (buf_size > 0) { | |
145 first_picture = pc->first_picture; | |
146 ret = cpc->parser->parser_parse(cpc, avctx, &frame_data, &frame_size, bu f, buf_size); | |
147 | |
148 if (ret < 0) | |
149 return ret; | |
150 | |
151 buf_size -= ret; | |
152 buf += ret; | |
153 | |
154 // If the first picture is decoded, encode the header. | |
155 if (first_picture && !pc->first_picture) { | |
156 assert(!*poutbuf); | |
157 *poutbuf = av_malloc(1024); | |
158 *poutbuf_size = 1024; | |
159 init_put_bits(&s->pb, *poutbuf, 1024); | |
160 mpeg4_encode_visual_object_header(s); | |
161 mpeg4_encode_vol_header(s, 0, 0); | |
162 flush_put_bits(&s->pb); | |
163 outbuf_idx = (put_bits_count(&s->pb)+7)>>3; | |
164 } | |
165 | |
166 if (!frame_size) | |
167 break; | |
168 | |
169 *poutbuf = av_fast_realloc(*poutbuf, poutbuf_size, outbuf_idx + frame_si ze); | |
170 memcpy(*poutbuf + outbuf_idx, frame_data, frame_size); | |
171 outbuf_idx += frame_size; | |
172 } | |
173 | |
174 *poutbuf_size = outbuf_idx; | |
175 return 0; | |
176 } | |
177 | |
178 AVBitStreamFilter mpeg4video_es_bsf = { | |
179 "mpeg4video_es", | |
180 0, | |
181 mpeg4video_es_filter, | |
182 }; | |
OLD | NEW |