Mercurial > libavformat.hg
annotate raw.c @ 468:60f897e8dd2d libavformat
pass AVPacket into av_write_frame()
fixes the random dts/pts during encoding
asf preroll fix
no more initial zero frames for b frame encoding
mpeg-es dts during demuxing fixed
.ffm timestamp scale fixed, ffm is still broken though
author | michael |
---|---|
date | Sat, 29 May 2004 02:06:32 +0000 |
parents | 09e46bfc859c |
children | e0a66a870b7f |
rev | line source |
---|---|
0 | 1 /* |
2 * RAW encoder and decoder | |
3 * Copyright (c) 2001 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
21 #ifdef CONFIG_ENCODERS |
0 | 22 /* simple formats */ |
64 | 23 static int raw_write_header(struct AVFormatContext *s) |
0 | 24 { |
25 return 0; | |
26 } | |
27 | |
468 | 28 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
0 | 29 { |
468 | 30 put_buffer(&s->pb, pkt->data, pkt->size); |
0 | 31 put_flush_packet(&s->pb); |
32 return 0; | |
33 } | |
34 | |
64 | 35 static int raw_write_trailer(struct AVFormatContext *s) |
0 | 36 { |
37 return 0; | |
38 } | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
39 #endif //CONFIG_ENCODERS |
0 | 40 |
41 /* raw input */ | |
65 | 42 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) |
0 | 43 { |
44 AVStream *st; | |
45 int id; | |
46 | |
47 st = av_new_stream(s, 0); | |
48 if (!st) | |
49 return AVERROR_NOMEM; | |
50 if (ap) { | |
51 id = s->iformat->value; | |
52 if (id == CODEC_ID_RAWVIDEO) { | |
53 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
54 } else { | |
55 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
56 } | |
57 st->codec.codec_id = id; | |
58 | |
59 switch(st->codec.codec_type) { | |
60 case CODEC_TYPE_AUDIO: | |
61 st->codec.sample_rate = ap->sample_rate; | |
62 st->codec.channels = ap->channels; | |
63 break; | |
64 case CODEC_TYPE_VIDEO: | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
65 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
66 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 67 st->codec.width = ap->width; |
68 st->codec.height = ap->height; | |
128 | 69 st->codec.pix_fmt = ap->pix_fmt; |
0 | 70 break; |
71 default: | |
72 return -1; | |
73 } | |
74 } else { | |
75 return -1; | |
76 } | |
77 return 0; | |
78 } | |
79 | |
80 #define RAW_PACKET_SIZE 1024 | |
81 | |
64 | 82 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 83 { |
84 int ret, size; | |
28 | 85 // AVStream *st = s->streams[0]; |
0 | 86 |
87 size= RAW_PACKET_SIZE; | |
88 | |
89 if (av_new_packet(pkt, size) < 0) | |
90 return -EIO; | |
91 | |
92 pkt->stream_index = 0; | |
93 ret = get_buffer(&s->pb, pkt->data, size); | |
94 if (ret <= 0) { | |
95 av_free_packet(pkt); | |
96 return -EIO; | |
97 } | |
98 /* note: we need to modify the packet size here to handle the last | |
99 packet */ | |
100 pkt->size = ret; | |
101 return ret; | |
102 } | |
103 | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
104 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
105 { |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
106 int ret, size; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
107 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
108 size = RAW_PACKET_SIZE; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
109 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
110 if (av_new_packet(pkt, size) < 0) |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
111 return -EIO; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
112 |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
113 pkt->stream_index = 0; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
114 ret = get_partial_buffer(&s->pb, pkt->data, size); |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
115 if (ret <= 0) { |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
116 av_free_packet(pkt); |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
117 return -EIO; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
118 } |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
119 pkt->size = ret; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
120 return ret; |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
121 } |
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
122 |
64 | 123 static int raw_read_close(AVFormatContext *s) |
0 | 124 { |
125 return 0; | |
126 } | |
127 | |
306 | 128 int pcm_read_seek(AVFormatContext *s, |
129 int stream_index, int64_t timestamp) | |
130 { | |
131 AVStream *st; | |
132 int block_align, byte_rate; | |
133 int64_t pos; | |
134 | |
135 st = s->streams[0]; | |
136 switch(st->codec.codec_id) { | |
137 case CODEC_ID_PCM_S16LE: | |
138 case CODEC_ID_PCM_S16BE: | |
139 case CODEC_ID_PCM_U16LE: | |
140 case CODEC_ID_PCM_U16BE: | |
141 block_align = 2 * st->codec.channels; | |
142 byte_rate = block_align * st->codec.sample_rate; | |
143 break; | |
144 case CODEC_ID_PCM_S8: | |
145 case CODEC_ID_PCM_U8: | |
146 case CODEC_ID_PCM_MULAW: | |
147 case CODEC_ID_PCM_ALAW: | |
148 block_align = st->codec.channels; | |
149 byte_rate = block_align * st->codec.sample_rate; | |
150 break; | |
151 default: | |
152 block_align = st->codec.block_align; | |
153 byte_rate = st->codec.bit_rate / 8; | |
154 break; | |
155 } | |
156 | |
157 if (block_align <= 0 || byte_rate <= 0) | |
158 return -1; | |
159 | |
160 /* compute the position by aligning it to block_align */ | |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
389
diff
changeset
|
161 pos = av_rescale(timestamp * byte_rate, st->time_base.num, st->time_base.den); |
306 | 162 pos = (pos / block_align) * block_align; |
163 | |
164 /* recompute exact position */ | |
464 | 165 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); |
306 | 166 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); |
167 return 0; | |
168 } | |
169 | |
63 | 170 /* ac3 read */ |
171 static int ac3_read_header(AVFormatContext *s, | |
172 AVFormatParameters *ap) | |
173 { | |
174 AVStream *st; | |
175 | |
176 st = av_new_stream(s, 0); | |
177 if (!st) | |
178 return AVERROR_NOMEM; | |
179 | |
180 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
181 st->codec.codec_id = CODEC_ID_AC3; | |
306 | 182 st->need_parsing = 1; |
63 | 183 /* the parameters will be extracted from the compressed bitstream */ |
184 return 0; | |
185 } | |
186 | |
0 | 187 /* mpeg1/h263 input */ |
188 static int video_read_header(AVFormatContext *s, | |
189 AVFormatParameters *ap) | |
190 { | |
191 AVStream *st; | |
192 | |
193 st = av_new_stream(s, 0); | |
194 if (!st) | |
195 return AVERROR_NOMEM; | |
196 | |
197 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
198 st->codec.codec_id = s->iformat->value; | |
306 | 199 st->need_parsing = 1; |
200 | |
0 | 201 /* for mjpeg, specify frame rate */ |
202 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ | |
306 | 203 if (st->codec.codec_id == CODEC_ID_MJPEG || |
204 st->codec.codec_id == CODEC_ID_MPEG4) { | |
205 if (ap && ap->frame_rate) { | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
206 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
207 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 208 } else { |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
209 st->codec.frame_rate = 25; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
210 st->codec.frame_rate_base = 1; |
0 | 211 } |
212 } | |
213 return 0; | |
214 } | |
215 | |
216 #define SEQ_START_CODE 0x000001b3 | |
217 #define GOP_START_CODE 0x000001b8 | |
218 #define PICTURE_START_CODE 0x00000100 | |
219 | |
220 /* XXX: improve that by looking at several start codes */ | |
221 static int mpegvideo_probe(AVProbeData *p) | |
222 { | |
49 | 223 int code; |
224 const uint8_t *d; | |
0 | 225 |
226 /* we search the first start code. If it is a sequence, gop or | |
227 picture start code then we decide it is an mpeg video | |
228 stream. We do not send highest value to give a chance to mpegts */ | |
49 | 229 /* NOTE: the search range was restricted to avoid too many false |
230 detections */ | |
231 | |
232 if (p->buf_size < 6) | |
233 return 0; | |
234 d = p->buf; | |
235 code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]); | |
236 if ((code & 0xffffff00) == 0x100) { | |
237 if (code == SEQ_START_CODE || | |
238 code == GOP_START_CODE || | |
239 code == PICTURE_START_CODE) | |
240 return 50 - 1; | |
241 else | |
242 return 0; | |
0 | 243 } |
244 return 0; | |
245 } | |
246 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
247 static int h263_probe(AVProbeData *p) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
248 { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
249 int code; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
250 const uint8_t *d; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
251 |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
252 if (p->buf_size < 6) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
253 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
254 d = p->buf; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
255 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
256 if (code == 0x20) { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
257 return 50; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
258 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
259 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
260 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
261 |
0 | 262 AVInputFormat ac3_iformat = { |
263 "ac3", | |
264 "raw ac3", | |
265 0, | |
266 NULL, | |
63 | 267 ac3_read_header, |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
268 raw_read_partial_packet, |
0 | 269 raw_read_close, |
270 .extensions = "ac3", | |
271 }; | |
272 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
273 #ifdef CONFIG_ENCODERS |
0 | 274 AVOutputFormat ac3_oformat = { |
275 "ac3", | |
276 "raw ac3", | |
277 "audio/x-ac3", | |
278 "ac3", | |
279 0, | |
280 CODEC_ID_AC3, | |
281 0, | |
282 raw_write_header, | |
283 raw_write_packet, | |
284 raw_write_trailer, | |
285 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
286 #endif //CONFIG_ENCODERS |
0 | 287 |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
288 AVInputFormat h263_iformat = { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
289 "h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
290 "raw h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
291 0, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
292 h263_probe, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
293 video_read_header, |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
294 raw_read_partial_packet, |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
295 raw_read_close, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
296 // .extensions = "h263", //FIXME remove after writing mpeg4_probe |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
297 .value = CODEC_ID_H263, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
298 }; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
299 |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
300 #ifdef CONFIG_ENCODERS |
0 | 301 AVOutputFormat h263_oformat = { |
302 "h263", | |
303 "raw h263", | |
304 "video/x-h263", | |
305 "h263", | |
306 0, | |
307 0, | |
308 CODEC_ID_H263, | |
309 raw_write_header, | |
310 raw_write_packet, | |
311 raw_write_trailer, | |
312 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
313 #endif //CONFIG_ENCODERS |
0 | 314 |
315 AVInputFormat m4v_iformat = { | |
316 "m4v", | |
317 "raw MPEG4 video format", | |
318 0, | |
319 NULL /*mpegvideo_probe*/, | |
320 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
321 raw_read_partial_packet, |
0 | 322 raw_read_close, |
323 .extensions = "m4v", //FIXME remove after writing mpeg4_probe | |
324 .value = CODEC_ID_MPEG4, | |
325 }; | |
326 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
327 #ifdef CONFIG_ENCODERS |
0 | 328 AVOutputFormat m4v_oformat = { |
329 "m4v", | |
330 "raw MPEG4 video format", | |
331 NULL, | |
332 "m4v", | |
333 0, | |
334 CODEC_ID_NONE, | |
335 CODEC_ID_MPEG4, | |
336 raw_write_header, | |
337 raw_write_packet, | |
338 raw_write_trailer, | |
339 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
340 #endif //CONFIG_ENCODERS |
0 | 341 |
100 | 342 AVInputFormat h264_iformat = { |
343 "h264", | |
344 "raw H264 video format", | |
345 0, | |
346 NULL /*mpegvideo_probe*/, | |
347 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
348 raw_read_partial_packet, |
100 | 349 raw_read_close, |
350 .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe | |
351 .value = CODEC_ID_H264, | |
352 }; | |
353 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
354 #ifdef CONFIG_ENCODERS |
100 | 355 AVOutputFormat h264_oformat = { |
356 "h264", | |
357 "raw H264 video format", | |
358 NULL, | |
359 "h264", | |
360 0, | |
361 CODEC_ID_NONE, | |
362 CODEC_ID_H264, | |
363 raw_write_header, | |
364 raw_write_packet, | |
365 raw_write_trailer, | |
366 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
367 #endif //CONFIG_ENCODERS |
100 | 368 |
0 | 369 AVInputFormat mpegvideo_iformat = { |
370 "mpegvideo", | |
371 "MPEG video", | |
372 0, | |
373 mpegvideo_probe, | |
374 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
375 raw_read_partial_packet, |
0 | 376 raw_read_close, |
377 .value = CODEC_ID_MPEG1VIDEO, | |
378 }; | |
379 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
380 #ifdef CONFIG_ENCODERS |
0 | 381 AVOutputFormat mpeg1video_oformat = { |
382 "mpeg1video", | |
383 "MPEG video", | |
384 "video/x-mpeg", | |
385 "mpg,mpeg", | |
386 0, | |
387 0, | |
388 CODEC_ID_MPEG1VIDEO, | |
389 raw_write_header, | |
390 raw_write_packet, | |
391 raw_write_trailer, | |
392 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
393 #endif //CONFIG_ENCODERS |
0 | 394 |
395 AVInputFormat mjpeg_iformat = { | |
396 "mjpeg", | |
397 "MJPEG video", | |
398 0, | |
399 NULL, | |
400 video_read_header, | |
389
e14fcd57ad2f
decode latency patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
306
diff
changeset
|
401 raw_read_partial_packet, |
0 | 402 raw_read_close, |
403 .extensions = "mjpg,mjpeg", | |
404 .value = CODEC_ID_MJPEG, | |
405 }; | |
406 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
407 #ifdef CONFIG_ENCODERS |
0 | 408 AVOutputFormat mjpeg_oformat = { |
409 "mjpeg", | |
410 "MJPEG video", | |
411 "video/x-mjpeg", | |
412 "mjpg,mjpeg", | |
413 0, | |
414 0, | |
415 CODEC_ID_MJPEG, | |
416 raw_write_header, | |
417 raw_write_packet, | |
418 raw_write_trailer, | |
419 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
420 #endif //CONFIG_ENCODERS |
0 | 421 |
422 /* pcm formats */ | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
423 |
306 | 424 #define PCMINPUTDEF(name, long_name, ext, codec) \ |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
425 AVInputFormat pcm_ ## name ## _iformat = {\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
426 #name,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
427 long_name,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
428 0,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
429 NULL,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
430 raw_read_header,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
431 raw_read_packet,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
432 raw_read_close,\ |
306 | 433 pcm_read_seek,\ |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
434 .extensions = ext,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
435 .value = codec,\ |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
436 }; |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
437 |
306 | 438 #if !defined(CONFIG_ENCODERS) && defined(CONFIG_DECODERS) |
439 | |
440 #define PCMDEF(name, long_name, ext, codec) \ | |
441 PCMINPUTDEF(name, long_name, ext, codec) | |
442 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
443 #else |
0 | 444 |
445 #define PCMDEF(name, long_name, ext, codec) \ | |
306 | 446 PCMINPUTDEF(name, long_name, ext, codec)\ |
0 | 447 \ |
448 AVOutputFormat pcm_ ## name ## _oformat = {\ | |
449 #name,\ | |
450 long_name,\ | |
451 NULL,\ | |
452 ext,\ | |
453 0,\ | |
454 codec,\ | |
455 0,\ | |
456 raw_write_header,\ | |
457 raw_write_packet,\ | |
458 raw_write_trailer,\ | |
459 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
460 #endif //CONFIG_ENCODERS |
0 | 461 |
462 #ifdef WORDS_BIGENDIAN | |
463 #define BE_DEF(s) s | |
464 #define LE_DEF(s) NULL | |
465 #else | |
466 #define BE_DEF(s) NULL | |
467 #define LE_DEF(s) s | |
468 #endif | |
469 | |
470 | |
471 PCMDEF(s16le, "pcm signed 16 bit little endian format", | |
472 LE_DEF("sw"), CODEC_ID_PCM_S16LE) | |
473 | |
474 PCMDEF(s16be, "pcm signed 16 bit big endian format", | |
475 BE_DEF("sw"), CODEC_ID_PCM_S16BE) | |
476 | |
477 PCMDEF(u16le, "pcm unsigned 16 bit little endian format", | |
478 LE_DEF("uw"), CODEC_ID_PCM_U16LE) | |
479 | |
480 PCMDEF(u16be, "pcm unsigned 16 bit big endian format", | |
481 BE_DEF("uw"), CODEC_ID_PCM_U16BE) | |
482 | |
483 PCMDEF(s8, "pcm signed 8 bit format", | |
484 "sb", CODEC_ID_PCM_S8) | |
485 | |
486 PCMDEF(u8, "pcm unsigned 8 bit format", | |
487 "ub", CODEC_ID_PCM_U8) | |
488 | |
489 PCMDEF(mulaw, "pcm mu law format", | |
490 "ul", CODEC_ID_PCM_MULAW) | |
491 | |
492 PCMDEF(alaw, "pcm A law format", | |
493 "al", CODEC_ID_PCM_ALAW) | |
494 | |
64 | 495 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 496 { |
497 int packet_size, ret, width, height; | |
498 AVStream *st = s->streams[0]; | |
499 | |
500 width = st->codec.width; | |
501 height = st->codec.height; | |
502 | |
128 | 503 packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); |
504 if (packet_size < 0) | |
0 | 505 av_abort(); |
506 | |
507 if (av_new_packet(pkt, packet_size) < 0) | |
508 return -EIO; | |
509 | |
510 pkt->stream_index = 0; | |
511 #if 0 | |
512 /* bypass buffered I/O */ | |
513 ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size); | |
514 #else | |
515 ret = get_buffer(&s->pb, pkt->data, pkt->size); | |
516 #endif | |
517 if (ret != pkt->size) { | |
518 av_free_packet(pkt); | |
519 return -EIO; | |
520 } else { | |
521 return 0; | |
522 } | |
523 } | |
524 | |
525 AVInputFormat rawvideo_iformat = { | |
526 "rawvideo", | |
527 "raw video format", | |
528 0, | |
529 NULL, | |
530 raw_read_header, | |
531 rawvideo_read_packet, | |
532 raw_read_close, | |
533 .extensions = "yuv", | |
534 .value = CODEC_ID_RAWVIDEO, | |
535 }; | |
536 | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
537 #ifdef CONFIG_ENCODERS |
0 | 538 AVOutputFormat rawvideo_oformat = { |
539 "rawvideo", | |
540 "raw video format", | |
541 NULL, | |
542 "yuv", | |
543 0, | |
544 CODEC_ID_NONE, | |
545 CODEC_ID_RAWVIDEO, | |
546 raw_write_header, | |
547 raw_write_packet, | |
548 raw_write_trailer, | |
549 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
550 #endif //CONFIG_ENCODERS |
0 | 551 |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
552 #ifdef CONFIG_ENCODERS |
468 | 553 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
0 | 554 { |
555 return 0; | |
556 } | |
557 | |
558 AVOutputFormat null_oformat = { | |
559 "null", | |
560 "null video format", | |
561 NULL, | |
562 NULL, | |
563 0, | |
564 #ifdef WORDS_BIGENDIAN | |
565 CODEC_ID_PCM_S16BE, | |
566 #else | |
567 CODEC_ID_PCM_S16LE, | |
568 #endif | |
569 CODEC_ID_RAWVIDEO, | |
570 raw_write_header, | |
571 null_write_packet, | |
572 raw_write_trailer, | |
573 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE, | |
574 }; | |
277
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
575 #endif //CONFIG_ENCODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
576 |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
577 #ifndef CONFIG_ENCODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
578 #define av_register_output_format(format) |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
579 #endif |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
580 #ifndef CONFIG_DECODERS |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
581 #define av_register_input_format(format) |
a313e1080322
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
241
diff
changeset
|
582 #endif |
0 | 583 |
584 int raw_init(void) | |
585 { | |
586 av_register_input_format(&ac3_iformat); | |
587 av_register_output_format(&ac3_oformat); | |
588 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
589 av_register_input_format(&h263_iformat); |
0 | 590 av_register_output_format(&h263_oformat); |
591 | |
592 av_register_input_format(&m4v_iformat); | |
593 av_register_output_format(&m4v_oformat); | |
100 | 594 |
595 av_register_input_format(&h264_iformat); | |
596 av_register_output_format(&h264_oformat); | |
0 | 597 |
598 av_register_input_format(&mpegvideo_iformat); | |
599 av_register_output_format(&mpeg1video_oformat); | |
600 | |
601 av_register_input_format(&mjpeg_iformat); | |
602 av_register_output_format(&mjpeg_oformat); | |
603 | |
604 av_register_input_format(&pcm_s16le_iformat); | |
605 av_register_output_format(&pcm_s16le_oformat); | |
606 av_register_input_format(&pcm_s16be_iformat); | |
607 av_register_output_format(&pcm_s16be_oformat); | |
608 av_register_input_format(&pcm_u16le_iformat); | |
609 av_register_output_format(&pcm_u16le_oformat); | |
610 av_register_input_format(&pcm_u16be_iformat); | |
611 av_register_output_format(&pcm_u16be_oformat); | |
612 av_register_input_format(&pcm_s8_iformat); | |
613 av_register_output_format(&pcm_s8_oformat); | |
614 av_register_input_format(&pcm_u8_iformat); | |
615 av_register_output_format(&pcm_u8_oformat); | |
616 av_register_input_format(&pcm_mulaw_iformat); | |
617 av_register_output_format(&pcm_mulaw_oformat); | |
618 av_register_input_format(&pcm_alaw_iformat); | |
619 av_register_output_format(&pcm_alaw_oformat); | |
620 | |
621 av_register_input_format(&rawvideo_iformat); | |
622 av_register_output_format(&rawvideo_oformat); | |
623 | |
624 av_register_output_format(&null_oformat); | |
625 return 0; | |
626 } |