Mercurial > libavformat.hg
annotate utils.c @ 1278:f40d75601106 libavformat
initial support for AVOption in AVFormatContext
author | nicodvb |
---|---|
date | Sun, 27 Aug 2006 12:14:13 +0000 |
parents | 613adcd70d18 |
children | a12e0b434174 |
rev | line source |
---|---|
0 | 1 /* |
2 * Various utilities for ffmpeg system | |
3 * Copyright (c) 2000, 2001, 2002 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 | |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 */ |
19 #include "avformat.h" | |
1142
e3a585883bbd
Move initialisations and internal symbols in allformats.h,
gpoirier
parents:
1141
diff
changeset
|
20 #include "allformats.h" |
1278 | 21 #include "opt.h" |
0 | 22 |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
23 #undef NDEBUG |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
24 #include <assert.h> |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
25 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
26 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
27 * @file libavformat/utils.c |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
28 * Various utility functions for using ffmpeg library. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
29 */ |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
30 |
1135
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
31 static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den); |
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
32 static void av_frac_add(AVFrac *f, int64_t incr); |
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
33 static void av_frac_set(AVFrac *f, int64_t val); |
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
34 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
35 /** head of registered input format linked list. */ |
512
8dfd00fb6a6d
Minor Patch for shared libs on Mac OSX by (Bill May <wmay at cisco dot com>)
michael
parents:
511
diff
changeset
|
36 AVInputFormat *first_iformat = NULL; |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
37 /** head of registered output format linked list. */ |
512
8dfd00fb6a6d
Minor Patch for shared libs on Mac OSX by (Bill May <wmay at cisco dot com>)
michael
parents:
511
diff
changeset
|
38 AVOutputFormat *first_oformat = NULL; |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
39 /** head of registered image format linked list. */ |
512
8dfd00fb6a6d
Minor Patch for shared libs on Mac OSX by (Bill May <wmay at cisco dot com>)
michael
parents:
511
diff
changeset
|
40 AVImageFormat *first_image_format = NULL; |
0 | 41 |
42 void av_register_input_format(AVInputFormat *format) | |
43 { | |
44 AVInputFormat **p; | |
45 p = &first_iformat; | |
46 while (*p != NULL) p = &(*p)->next; | |
47 *p = format; | |
48 format->next = NULL; | |
49 } | |
50 | |
51 void av_register_output_format(AVOutputFormat *format) | |
52 { | |
53 AVOutputFormat **p; | |
54 p = &first_oformat; | |
55 while (*p != NULL) p = &(*p)->next; | |
56 *p = format; | |
57 format->next = NULL; | |
58 } | |
59 | |
60 int match_ext(const char *filename, const char *extensions) | |
61 { | |
62 const char *ext, *p; | |
63 char ext1[32], *q; | |
64 | |
453 | 65 if(!filename) |
66 return 0; | |
885 | 67 |
0 | 68 ext = strrchr(filename, '.'); |
69 if (ext) { | |
70 ext++; | |
71 p = extensions; | |
72 for(;;) { | |
73 q = ext1; | |
885 | 74 while (*p != '\0' && *p != ',' && q-ext1<sizeof(ext1)-1) |
0 | 75 *q++ = *p++; |
76 *q = '\0'; | |
885 | 77 if (!strcasecmp(ext1, ext)) |
0 | 78 return 1; |
885 | 79 if (*p == '\0') |
0 | 80 break; |
81 p++; | |
82 } | |
83 } | |
84 return 0; | |
85 } | |
86 | |
885 | 87 AVOutputFormat *guess_format(const char *short_name, const char *filename, |
0 | 88 const char *mime_type) |
89 { | |
90 AVOutputFormat *fmt, *fmt_found; | |
91 int score_max, score; | |
92 | |
20 | 93 /* specific test for image sequences */ |
1169 | 94 #ifdef CONFIG_IMAGE2_MUXER |
885 | 95 if (!short_name && filename && |
21 | 96 filename_number_test(filename) >= 0 && |
583 | 97 av_guess_image2_codec(filename) != CODEC_ID_NONE) { |
98 return guess_format("image2", NULL, NULL); | |
99 } | |
1169 | 100 #endif |
885 | 101 if (!short_name && filename && |
583 | 102 filename_number_test(filename) >= 0 && |
21 | 103 guess_image_format(filename)) { |
20 | 104 return guess_format("image", NULL, NULL); |
105 } | |
106 | |
0 | 107 /* find the proper file type */ |
108 fmt_found = NULL; | |
109 score_max = 0; | |
110 fmt = first_oformat; | |
111 while (fmt != NULL) { | |
112 score = 0; | |
113 if (fmt->name && short_name && !strcmp(fmt->name, short_name)) | |
114 score += 100; | |
115 if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type)) | |
116 score += 10; | |
885 | 117 if (filename && fmt->extensions && |
0 | 118 match_ext(filename, fmt->extensions)) { |
119 score += 5; | |
120 } | |
121 if (score > score_max) { | |
122 score_max = score; | |
123 fmt_found = fmt; | |
124 } | |
125 fmt = fmt->next; | |
126 } | |
127 return fmt_found; | |
885 | 128 } |
129 | |
130 AVOutputFormat *guess_stream_format(const char *short_name, const char *filename, | |
0 | 131 const char *mime_type) |
132 { | |
133 AVOutputFormat *fmt = guess_format(short_name, filename, mime_type); | |
134 | |
135 if (fmt) { | |
136 AVOutputFormat *stream_fmt; | |
137 char stream_format_name[64]; | |
138 | |
139 snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream", fmt->name); | |
140 stream_fmt = guess_format(stream_format_name, NULL, NULL); | |
141 | |
142 if (stream_fmt) | |
143 fmt = stream_fmt; | |
144 } | |
145 | |
146 return fmt; | |
147 } | |
148 | |
583 | 149 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
150 * Guesses the codec id based upon muxer and filename. |
583 | 151 */ |
885 | 152 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, |
583 | 153 const char *filename, const char *mime_type, enum CodecType type){ |
154 if(type == CODEC_TYPE_VIDEO){ | |
155 enum CodecID codec_id= CODEC_ID_NONE; | |
156 | |
1169 | 157 #ifdef CONFIG_IMAGE2_MUXER |
586 | 158 if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){ |
583 | 159 codec_id= av_guess_image2_codec(filename); |
160 } | |
1169 | 161 #endif |
583 | 162 if(codec_id == CODEC_ID_NONE) |
163 codec_id= fmt->video_codec; | |
164 return codec_id; | |
165 }else if(type == CODEC_TYPE_AUDIO) | |
166 return fmt->audio_codec; | |
167 else | |
168 return CODEC_ID_NONE; | |
169 } | |
170 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
171 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
172 * finds AVInputFormat based on input format's short name. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
173 */ |
0 | 174 AVInputFormat *av_find_input_format(const char *short_name) |
175 { | |
176 AVInputFormat *fmt; | |
177 for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) { | |
178 if (!strcmp(fmt->name, short_name)) | |
179 return fmt; | |
180 } | |
181 return NULL; | |
182 } | |
183 | |
184 /* memory handling */ | |
185 | |
186 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
187 * Default packet destructor. |
53
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
188 */ |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
189 void av_destruct_packet(AVPacket *pkt) |
53
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
190 { |
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
191 av_free(pkt->data); |
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
192 pkt->data = NULL; pkt->size = 0; |
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
193 } |
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
194 |
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
195 /** |
0 | 196 * Allocate the payload of a packet and intialized its fields to default values. |
197 * | |
198 * @param pkt packet | |
199 * @param size wanted payload size | |
200 * @return 0 if OK. AVERROR_xxx otherwise. | |
201 */ | |
202 int av_new_packet(AVPacket *pkt, int size) | |
203 { | |
639 | 204 void *data; |
205 if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE) | |
885 | 206 return AVERROR_NOMEM; |
639 | 207 data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); |
53
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
208 if (!data) |
0 | 209 return AVERROR_NOMEM; |
53
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
210 memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
0 | 211 |
53
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
212 av_init_packet(pkt); |
885 | 213 pkt->data = data; |
53
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
214 pkt->size = size; |
fb671d87824e
zero copy packet handling for DV1394 by Max Krasnyansky
bellard
parents:
32
diff
changeset
|
215 pkt->destruct = av_destruct_packet; |
0 | 216 return 0; |
217 } | |
218 | |
775 | 219 /** |
220 * Allocate and read the payload of a packet and intialized its fields to default values. | |
221 * | |
222 * @param pkt packet | |
223 * @param size wanted payload size | |
224 * @return >0 (read size) if OK. AVERROR_xxx otherwise. | |
225 */ | |
226 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size) | |
227 { | |
228 int ret= av_new_packet(pkt, size); | |
229 | |
230 if(ret<0) | |
231 return ret; | |
232 | |
233 pkt->pos= url_ftell(s); | |
234 | |
235 ret= get_buffer(s, pkt->data, size); | |
236 if(ret<=0) | |
237 av_free_packet(pkt); | |
238 else | |
239 pkt->size= ret; | |
240 | |
241 return ret; | |
242 } | |
243 | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
244 /* This is a hack - the packet memory allocation stuff is broken. The |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
245 packet is allocated if it was not really allocated */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
246 int av_dup_packet(AVPacket *pkt) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
247 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
248 if (pkt->destruct != av_destruct_packet) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
249 uint8_t *data; |
330 | 250 /* we duplicate the packet and don't forget to put the padding |
251 again */ | |
639 | 252 if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE) |
885 | 253 return AVERROR_NOMEM; |
330 | 254 data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
255 if (!data) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
256 return AVERROR_NOMEM; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
257 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
258 memcpy(data, pkt->data, pkt->size); |
330 | 259 memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
260 pkt->data = data; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
261 pkt->destruct = av_destruct_packet; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
262 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
263 return 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
264 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
265 |
0 | 266 /* fifo handling */ |
267 | |
268 int fifo_init(FifoBuffer *f, int size) | |
269 { | |
270 f->buffer = av_malloc(size); | |
271 if (!f->buffer) | |
272 return -1; | |
273 f->end = f->buffer + size; | |
274 f->wptr = f->rptr = f->buffer; | |
275 return 0; | |
276 } | |
277 | |
278 void fifo_free(FifoBuffer *f) | |
279 { | |
280 av_free(f->buffer); | |
281 } | |
282 | |
65 | 283 int fifo_size(FifoBuffer *f, uint8_t *rptr) |
0 | 284 { |
285 int size; | |
885 | 286 |
602 | 287 if(!rptr) |
288 rptr= f->rptr; | |
0 | 289 |
290 if (f->wptr >= rptr) { | |
291 size = f->wptr - rptr; | |
292 } else { | |
293 size = (f->end - rptr) + (f->wptr - f->buffer); | |
294 } | |
295 return size; | |
296 } | |
297 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
298 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
299 * Get data from the fifo (returns -1 if not enough data). |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
300 */ |
65 | 301 int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr) |
0 | 302 { |
602 | 303 uint8_t *rptr; |
0 | 304 int size, len; |
305 | |
602 | 306 if(!rptr_ptr) |
307 rptr_ptr= &f->rptr; | |
308 rptr = *rptr_ptr; | |
309 | |
0 | 310 if (f->wptr >= rptr) { |
311 size = f->wptr - rptr; | |
312 } else { | |
313 size = (f->end - rptr) + (f->wptr - f->buffer); | |
314 } | |
885 | 315 |
0 | 316 if (size < buf_size) |
317 return -1; | |
318 while (buf_size > 0) { | |
319 len = f->end - rptr; | |
320 if (len > buf_size) | |
321 len = buf_size; | |
322 memcpy(buf, rptr, len); | |
323 buf += len; | |
324 rptr += len; | |
325 if (rptr >= f->end) | |
326 rptr = f->buffer; | |
327 buf_size -= len; | |
328 } | |
329 *rptr_ptr = rptr; | |
330 return 0; | |
331 } | |
332 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
333 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
334 * Resizes a FIFO. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
335 */ |
639 | 336 void fifo_realloc(FifoBuffer *f, unsigned int new_size){ |
337 unsigned int old_size= f->end - f->buffer; | |
885 | 338 |
602 | 339 if(old_size < new_size){ |
340 uint8_t *old= f->buffer; | |
341 | |
342 f->buffer= av_realloc(f->buffer, new_size); | |
343 | |
344 f->rptr += f->buffer - old; | |
345 f->wptr += f->buffer - old; | |
346 | |
347 if(f->wptr < f->rptr){ | |
348 memmove(f->rptr + new_size - old_size, f->rptr, f->buffer + old_size - f->rptr); | |
349 f->rptr += new_size - old_size; | |
350 } | |
351 f->end= f->buffer + new_size; | |
352 } | |
353 } | |
354 | |
1123
6992dd78ff68
Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents:
1120
diff
changeset
|
355 void fifo_write(FifoBuffer *f, const uint8_t *buf, int size, uint8_t **wptr_ptr) |
0 | 356 { |
357 int len; | |
65 | 358 uint8_t *wptr; |
602 | 359 |
360 if(!wptr_ptr) | |
361 wptr_ptr= &f->wptr; | |
0 | 362 wptr = *wptr_ptr; |
602 | 363 |
0 | 364 while (size > 0) { |
365 len = f->end - wptr; | |
366 if (len > size) | |
367 len = size; | |
368 memcpy(wptr, buf, len); | |
369 wptr += len; | |
370 if (wptr >= f->end) | |
371 wptr = f->buffer; | |
372 buf += len; | |
373 size -= len; | |
374 } | |
375 *wptr_ptr = wptr; | |
376 } | |
377 | |
542 | 378 /* get data from the fifo (return -1 if not enough data) */ |
379 int put_fifo(ByteIOContext *pb, FifoBuffer *f, int buf_size, uint8_t **rptr_ptr) | |
380 { | |
381 uint8_t *rptr = *rptr_ptr; | |
382 int size, len; | |
383 | |
384 if (f->wptr >= rptr) { | |
385 size = f->wptr - rptr; | |
386 } else { | |
387 size = (f->end - rptr) + (f->wptr - f->buffer); | |
388 } | |
885 | 389 |
542 | 390 if (size < buf_size) |
391 return -1; | |
392 while (buf_size > 0) { | |
393 len = f->end - rptr; | |
394 if (len > buf_size) | |
395 len = buf_size; | |
396 put_buffer(pb, rptr, len); | |
397 rptr += len; | |
398 if (rptr >= f->end) | |
399 rptr = f->buffer; | |
400 buf_size -= len; | |
401 } | |
402 *rptr_ptr = rptr; | |
403 return 0; | |
404 } | |
405 | |
0 | 406 int filename_number_test(const char *filename) |
407 { | |
408 char buf[1024]; | |
453 | 409 if(!filename) |
410 return -1; | |
0 | 411 return get_frame_filename(buf, sizeof(buf), filename, 1); |
412 } | |
413 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
414 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
415 * Guess file format. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
416 */ |
0 | 417 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) |
418 { | |
419 AVInputFormat *fmt1, *fmt; | |
420 int score, score_max; | |
421 | |
422 fmt = NULL; | |
423 score_max = 0; | |
424 for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) { | |
425 if (!is_opened && !(fmt1->flags & AVFMT_NOFILE)) | |
426 continue; | |
427 score = 0; | |
428 if (fmt1->read_probe) { | |
429 score = fmt1->read_probe(pd); | |
430 } else if (fmt1->extensions) { | |
431 if (match_ext(pd->filename, fmt1->extensions)) { | |
432 score = 50; | |
433 } | |
885 | 434 } |
0 | 435 if (score > score_max) { |
436 score_max = score; | |
437 fmt = fmt1; | |
438 } | |
439 } | |
440 return fmt; | |
441 } | |
442 | |
443 /************************************************************/ | |
444 /* input media file */ | |
445 | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
446 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
447 * Open a media file from an IO stream. 'fmt' must be specified. |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
448 */ |
371 | 449 static const char* format_to_name(void* ptr) |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
450 { |
371 | 451 AVFormatContext* fc = (AVFormatContext*) ptr; |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
452 if(fc->iformat) return fc->iformat->name; |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
453 else if(fc->oformat) return fc->oformat->name; |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
454 else return "NULL"; |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
455 } |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
456 |
1278 | 457 #define OFFSET(x) (int)&((AVFormatContext*)0)->x |
458 #define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C | |
459 //these names are too long to be readable | |
460 #define E AV_OPT_FLAG_ENCODING_PARAM | |
461 #define D AV_OPT_FLAG_DECODING_PARAM | |
462 | |
463 static const AVOption options[]={ | |
464 {NULL}, | |
465 }; | |
466 | |
467 static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options }; | |
468 | |
469 void avformat_get_context_defaults(AVFormatContext *s){ | |
470 memset(s, 0, sizeof(AVFormatContext)); | |
471 } | |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
472 |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
473 AVFormatContext *av_alloc_format_context(void) |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
474 { |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
475 AVFormatContext *ic; |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
476 ic = av_mallocz(sizeof(AVFormatContext)); |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
477 if (!ic) return ic; |
1278 | 478 avformat_get_context_defaults(ic); |
371 | 479 ic->av_class = &av_format_context_class; |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
480 return ic; |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
481 } |
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
367
diff
changeset
|
482 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
483 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
484 * Allocates all the structures needed to read an input stream. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
485 * This does not open the needed codecs for decoding the stream[s]. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
486 */ |
885 | 487 int av_open_input_stream(AVFormatContext **ic_ptr, |
488 ByteIOContext *pb, const char *filename, | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
489 AVInputFormat *fmt, AVFormatParameters *ap) |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
490 { |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
491 int err; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
492 AVFormatContext *ic; |
1003 | 493 AVFormatParameters default_ap; |
494 | |
495 if(!ap){ | |
496 ap=&default_ap; | |
497 memset(ap, 0, sizeof(default_ap)); | |
498 } | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
499 |
1278 | 500 if(!ap->prealloced_context) |
501 ic = av_alloc_format_context(); | |
502 else | |
503 ic = *ic_ptr; | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
504 if (!ic) { |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
505 err = AVERROR_NOMEM; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
506 goto fail; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
507 } |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
508 ic->iformat = fmt; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
509 if (pb) |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
510 ic->pb = *pb; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
511 ic->duration = AV_NOPTS_VALUE; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
512 ic->start_time = AV_NOPTS_VALUE; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
513 pstrcpy(ic->filename, sizeof(ic->filename), filename); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
514 |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
515 /* allocate private data */ |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
516 if (fmt->priv_data_size > 0) { |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
517 ic->priv_data = av_mallocz(fmt->priv_data_size); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
518 if (!ic->priv_data) { |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
519 err = AVERROR_NOMEM; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
520 goto fail; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
521 } |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
522 } else { |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
523 ic->priv_data = NULL; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
524 } |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
525 |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
526 err = ic->iformat->read_header(ic, ap); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
527 if (err < 0) |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
528 goto fail; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
529 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
530 if (pb) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
531 ic->data_offset = url_ftell(&ic->pb); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
532 |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
533 *ic_ptr = ic; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
534 return 0; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
535 fail: |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
536 if (ic) { |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
537 av_freep(&ic->priv_data); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
538 } |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
539 av_free(ic); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
540 *ic_ptr = NULL; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
541 return err; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
542 } |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
543 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
544 /** Size of probe buffer, for guessing file type from file contents. */ |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
545 #define PROBE_BUF_MIN 2048 |
1111 | 546 #define PROBE_BUF_MAX (1<<20) |
0 | 547 |
548 /** | |
549 * Open a media file as input. The codec are not opened. Only the file | |
550 * header (if present) is read. | |
551 * | |
552 * @param ic_ptr the opened media file handle is put here | |
553 * @param filename filename to open. | |
554 * @param fmt if non NULL, force the file format to use | |
555 * @param buf_size optional buffer size (zero if default is OK) | |
556 * @param ap additionnal parameters needed when opening the file (NULL if default) | |
557 * @return 0 if OK. AVERROR_xxx otherwise. | |
558 */ | |
885 | 559 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, |
0 | 560 AVInputFormat *fmt, |
561 int buf_size, | |
562 AVFormatParameters *ap) | |
563 { | |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
564 int err, must_open_file, file_opened, probe_size; |
0 | 565 AVProbeData probe_data, *pd = &probe_data; |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
566 ByteIOContext pb1, *pb = &pb1; |
885 | 567 |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
568 file_opened = 0; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
569 pd->filename = ""; |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
570 if (filename) |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
571 pd->filename = filename; |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
572 pd->buf = NULL; |
0 | 573 pd->buf_size = 0; |
574 | |
575 if (!fmt) { | |
576 /* guess format if no file can be opened */ | |
577 fmt = av_probe_input_format(pd, 0); | |
578 } | |
579 | |
172 | 580 /* do not open file if the format does not need it. XXX: specific |
581 hack needed to handle RTSP/TCP */ | |
582 must_open_file = 1; | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
583 if (fmt && (fmt->flags & AVFMT_NOFILE)) { |
172 | 584 must_open_file = 0; |
535 | 585 pb= NULL; //FIXME this or memset(pb, 0, sizeof(ByteIOContext)); otherwise its uninitalized |
172 | 586 } |
587 | |
588 if (!fmt || must_open_file) { | |
20 | 589 /* if no file needed do not try to open one */ |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
590 if (url_fopen(pb, filename, URL_RDONLY) < 0) { |
0 | 591 err = AVERROR_IO; |
592 goto fail; | |
593 } | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
594 file_opened = 1; |
0 | 595 if (buf_size > 0) { |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
596 url_setbufsize(pb, buf_size); |
0 | 597 } |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
598 |
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
599 for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){ |
0 | 600 /* read probe data */ |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
601 pd->buf= av_realloc(pd->buf, probe_size); |
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
602 pd->buf_size = get_buffer(pb, pd->buf, probe_size); |
502
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
603 if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) { |
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
604 url_fclose(pb); |
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
605 if (url_fopen(pb, filename, URL_RDONLY) < 0) { |
941
5e15da09cd6b
Fix for url_fclose() being called on an already closed file based on a patch by (<Colin Ward> hitman codehq org)
michael
parents:
927
diff
changeset
|
606 file_opened = 0; |
502
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
607 err = AVERROR_IO; |
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
608 goto fail; |
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
609 } |
813b0119a98e
ffserver fixes by (Koos Vriezen <koos.vriezen at xs4all dot nl>)
michael
parents:
497
diff
changeset
|
610 } |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
611 /* guess file format */ |
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
612 fmt = av_probe_input_format(pd, 1); |
0 | 613 } |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
614 av_freep(&pd->buf); |
0 | 615 } |
616 | |
617 /* if still no format found, error */ | |
618 if (!fmt) { | |
619 err = AVERROR_NOFMT; | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
620 goto fail; |
0 | 621 } |
885 | 622 |
0 | 623 /* XXX: suppress this hack for redirectors */ |
22
65433f1b2549
os2 support patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents:
21
diff
changeset
|
624 #ifdef CONFIG_NETWORK |
1167 | 625 if (fmt == &redir_demuxer) { |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
626 err = redir_open(ic_ptr, pb); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
627 url_fclose(pb); |
0 | 628 return err; |
629 } | |
11
932b59c66c60
mingw patch by (Bill Eldridge <bill at rfa dot org>)
michaelni
parents:
9
diff
changeset
|
630 #endif |
0 | 631 |
20 | 632 /* check filename in case of an image number is expected */ |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
633 if (fmt->flags & AVFMT_NEEDNUMBER) { |
885 | 634 if (filename_number_test(filename) < 0) { |
20 | 635 err = AVERROR_NUMEXPECTED; |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
636 goto fail; |
20 | 637 } |
638 } | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
639 err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap); |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
640 if (err) |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
641 goto fail; |
0 | 642 return 0; |
643 fail: | |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
644 av_freep(&pd->buf); |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
645 if (file_opened) |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
646 url_fclose(pb); |
0 | 647 *ic_ptr = NULL; |
648 return err; | |
885 | 649 |
0 | 650 } |
651 | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
652 /*******************************************************/ |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
653 |
0 | 654 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
655 * Read a transport packet from a media file. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
656 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
657 * This function is absolete and should never be used. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
658 * Use av_read_frame() instead. |
885 | 659 * |
0 | 660 * @param s media file handle |
885 | 661 * @param pkt is filled |
662 * @return 0 if OK. AVERROR_xxx if error. | |
0 | 663 */ |
664 int av_read_packet(AVFormatContext *s, AVPacket *pkt) | |
665 { | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
666 return s->iformat->read_packet(s, pkt); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
667 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
668 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
669 /**********************************************************/ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
670 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
671 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
672 * Get the number of samples of an audio frame. Return (-1) if error. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
673 */ |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
674 static int get_audio_frame_size(AVCodecContext *enc, int size) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
675 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
676 int frame_size; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
677 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
678 if (enc->frame_size <= 1) { |
1158 | 679 int bits_per_sample = av_get_bits_per_sample(enc->codec_id); |
680 | |
681 if (bits_per_sample) { | |
846
fd1c2109505e
Support de-/encoding of 24 and 32 bit PCM (from and to internal 16 bit).
reimar
parents:
842
diff
changeset
|
682 if (enc->channels == 0) |
fd1c2109505e
Support de-/encoding of 24 and 32 bit PCM (from and to internal 16 bit).
reimar
parents:
842
diff
changeset
|
683 return -1; |
1160 | 684 frame_size = (size << 3) / (bits_per_sample * enc->channels); |
1158 | 685 } else { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
686 /* used for example by ADPCM codecs */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
687 if (enc->bit_rate == 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
688 return -1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
689 frame_size = (size * 8 * enc->sample_rate) / enc->bit_rate; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
690 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
691 } else { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
692 frame_size = enc->frame_size; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
693 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
694 return frame_size; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
695 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
696 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
697 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
698 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
699 * Return the frame duration in seconds, return 0 if not available. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
700 */ |
885 | 701 static void compute_frame_duration(int *pnum, int *pden, AVStream *st, |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
702 AVCodecParserContext *pc, AVPacket *pkt) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
703 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
704 int frame_size; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
705 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
706 *pnum = 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
707 *pden = 0; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
708 switch(st->codec->codec_type) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
709 case CODEC_TYPE_VIDEO: |
757 | 710 if(st->time_base.num*1000LL > st->time_base.den){ |
743 | 711 *pnum = st->time_base.num; |
712 *pden = st->time_base.den; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
713 }else if(st->codec->time_base.num*1000LL > st->codec->time_base.den){ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
714 *pnum = st->codec->time_base.num; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
715 *pden = st->codec->time_base.den; |
747
95c9cef3c3db
prefer container time_base for frame duration guess
michael
parents:
743
diff
changeset
|
716 if (pc && pc->repeat_pict) { |
95c9cef3c3db
prefer container time_base for frame duration guess
michael
parents:
743
diff
changeset
|
717 *pden *= 2; |
95c9cef3c3db
prefer container time_base for frame duration guess
michael
parents:
743
diff
changeset
|
718 *pnum = (*pnum) * (2 + pc->repeat_pict); |
95c9cef3c3db
prefer container time_base for frame duration guess
michael
parents:
743
diff
changeset
|
719 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
720 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
721 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
722 case CODEC_TYPE_AUDIO: |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
723 frame_size = get_audio_frame_size(st->codec, pkt->size); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
724 if (frame_size < 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
725 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
726 *pnum = frame_size; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
727 *pden = st->codec->sample_rate; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
728 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
729 default: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
730 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
731 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
732 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
733 |
570
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
734 static int is_intra_only(AVCodecContext *enc){ |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
735 if(enc->codec_type == CODEC_TYPE_AUDIO){ |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
736 return 1; |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
737 }else if(enc->codec_type == CODEC_TYPE_VIDEO){ |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
738 switch(enc->codec_id){ |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
739 case CODEC_ID_MJPEG: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
740 case CODEC_ID_MJPEGB: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
741 case CODEC_ID_LJPEG: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
742 case CODEC_ID_RAWVIDEO: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
743 case CODEC_ID_DVVIDEO: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
744 case CODEC_ID_HUFFYUV: |
599 | 745 case CODEC_ID_FFVHUFF: |
570
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
746 case CODEC_ID_ASV1: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
747 case CODEC_ID_ASV2: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
748 case CODEC_ID_VCR1: |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
749 return 1; |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
750 default: break; |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
751 } |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
752 } |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
753 return 0; |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
754 } |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
755 |
464 | 756 static int64_t lsb2full(int64_t lsb, int64_t last_ts, int lsb_bits){ |
466 | 757 int64_t mask = lsb_bits < 64 ? (1LL<<lsb_bits)-1 : -1LL; |
464 | 758 int64_t delta= last_ts - mask/2; |
759 return ((lsb - delta)&mask) + delta; | |
760 } | |
761 | |
885 | 762 static void compute_pkt_fields(AVFormatContext *s, AVStream *st, |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
763 AVCodecParserContext *pc, AVPacket *pkt) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
764 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
765 int num, den, presentation_delayed; |
464 | 766 /* handle wrapping */ |
468 | 767 if(st->cur_dts != AV_NOPTS_VALUE){ |
768 if(pkt->pts != AV_NOPTS_VALUE) | |
769 pkt->pts= lsb2full(pkt->pts, st->cur_dts, st->pts_wrap_bits); | |
770 if(pkt->dts != AV_NOPTS_VALUE) | |
771 pkt->dts= lsb2full(pkt->dts, st->cur_dts, st->pts_wrap_bits); | |
772 } | |
885 | 773 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
774 if (pkt->duration == 0) { |
470 | 775 compute_frame_duration(&num, &den, st, pc, pkt); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
776 if (den && num) { |
464 | 777 pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
778 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
779 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
780 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
781 if(is_intra_only(st->codec)) |
570
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
782 pkt->flags |= PKT_FLAG_KEY; |
d82ccc7cff1c
set keyframe flag at a more central place instead of in every demuxer for containers which only store intra only streams
michael
parents:
563
diff
changeset
|
783 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
784 /* do we have a video B frame ? */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
785 presentation_delayed = 0; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
786 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
787 /* XXX: need has_b_frame, but cannot get it if the codec is |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
788 not initialized */ |
885 | 789 if (( st->codec->codec_id == CODEC_ID_H264 |
790 || st->codec->has_b_frames) && | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
791 pc && pc->pict_type != FF_B_TYPE) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
792 presentation_delayed = 1; |
464 | 793 /* this may be redundant, but it shouldnt hurt */ |
794 if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts > pkt->dts) | |
795 presentation_delayed = 1; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
796 } |
885 | 797 |
468 | 798 if(st->cur_dts == AV_NOPTS_VALUE){ |
799 if(presentation_delayed) st->cur_dts = -pkt->duration; | |
800 else st->cur_dts = 0; | |
801 } | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
802 |
470 | 803 // av_log(NULL, AV_LOG_DEBUG, "IN delayed:%d pts:%lld, dts:%lld cur_dts:%lld st:%d pc:%p\n", presentation_delayed, pkt->pts, pkt->dts, st->cur_dts, pkt->stream_index, pc); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
804 /* interpolate PTS and DTS if they are not present */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
805 if (presentation_delayed) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
806 /* DTS = decompression time stamp */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
807 /* PTS = presentation time stamp */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
808 if (pkt->dts == AV_NOPTS_VALUE) { |
464 | 809 /* if we know the last pts, use it */ |
810 if(st->last_IP_pts != AV_NOPTS_VALUE) | |
811 st->cur_dts = pkt->dts = st->last_IP_pts; | |
812 else | |
813 pkt->dts = st->cur_dts; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
814 } else { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
815 st->cur_dts = pkt->dts; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
816 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
817 /* this is tricky: the dts must be incremented by the duration |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
818 of the frame we are displaying, i.e. the last I or P frame */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
819 if (st->last_IP_duration == 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
820 st->cur_dts += pkt->duration; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
821 else |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
822 st->cur_dts += st->last_IP_duration; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
823 st->last_IP_duration = pkt->duration; |
464 | 824 st->last_IP_pts= pkt->pts; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
825 /* cannot compute PTS if not present (we can compute it only |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
826 by knowing the futur */ |
666
ffad4fdbd3d1
dont predict missing timestamps if we lack the required information to do so
michael
parents:
662
diff
changeset
|
827 } else if(pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE || pkt->duration){ |
618 | 828 if(pkt->pts != AV_NOPTS_VALUE && pkt->duration){ |
829 int64_t old_diff= ABS(st->cur_dts - pkt->duration - pkt->pts); | |
830 int64_t new_diff= ABS(st->cur_dts - pkt->pts); | |
831 if(old_diff < new_diff && old_diff < (pkt->duration>>3)){ | |
832 pkt->pts += pkt->duration; | |
624 | 833 // av_log(NULL, AV_LOG_DEBUG, "id:%d old:%Ld new:%Ld dur:%d cur:%Ld size:%d\n", pkt->stream_index, old_diff, new_diff, pkt->duration, st->cur_dts, pkt->size); |
618 | 834 } |
835 } | |
885 | 836 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
837 /* presentation is not delayed : PTS and DTS are the same */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
838 if (pkt->pts == AV_NOPTS_VALUE) { |
367
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
839 if (pkt->dts == AV_NOPTS_VALUE) { |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
840 pkt->pts = st->cur_dts; |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
841 pkt->dts = st->cur_dts; |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
842 } |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
843 else { |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
844 st->cur_dts = pkt->dts; |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
845 pkt->pts = pkt->dts; |
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
354
diff
changeset
|
846 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
847 } else { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
848 st->cur_dts = pkt->pts; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
849 pkt->dts = pkt->pts; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
850 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
851 st->cur_dts += pkt->duration; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
852 } |
468 | 853 // av_log(NULL, AV_LOG_DEBUG, "OUTdelayed:%d pts:%lld, dts:%lld cur_dts:%lld\n", presentation_delayed, pkt->pts, pkt->dts, st->cur_dts); |
885 | 854 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
855 /* update flags */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
856 if (pc) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
857 pkt->flags = 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
858 /* key frame computation */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
859 switch(st->codec->codec_type) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
860 case CODEC_TYPE_VIDEO: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
861 if (pc->pict_type == FF_I_TYPE) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
862 pkt->flags |= PKT_FLAG_KEY; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
863 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
864 case CODEC_TYPE_AUDIO: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
865 pkt->flags |= PKT_FLAG_KEY; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
866 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
867 default: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
868 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
869 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
870 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
871 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
872 |
535 | 873 void av_destruct_packet_nofree(AVPacket *pkt) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
874 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
875 pkt->data = NULL; pkt->size = 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
876 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
877 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
878 static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
879 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
880 AVStream *st; |
333 | 881 int len, ret, i; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
882 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
883 for(;;) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
884 /* select current input stream component */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
885 st = s->cur_st; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
886 if (st) { |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
887 if (!st->need_parsing || !st->parser) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
888 /* no parsing needed: we just output the packet as is */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
889 /* raw data support */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
890 *pkt = s->cur_pkt; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
891 compute_pkt_fields(s, st, NULL, pkt); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
892 s->cur_st = NULL; |
1244 | 893 break; |
708 | 894 } else if (s->cur_len > 0 && st->discard < AVDISCARD_ALL) { |
885 | 895 len = av_parser_parse(st->parser, st->codec, &pkt->data, &pkt->size, |
334
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
896 s->cur_ptr, s->cur_len, |
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
897 s->cur_pkt.pts, s->cur_pkt.dts); |
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
898 s->cur_pkt.pts = AV_NOPTS_VALUE; |
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
899 s->cur_pkt.dts = AV_NOPTS_VALUE; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
900 /* increment read pointer */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
901 s->cur_ptr += len; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
902 s->cur_len -= len; |
885 | 903 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
904 /* return packet if any */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
905 if (pkt->size) { |
333 | 906 got_packet: |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
907 pkt->duration = 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
908 pkt->stream_index = st->index; |
334
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
909 pkt->pts = st->parser->pts; |
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
910 pkt->dts = st->parser->dts; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
911 pkt->destruct = av_destruct_packet_nofree; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
912 compute_pkt_fields(s, st, st->parser, pkt); |
1244 | 913 break; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
914 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
915 } else { |
319 | 916 /* free packet */ |
885 | 917 av_free_packet(&s->cur_pkt); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
918 s->cur_st = NULL; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
919 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
920 } else { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
921 /* read next packet */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
922 ret = av_read_packet(s, &s->cur_pkt); |
333 | 923 if (ret < 0) { |
924 if (ret == -EAGAIN) | |
925 return ret; | |
926 /* return the last frames, if any */ | |
927 for(i = 0; i < s->nb_streams; i++) { | |
928 st = s->streams[i]; | |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
929 if (st->parser && st->need_parsing) { |
885 | 930 av_parser_parse(st->parser, st->codec, |
931 &pkt->data, &pkt->size, | |
932 NULL, 0, | |
334
7f089db11f9a
fixed incorrect PTS/DTS logic in MPEG video case (caused rare PTS glitches if start codes were between two PES packets)
bellard
parents:
333
diff
changeset
|
933 AV_NOPTS_VALUE, AV_NOPTS_VALUE); |
333 | 934 if (pkt->size) |
935 goto got_packet; | |
936 } | |
937 } | |
938 /* no more packets: really terminates parsing */ | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
939 return ret; |
333 | 940 } |
885 | 941 |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
942 st = s->streams[s->cur_pkt.stream_index]; |
1244 | 943 if(st->codec->debug & FF_DEBUG_PTS) |
944 av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%lld, dts=%lld, size=%d\n", | |
945 s->cur_pkt.stream_index, | |
946 s->cur_pkt.pts, | |
947 s->cur_pkt.dts, | |
948 s->cur_pkt.size); | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
949 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
950 s->cur_st = st; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
951 s->cur_ptr = s->cur_pkt.data; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
952 s->cur_len = s->cur_pkt.size; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
953 if (st->need_parsing && !st->parser) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
954 st->parser = av_parser_init(st->codec->codec_id); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
955 if (!st->parser) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
956 /* no parser available : just output the raw packets */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
957 st->need_parsing = 0; |
842 | 958 }else if(st->need_parsing == 2){ |
959 st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
960 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
961 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
962 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
963 } |
1244 | 964 if(st->codec->debug & FF_DEBUG_PTS) |
965 av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%lld, dts=%lld, size=%d\n", | |
966 pkt->stream_index, | |
967 pkt->pts, | |
968 pkt->dts, | |
969 pkt->size); | |
970 | |
971 return 0; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
972 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
973 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
974 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
975 * Return the next frame of a stream. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
976 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
977 * The returned packet is valid |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
978 * until the next av_read_frame() or until av_close_input_file() and |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
979 * must be freed with av_free_packet. For video, the packet contains |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
980 * exactly one frame. For audio, it contains an integer number of |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
981 * frames if each frame has a known fixed size (e.g. PCM or ADPCM |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
982 * data). If the audio frames have a variable size (e.g. MPEG audio), |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
983 * then it contains one frame. |
885 | 984 * |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
985 * pkt->pts, pkt->dts and pkt->duration are always set to correct |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
986 * values in AV_TIME_BASE unit (and guessed if the format cannot |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
987 * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
988 * has B frames, so it is better to rely on pkt->dts if you do not |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
989 * decompress the payload. |
885 | 990 * |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
991 * @return 0 if OK, < 0 if error or end of file. |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
992 */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
993 int av_read_frame(AVFormatContext *s, AVPacket *pkt) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
994 { |
0 | 995 AVPacketList *pktl; |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
996 int eof=0; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
997 const int genpts= s->flags & AVFMT_FLAG_GENPTS; |
0 | 998 |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
999 for(;;){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1000 pktl = s->packet_buffer; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1001 if (pktl) { |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1002 AVPacket *next_pkt= &pktl->pkt; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1003 |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1004 if(genpts && next_pkt->dts != AV_NOPTS_VALUE){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1005 while(pktl && next_pkt->pts == AV_NOPTS_VALUE){ |
885 | 1006 if( pktl->pkt.stream_index == next_pkt->stream_index |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1007 && next_pkt->dts < pktl->pkt.dts |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1008 && pktl->pkt.pts != pktl->pkt.dts //not b frame |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1009 /*&& pktl->pkt.dts != AV_NOPTS_VALUE*/){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1010 next_pkt->pts= pktl->pkt.dts; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1011 } |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1012 pktl= pktl->next; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1013 } |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1014 pktl = s->packet_buffer; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1015 } |
885 | 1016 |
1017 if( next_pkt->pts != AV_NOPTS_VALUE | |
1018 || next_pkt->dts == AV_NOPTS_VALUE | |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1019 || !genpts || eof){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1020 /* read packet from packet buffer, if there is data */ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1021 *pkt = *next_pkt; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1022 s->packet_buffer = pktl->next; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1023 av_free(pktl); |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1024 return 0; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1025 } |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1026 } |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1027 if(genpts){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1028 AVPacketList **plast_pktl= &s->packet_buffer; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1029 int ret= av_read_frame_internal(s, pkt); |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1030 if(ret<0){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1031 if(pktl && ret != -EAGAIN){ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1032 eof=1; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1033 continue; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1034 }else |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1035 return ret; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1036 } |
885 | 1037 |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1038 /* duplicate the packet */ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1039 if (av_dup_packet(pkt) < 0) |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1040 return AVERROR_NOMEM; |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1041 |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1042 while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last? |
885 | 1043 |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1044 pktl = av_mallocz(sizeof(AVPacketList)); |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1045 if (!pktl) |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1046 return AVERROR_NOMEM; |
885 | 1047 |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1048 /* add the packet in the buffered packet list */ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1049 *plast_pktl = pktl; |
885 | 1050 pktl->pkt= *pkt; |
841
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1051 }else{ |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1052 assert(!s->packet_buffer); |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1053 return av_read_frame_internal(s, pkt); |
ba7631ba33a7
support fixing missing pts by parsing future frames
michael
parents:
840
diff
changeset
|
1054 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1055 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1056 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1057 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1058 /* XXX: suppress the packet queue */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1059 static void flush_packet_queue(AVFormatContext *s) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1060 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1061 AVPacketList *pktl; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1062 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1063 for(;;) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1064 pktl = s->packet_buffer; |
885 | 1065 if (!pktl) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1066 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1067 s->packet_buffer = pktl->next; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1068 av_free_packet(&pktl->pkt); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1069 av_free(pktl); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1070 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1071 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1072 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1073 /*******************************************************/ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1074 /* seek support */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1075 |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1076 int av_find_default_stream_index(AVFormatContext *s) |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1077 { |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1078 int i; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1079 AVStream *st; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1080 |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1081 if (s->nb_streams <= 0) |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1082 return -1; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1083 for(i = 0; i < s->nb_streams; i++) { |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1084 st = s->streams[i]; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1085 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1086 return i; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1087 } |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1088 } |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1089 return 0; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1090 } |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1091 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1092 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1093 * Flush the frame reader. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1094 */ |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1095 static void av_read_frame_flush(AVFormatContext *s) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1096 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1097 AVStream *st; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1098 int i; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1099 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1100 flush_packet_queue(s); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1101 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1102 /* free previous packet */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1103 if (s->cur_st) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1104 if (s->cur_st->parser) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1105 av_free_packet(&s->cur_pkt); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1106 s->cur_st = NULL; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1107 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1108 /* fail safe */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1109 s->cur_ptr = NULL; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1110 s->cur_len = 0; |
885 | 1111 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1112 /* for each stream, reset read state */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1113 for(i = 0; i < s->nb_streams; i++) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1114 st = s->streams[i]; |
885 | 1115 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1116 if (st->parser) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1117 av_parser_close(st->parser); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1118 st->parser = NULL; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1119 } |
464 | 1120 st->last_IP_pts = AV_NOPTS_VALUE; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1121 st->cur_dts = 0; /* we set the current DTS to an unspecified origin */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1122 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1123 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1124 |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1125 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1126 * Updates cur_dts of all streams based on given timestamp and AVStream. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1127 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1128 * Stream ref_st unchanged, others set cur_dts in their native timebase |
572
640706a29efb
bug in libavformat av_update_cur_dts(), patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
570
diff
changeset
|
1129 * only needed for timestamp wrapping or if (dts not set and pts!=dts) |
640706a29efb
bug in libavformat av_update_cur_dts(), patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
570
diff
changeset
|
1130 * @param timestamp new dts expressed in time_base of param ref_st |
640706a29efb
bug in libavformat av_update_cur_dts(), patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
570
diff
changeset
|
1131 * @param ref_st reference stream giving time_base of param timestamp |
560 | 1132 */ |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
1133 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ |
560 | 1134 int i; |
1135 | |
1136 for(i = 0; i < s->nb_streams; i++) { | |
572
640706a29efb
bug in libavformat av_update_cur_dts(), patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
570
diff
changeset
|
1137 AVStream *st = s->streams[i]; |
560 | 1138 |
885 | 1139 st->cur_dts = av_rescale(timestamp, |
572
640706a29efb
bug in libavformat av_update_cur_dts(), patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
570
diff
changeset
|
1140 st->time_base.den * (int64_t)ref_st->time_base.num, |
640706a29efb
bug in libavformat av_update_cur_dts(), patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
570
diff
changeset
|
1141 st->time_base.num * (int64_t)ref_st->time_base.den); |
560 | 1142 } |
1143 } | |
1144 | |
1145 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1146 * Add a index entry into a sorted list updateing if it is already there. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1147 * |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1148 * @param timestamp timestamp in the timebase of the given stream |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1149 */ |
354
6770ca07abe2
store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents:
346
diff
changeset
|
1150 int av_add_index_entry(AVStream *st, |
979 | 1151 int64_t pos, int64_t timestamp, int size, int distance, int flags) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1152 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1153 AVIndexEntry *entries, *ie; |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1154 int index; |
885 | 1155 |
639 | 1156 if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) |
1157 return -1; | |
885 | 1158 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1159 entries = av_fast_realloc(st->index_entries, |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1160 &st->index_entries_allocated_size, |
885 | 1161 (st->nb_index_entries + 1) * |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1162 sizeof(AVIndexEntry)); |
639 | 1163 if(!entries) |
1164 return -1; | |
1165 | |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1166 st->index_entries= entries; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1167 |
698 | 1168 index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY); |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1169 |
555 | 1170 if(index<0){ |
354
6770ca07abe2
store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents:
346
diff
changeset
|
1171 index= st->nb_index_entries++; |
6770ca07abe2
store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents:
346
diff
changeset
|
1172 ie= &entries[index]; |
555 | 1173 assert(index==0 || ie[-1].timestamp < timestamp); |
1174 }else{ | |
1175 ie= &entries[index]; | |
1176 if(ie->timestamp != timestamp){ | |
563
d141aa45ca86
fix assertion failure in case of timestamp discontinuities
michael
parents:
560
diff
changeset
|
1177 if(ie->timestamp <= timestamp) |
d141aa45ca86
fix assertion failure in case of timestamp discontinuities
michael
parents:
560
diff
changeset
|
1178 return -1; |
555 | 1179 memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index)); |
1180 st->nb_index_entries++; | |
1181 }else if(ie->pos == pos && distance < ie->min_distance) //dont reduce the distance | |
1182 distance= ie->min_distance; | |
354
6770ca07abe2
store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents:
346
diff
changeset
|
1183 } |
555 | 1184 |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1185 ie->pos = pos; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1186 ie->timestamp = timestamp; |
354
6770ca07abe2
store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents:
346
diff
changeset
|
1187 ie->min_distance= distance; |
979 | 1188 ie->size= size; |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1189 ie->flags = flags; |
885 | 1190 |
354
6770ca07abe2
store searched distance in index, so we dont waste time searching for keyframes where we already searched
michael
parents:
346
diff
changeset
|
1191 return index; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1192 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1193 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1194 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1195 * build an index for raw streams using a parser. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1196 */ |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1197 static void av_build_index_raw(AVFormatContext *s) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1198 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1199 AVPacket pkt1, *pkt = &pkt1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1200 int ret; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1201 AVStream *st; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1202 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1203 st = s->streams[0]; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1204 av_read_frame_flush(s); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1205 url_fseek(&s->pb, s->data_offset, SEEK_SET); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1206 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1207 for(;;) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1208 ret = av_read_frame(s, pkt); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1209 if (ret < 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1210 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1211 if (pkt->stream_index == 0 && st->parser && |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1212 (pkt->flags & PKT_FLAG_KEY)) { |
885 | 1213 av_add_index_entry(st, st->parser->frame_offset, pkt->dts, |
979 | 1214 0, 0, AVINDEX_KEYFRAME); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1215 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1216 av_free_packet(pkt); |
0 | 1217 } |
1218 } | |
1219 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1220 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1221 * Returns TRUE if we deal with a raw stream. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1222 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1223 * Raw codec data and parsing needed. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1224 */ |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1225 static int is_raw_stream(AVFormatContext *s) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1226 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1227 AVStream *st; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1228 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1229 if (s->nb_streams != 1) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1230 return 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1231 st = s->streams[0]; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1232 if (!st->need_parsing) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1233 return 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1234 return 1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1235 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1236 |
555 | 1237 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1238 * Gets the index for a specific timestamp. |
885 | 1239 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to |
1240 * the timestamp which is <= the requested one, if backward is 0 | |
555 | 1241 * then it will be >= |
698 | 1242 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise |
555 | 1243 * @return < 0 if no such timestamp could be found |
1244 */ | |
597
d814669d2c13
int / int64 fix by (Wolfram Gloger <wmglo @@@ dent:med:uni-muenchen:de>)
michael
parents:
588
diff
changeset
|
1245 int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, |
698 | 1246 int flags) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1247 { |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1248 AVIndexEntry *entries= st->index_entries; |
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1249 int nb_entries= st->nb_index_entries; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1250 int a, b, m; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1251 int64_t timestamp; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1252 |
555 | 1253 a = - 1; |
1254 b = nb_entries; | |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1255 |
555 | 1256 while (b - a > 1) { |
1257 m = (a + b) >> 1; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1258 timestamp = entries[m].timestamp; |
555 | 1259 if(timestamp >= wanted_timestamp) |
1260 b = m; | |
1261 if(timestamp <= wanted_timestamp) | |
346
e154eb1b7149
caching of timestamps for mpeg-ps so seeking is faster
michael
parents:
334
diff
changeset
|
1262 a = m; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1263 } |
698 | 1264 m= (flags & AVSEEK_FLAG_BACKWARD) ? a : b; |
885 | 1265 |
698 | 1266 if(!(flags & AVSEEK_FLAG_ANY)){ |
1267 while(m>=0 && m<nb_entries && !(entries[m].flags & AVINDEX_KEYFRAME)){ | |
1268 m += (flags & AVSEEK_FLAG_BACKWARD) ? -1 : 1; | |
1269 } | |
1270 } | |
555 | 1271 |
885 | 1272 if(m == nb_entries) |
555 | 1273 return -1; |
1274 return m; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1275 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1276 |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1277 #define DEBUG_SEEK |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1278 |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1279 /** |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1280 * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp(). |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1281 * this isnt supposed to be called directly by a user application, but by demuxers |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1282 * @param target_ts target timestamp in the time base of the given stream |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1283 * @param stream_index stream number |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1284 */ |
555 | 1285 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1286 AVInputFormat *avif= s->iformat; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1287 int64_t pos_min, pos_max, pos, pos_limit; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1288 int64_t ts_min, ts_max, ts; |
810
2a84386ed2a8
avformat/av_seek_frame_binary with growing file patch by (Kenneth Aafly: kenneth, aafloy net)
michael
parents:
809
diff
changeset
|
1289 int64_t start_pos, filesize; |
560 | 1290 int index, no_change; |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1291 AVStream *st; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1292 |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1293 if (stream_index < 0) |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1294 return -1; |
885 | 1295 |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1296 #ifdef DEBUG_SEEK |
881 | 1297 av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts); |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1298 #endif |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1299 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1300 ts_max= |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1301 ts_min= AV_NOPTS_VALUE; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1302 pos_limit= -1; //gcc falsely says it may be uninitalized |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1303 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1304 st= s->streams[stream_index]; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1305 if(st->index_entries){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1306 AVIndexEntry *e; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1307 |
698 | 1308 index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); //FIXME whole func must be checked for non keyframe entries in index case, especially read_timestamp() |
555 | 1309 index= FFMAX(index, 0); |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1310 e= &st->index_entries[index]; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1311 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1312 if(e->timestamp <= target_ts || e->pos == e->min_distance){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1313 pos_min= e->pos; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1314 ts_min= e->timestamp; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1315 #ifdef DEBUG_SEEK |
885 | 1316 av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n", |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1317 pos_min,ts_min); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1318 #endif |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1319 }else{ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1320 assert(index==0); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1321 } |
885 | 1322 |
1323 index= av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD); | |
698 | 1324 assert(index < st->nb_index_entries); |
1325 if(index >= 0){ | |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1326 e= &st->index_entries[index]; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1327 assert(e->timestamp >= target_ts); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1328 pos_max= e->pos; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1329 ts_max= e->timestamp; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1330 pos_limit= pos_max - e->min_distance; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1331 #ifdef DEBUG_SEEK |
885 | 1332 av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n", |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1333 pos_max,pos_limit, ts_max); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1334 #endif |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1335 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1336 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1337 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1338 if(ts_min == AV_NOPTS_VALUE){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1339 pos_min = s->data_offset; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1340 ts_min = avif->read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1341 if (ts_min == AV_NOPTS_VALUE) |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1342 return -1; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1343 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1344 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1345 if(ts_max == AV_NOPTS_VALUE){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1346 int step= 1024; |
810
2a84386ed2a8
avformat/av_seek_frame_binary with growing file patch by (Kenneth Aafly: kenneth, aafloy net)
michael
parents:
809
diff
changeset
|
1347 filesize = url_fsize(&s->pb); |
2a84386ed2a8
avformat/av_seek_frame_binary with growing file patch by (Kenneth Aafly: kenneth, aafloy net)
michael
parents:
809
diff
changeset
|
1348 pos_max = filesize - 1; |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1349 do{ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1350 pos_max -= step; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1351 ts_max = avif->read_timestamp(s, stream_index, &pos_max, pos_max + step); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1352 step += step; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1353 }while(ts_max == AV_NOPTS_VALUE && pos_max >= step); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1354 if (ts_max == AV_NOPTS_VALUE) |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1355 return -1; |
885 | 1356 |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1357 for(;;){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1358 int64_t tmp_pos= pos_max + 1; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1359 int64_t tmp_ts= avif->read_timestamp(s, stream_index, &tmp_pos, INT64_MAX); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1360 if(tmp_ts == AV_NOPTS_VALUE) |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1361 break; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1362 ts_max= tmp_ts; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1363 pos_max= tmp_pos; |
810
2a84386ed2a8
avformat/av_seek_frame_binary with growing file patch by (Kenneth Aafly: kenneth, aafloy net)
michael
parents:
809
diff
changeset
|
1364 if(tmp_pos >= filesize) |
2a84386ed2a8
avformat/av_seek_frame_binary with growing file patch by (Kenneth Aafly: kenneth, aafloy net)
michael
parents:
809
diff
changeset
|
1365 break; |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1366 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1367 pos_limit= pos_max; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1368 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1369 |
926 | 1370 if(ts_min > ts_max){ |
1371 return -1; | |
1372 }else if(ts_min == ts_max){ | |
1373 pos_limit= pos_min; | |
1374 } | |
1375 | |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1376 no_change=0; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1377 while (pos_min < pos_limit) { |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1378 #ifdef DEBUG_SEEK |
885 | 1379 av_log(s, AV_LOG_DEBUG, "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%"PRId64" dts_max=%"PRId64"\n", |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1380 pos_min, pos_max, |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1381 ts_min, ts_max); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1382 #endif |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1383 assert(pos_limit <= pos_max); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1384 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1385 if(no_change==0){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1386 int64_t approximate_keyframe_distance= pos_max - pos_limit; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1387 // interpolate position (better than dichotomy) |
555 | 1388 pos = av_rescale(target_ts - ts_min, pos_max - pos_min, ts_max - ts_min) |
1389 + pos_min - approximate_keyframe_distance; | |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1390 }else if(no_change==1){ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1391 // bisection, if interpolation failed to change min or max pos last time |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1392 pos = (pos_min + pos_limit)>>1; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1393 }else{ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1394 // linear search if bisection failed, can only happen if there are very few or no keframes between min/max |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1395 pos=pos_min; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1396 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1397 if(pos <= pos_min) |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1398 pos= pos_min + 1; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1399 else if(pos > pos_limit) |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1400 pos= pos_limit; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1401 start_pos= pos; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1402 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1403 ts = avif->read_timestamp(s, stream_index, &pos, INT64_MAX); //may pass pos_limit instead of -1 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1404 if(pos == pos_max) |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1405 no_change++; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1406 else |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1407 no_change=0; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1408 #ifdef DEBUG_SEEK |
881 | 1409 av_log(s, AV_LOG_DEBUG, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, pos_limit, start_pos, no_change); |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1410 #endif |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1411 assert(ts != AV_NOPTS_VALUE); |
555 | 1412 if (target_ts <= ts) { |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1413 pos_limit = start_pos - 1; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1414 pos_max = pos; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1415 ts_max = ts; |
555 | 1416 } |
1417 if (target_ts >= ts) { | |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1418 pos_min = pos; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1419 ts_min = ts; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1420 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1421 } |
885 | 1422 |
555 | 1423 pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; |
1424 ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max; | |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1425 #ifdef DEBUG_SEEK |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1426 pos_min = pos; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1427 ts_min = avif->read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1428 pos_min++; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1429 ts_max = avif->read_timestamp(s, stream_index, &pos_min, INT64_MAX); |
885 | 1430 av_log(s, AV_LOG_DEBUG, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n", |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1431 pos, ts_min, target_ts, ts_max); |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1432 #endif |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1433 /* do the seek */ |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1434 url_fseek(&s->pb, pos, SEEK_SET); |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1435 |
560 | 1436 av_update_cur_dts(s, st, ts); |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1437 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1438 return 0; |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1439 } |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1440 |
555 | 1441 static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){ |
1442 int64_t pos_min, pos_max; | |
1443 #if 0 | |
1444 AVStream *st; | |
1445 | |
1446 if (stream_index < 0) | |
1447 return -1; | |
1448 | |
1449 st= s->streams[stream_index]; | |
1450 #endif | |
1451 | |
1452 pos_min = s->data_offset; | |
764
cdb845a57ae4
drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol)
aurel
parents:
757
diff
changeset
|
1453 pos_max = url_fsize(&s->pb) - 1; |
555 | 1454 |
1455 if (pos < pos_min) pos= pos_min; | |
1456 else if(pos > pos_max) pos= pos_max; | |
1457 | |
1458 url_fseek(&s->pb, pos, SEEK_SET); | |
1459 | |
1460 #if 0 | |
560 | 1461 av_update_cur_dts(s, st, ts); |
555 | 1462 #endif |
1463 return 0; | |
1464 } | |
1465 | |
885 | 1466 static int av_seek_frame_generic(AVFormatContext *s, |
555 | 1467 int stream_index, int64_t timestamp, int flags) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1468 { |
560 | 1469 int index; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1470 AVStream *st; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1471 AVIndexEntry *ie; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1472 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1473 if (!s->index_built) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1474 if (is_raw_stream(s)) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1475 av_build_index_raw(s); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1476 } else { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1477 return -1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1478 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1479 s->index_built = 1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1480 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1481 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1482 st = s->streams[stream_index]; |
698 | 1483 index = av_index_search_timestamp(st, timestamp, flags); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1484 if (index < 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1485 return -1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1486 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1487 /* now we have found the index, we can seek */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1488 ie = &st->index_entries[index]; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1489 av_read_frame_flush(s); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1490 url_fseek(&s->pb, ie->pos, SEEK_SET); |
555 | 1491 |
560 | 1492 av_update_cur_dts(s, st, ie->timestamp); |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1493 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1494 return 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1495 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1496 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1497 /** |
555 | 1498 * Seek to the key frame at timestamp. |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1499 * 'timestamp' in 'stream_index'. |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1500 * @param stream_index If stream_index is (-1), a default |
885 | 1501 * stream is selected, and timestamp is automatically converted |
557
084de726b4d0
default stream timebase docs patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
556
diff
changeset
|
1502 * from AV_TIME_BASE units to the stream specific time_base. |
555 | 1503 * @param timestamp timestamp in AVStream.time_base units |
809 | 1504 * or if there is no stream specified then in AV_TIME_BASE units |
555 | 1505 * @param flags flags which select direction and seeking mode |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1506 * @return >= 0 on success |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1507 */ |
555 | 1508 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1509 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1510 int ret; |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1511 AVStream *st; |
885 | 1512 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1513 av_read_frame_flush(s); |
885 | 1514 |
555 | 1515 if(flags & AVSEEK_FLAG_BYTE) |
1516 return av_seek_frame_byte(s, stream_index, timestamp, flags); | |
885 | 1517 |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1518 if(stream_index < 0){ |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1519 stream_index= av_find_default_stream_index(s); |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1520 if(stream_index < 0) |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1521 return -1; |
885 | 1522 |
555 | 1523 st= s->streams[stream_index]; |
557
084de726b4d0
default stream timebase docs patch by (Nathan Kurz <nate at verse dot com>)
michael
parents:
556
diff
changeset
|
1524 /* timestamp for default must be expressed in AV_TIME_BASE units */ |
555 | 1525 timestamp = av_rescale(timestamp, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1526 } |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1527 st= s->streams[stream_index]; |
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1528 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1529 /* first, we try the format specific seek */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1530 if (s->iformat->read_seek) |
555 | 1531 ret = s->iformat->read_seek(s, stream_index, timestamp, flags); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1532 else |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1533 ret = -1; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1534 if (ret >= 0) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1535 return 0; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1536 } |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1537 |
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1538 if(s->iformat->read_timestamp) |
555 | 1539 return av_seek_frame_binary(s, stream_index, timestamp, flags); |
437
50bae308f71e
moving nearly identical binary search code from nut/mpeg/asf to utils.c
michael
parents:
425
diff
changeset
|
1540 else |
555 | 1541 return av_seek_frame_generic(s, stream_index, timestamp, flags); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1542 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1543 |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
1544 /*******************************************************/ |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1545 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1546 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1547 * Returns TRUE if the stream has accurate timings in any stream. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1548 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1549 * @return TRUE if the stream has accurate timings for at least one component. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1550 */ |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1551 static int av_has_timings(AVFormatContext *ic) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1552 { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1553 int i; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1554 AVStream *st; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1555 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1556 for(i = 0;i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1557 st = ic->streams[i]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1558 if (st->start_time != AV_NOPTS_VALUE && |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1559 st->duration != AV_NOPTS_VALUE) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1560 return 1; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1561 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1562 return 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1563 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1564 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1565 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1566 * Estimate the stream timings from the one of each components. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1567 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1568 * Also computes the global bitrate if possible. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
1569 */ |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1570 static void av_update_stream_timings(AVFormatContext *ic) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1571 { |
743 | 1572 int64_t start_time, start_time1, end_time, end_time1; |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1573 int i; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1574 AVStream *st; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1575 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1576 start_time = MAXINT64; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1577 end_time = MININT64; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1578 for(i = 0;i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1579 st = ic->streams[i]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1580 if (st->start_time != AV_NOPTS_VALUE) { |
743 | 1581 start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q); |
1582 if (start_time1 < start_time) | |
1583 start_time = start_time1; | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1584 if (st->duration != AV_NOPTS_VALUE) { |
743 | 1585 end_time1 = start_time1 |
1586 + av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q); | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1587 if (end_time1 > end_time) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1588 end_time = end_time1; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1589 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1590 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1591 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1592 if (start_time != MAXINT64) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1593 ic->start_time = start_time; |
786 | 1594 if (end_time != MININT64) { |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1595 ic->duration = end_time - start_time; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1596 if (ic->file_size > 0) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1597 /* compute the bit rate */ |
885 | 1598 ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1599 (double)ic->duration; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1600 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1601 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1602 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1603 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1604 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1605 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1606 static void fill_all_stream_timings(AVFormatContext *ic) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1607 { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1608 int i; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1609 AVStream *st; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1610 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1611 av_update_stream_timings(ic); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1612 for(i = 0;i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1613 st = ic->streams[i]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1614 if (st->start_time == AV_NOPTS_VALUE) { |
743 | 1615 if(ic->start_time != AV_NOPTS_VALUE) |
1616 st->start_time = av_rescale_q(ic->start_time, AV_TIME_BASE_Q, st->time_base); | |
1617 if(ic->duration != AV_NOPTS_VALUE) | |
1618 st->duration = av_rescale_q(ic->duration, AV_TIME_BASE_Q, st->time_base); | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1619 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1620 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1621 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1622 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1623 static void av_estimate_timings_from_bit_rate(AVFormatContext *ic) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1624 { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1625 int64_t filesize, duration; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1626 int bit_rate, i; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1627 AVStream *st; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1628 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1629 /* if bit_rate is already set, we believe it */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1630 if (ic->bit_rate == 0) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1631 bit_rate = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1632 for(i=0;i<ic->nb_streams;i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1633 st = ic->streams[i]; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1634 bit_rate += st->codec->bit_rate; |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1635 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1636 ic->bit_rate = bit_rate; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1637 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1638 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1639 /* if duration is already set, we believe it */ |
885 | 1640 if (ic->duration == AV_NOPTS_VALUE && |
1641 ic->bit_rate != 0 && | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1642 ic->file_size != 0) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1643 filesize = ic->file_size; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1644 if (filesize > 0) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1645 for(i = 0; i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1646 st = ic->streams[i]; |
743 | 1647 duration= av_rescale(8*filesize, st->time_base.den, ic->bit_rate*(int64_t)st->time_base.num); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1648 if (st->start_time == AV_NOPTS_VALUE || |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1649 st->duration == AV_NOPTS_VALUE) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1650 st->start_time = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1651 st->duration = duration; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1652 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1653 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1654 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1655 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1656 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1657 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1658 #define DURATION_MAX_READ_SIZE 250000 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1659 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1660 /* only usable for MPEG-PS streams */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1661 static void av_estimate_timings_from_pts(AVFormatContext *ic) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1662 { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1663 AVPacket pkt1, *pkt = &pkt1; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1664 AVStream *st; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1665 int read_size, i, ret; |
838 | 1666 int64_t end_time; |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1667 int64_t filesize, offset, duration; |
885 | 1668 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1669 /* free previous packet */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1670 if (ic->cur_st && ic->cur_st->parser) |
885 | 1671 av_free_packet(&ic->cur_pkt); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1672 ic->cur_st = NULL; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1673 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1674 /* flush packet queue */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1675 flush_packet_queue(ic); |
488 | 1676 |
1677 for(i=0;i<ic->nb_streams;i++) { | |
1678 st = ic->streams[i]; | |
1679 if (st->parser) { | |
1680 av_parser_close(st->parser); | |
1681 st->parser= NULL; | |
1682 } | |
1683 } | |
885 | 1684 |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1685 /* we read the first packets to get the first PTS (not fully |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1686 accurate, but it is enough now) */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1687 url_fseek(&ic->pb, 0, SEEK_SET); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1688 read_size = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1689 for(;;) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1690 if (read_size >= DURATION_MAX_READ_SIZE) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1691 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1692 /* if all info is available, we can stop */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1693 for(i = 0;i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1694 st = ic->streams[i]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1695 if (st->start_time == AV_NOPTS_VALUE) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1696 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1697 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1698 if (i == ic->nb_streams) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1699 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1700 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1701 ret = av_read_packet(ic, pkt); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1702 if (ret != 0) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1703 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1704 read_size += pkt->size; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1705 st = ic->streams[pkt->stream_index]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1706 if (pkt->pts != AV_NOPTS_VALUE) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1707 if (st->start_time == AV_NOPTS_VALUE) |
743 | 1708 st->start_time = pkt->pts; |
224
8d1569be0ee1
memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents:
205
diff
changeset
|
1709 } |
8d1569be0ee1
memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents:
205
diff
changeset
|
1710 av_free_packet(pkt); |
8d1569be0ee1
memory leak fix by (Tom Dexter <devel at www dot digitalaudiorock dot com>)
michaelni
parents:
205
diff
changeset
|
1711 } |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1712 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1713 /* estimate the end time (duration) */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1714 /* XXX: may need to support wrapping */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1715 filesize = ic->file_size; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1716 offset = filesize - DURATION_MAX_READ_SIZE; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1717 if (offset < 0) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1718 offset = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1719 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1720 url_fseek(&ic->pb, offset, SEEK_SET); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1721 read_size = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1722 for(;;) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1723 if (read_size >= DURATION_MAX_READ_SIZE) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1724 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1725 /* if all info is available, we can stop */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1726 for(i = 0;i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1727 st = ic->streams[i]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1728 if (st->duration == AV_NOPTS_VALUE) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1729 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1730 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1731 if (i == ic->nb_streams) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1732 break; |
885 | 1733 |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1734 ret = av_read_packet(ic, pkt); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1735 if (ret != 0) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1736 break; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1737 read_size += pkt->size; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1738 st = ic->streams[pkt->stream_index]; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1739 if (pkt->pts != AV_NOPTS_VALUE) { |
743 | 1740 end_time = pkt->pts; |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1741 duration = end_time - st->start_time; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1742 if (duration > 0) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1743 if (st->duration == AV_NOPTS_VALUE || |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1744 st->duration < duration) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1745 st->duration = duration; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1746 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1747 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1748 av_free_packet(pkt); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1749 } |
885 | 1750 |
743 | 1751 fill_all_stream_timings(ic); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1752 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1753 url_fseek(&ic->pb, 0, SEEK_SET); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1754 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1755 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1756 static void av_estimate_timings(AVFormatContext *ic) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1757 { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1758 int64_t file_size; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1759 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1760 /* get the file size, if possible */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1761 if (ic->iformat->flags & AVFMT_NOFILE) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1762 file_size = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1763 } else { |
764
cdb845a57ae4
drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol)
aurel
parents:
757
diff
changeset
|
1764 file_size = url_fsize(&ic->pb); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1765 if (file_size < 0) |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1766 file_size = 0; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1767 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1768 ic->file_size = file_size; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1769 |
1169 | 1770 if ((!strcmp(ic->iformat->name, "mpeg") || |
1771 !strcmp(ic->iformat->name, "mpegts")) && | |
1772 file_size && !ic->pb.is_streamed) { | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1773 /* get accurate estimate from the PTSes */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1774 av_estimate_timings_from_pts(ic); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1775 } else if (av_has_timings(ic)) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1776 /* at least one components has timings - we use them for all |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1777 the components */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1778 fill_all_stream_timings(ic); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1779 } else { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1780 /* less precise: use bit rate info */ |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1781 av_estimate_timings_from_bit_rate(ic); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1782 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1783 av_update_stream_timings(ic); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1784 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1785 #if 0 |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1786 { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1787 int i; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1788 AVStream *st; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1789 for(i = 0;i < ic->nb_streams; i++) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1790 st = ic->streams[i]; |
885 | 1791 printf("%d: start_time: %0.3f duration: %0.3f\n", |
1792 i, (double)st->start_time / AV_TIME_BASE, | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1793 (double)st->duration / AV_TIME_BASE); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1794 } |
885 | 1795 printf("stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n", |
1796 (double)ic->start_time / AV_TIME_BASE, | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1797 (double)ic->duration / AV_TIME_BASE, |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1798 ic->bit_rate / 1000); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1799 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1800 #endif |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1801 } |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
1802 |
0 | 1803 static int has_codec_parameters(AVCodecContext *enc) |
1804 { | |
1805 int val; | |
1806 switch(enc->codec_type) { | |
1807 case CODEC_TYPE_AUDIO: | |
1808 val = enc->sample_rate; | |
1809 break; | |
1810 case CODEC_TYPE_VIDEO: | |
737 | 1811 val = enc->width && enc->pix_fmt != PIX_FMT_NONE; |
0 | 1812 break; |
1813 default: | |
1814 val = 1; | |
1815 break; | |
1816 } | |
1817 return (val != 0); | |
1818 } | |
1819 | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1820 static int try_decode_frame(AVStream *st, const uint8_t *data, int size) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1821 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1822 int16_t *samples; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1823 AVCodec *codec; |
801
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
1824 int got_picture, ret=0; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1825 AVFrame picture; |
885 | 1826 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1827 if(!st->codec->codec){ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1828 codec = avcodec_find_decoder(st->codec->codec_id); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1829 if (!codec) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1830 return -1; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1831 ret = avcodec_open(st->codec, codec); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1832 if (ret < 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1833 return ret; |
801
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
1834 } |
737 | 1835 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1836 if(!has_codec_parameters(st->codec)){ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1837 switch(st->codec->codec_type) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1838 case CODEC_TYPE_VIDEO: |
885 | 1839 ret = avcodec_decode_video(st->codec, &picture, |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1840 &got_picture, (uint8_t *)data, size); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1841 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1842 case CODEC_TYPE_AUDIO: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1843 samples = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1844 if (!samples) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1845 goto fail; |
885 | 1846 ret = avcodec_decode_audio(st->codec, samples, |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1847 &got_picture, (uint8_t *)data, size); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1848 av_free(samples); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1849 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1850 default: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1851 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1852 } |
737 | 1853 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1854 fail: |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1855 return ret; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1856 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1857 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1858 /* absolute maximum size we read until we abort */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1859 #define MAX_READ_SIZE 5000000 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1860 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1861 /* maximum duration until we stop analysing the stream */ |
1127 | 1862 #define MAX_STREAM_DURATION ((int)(AV_TIME_BASE * 3.0)) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1863 |
0 | 1864 /** |
1865 * Read the beginning of a media file to get stream information. This | |
1866 * is useful for file formats with no headers such as MPEG. This | |
1867 * function also compute the real frame rate in case of mpeg2 repeat | |
1868 * frame mode. | |
1869 * | |
1870 * @param ic media file handle | |
885 | 1871 * @return >=0 if OK. AVERROR_xxx if error. |
737 | 1872 * @todo let user decide somehow what information is needed so we dont waste time geting stuff the user doesnt need |
0 | 1873 */ |
1874 int av_find_stream_info(AVFormatContext *ic) | |
1875 { | |
927 | 1876 int i, count, ret, read_size, j; |
0 | 1877 AVStream *st; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1878 AVPacket pkt1, *pkt; |
0 | 1879 AVPacketList *pktl=NULL, **ppktl; |
620 | 1880 int64_t last_dts[MAX_STREAMS]; |
750 | 1881 int64_t duration_sum[MAX_STREAMS]; |
1882 int duration_count[MAX_STREAMS]={0}; | |
0 | 1883 |
743 | 1884 for(i=0;i<ic->nb_streams;i++) { |
1885 st = ic->streams[i]; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1886 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ |
743 | 1887 /* if(!st->time_base.num) |
1888 st->time_base= */ | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1889 if(!st->codec->time_base.num) |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1890 st->codec->time_base= st->time_base; |
743 | 1891 } |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
1892 //only for the split stuff |
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
1893 if (!st->parser) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1894 st->parser = av_parser_init(st->codec->codec_id); |
842 | 1895 if(st->need_parsing == 2 && st->parser){ |
1896 st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; | |
1897 } | |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
1898 } |
743 | 1899 } |
1900 | |
620 | 1901 for(i=0;i<MAX_STREAMS;i++){ |
1902 last_dts[i]= AV_NOPTS_VALUE; | |
750 | 1903 duration_sum[i]= INT64_MAX; |
620 | 1904 } |
885 | 1905 |
0 | 1906 count = 0; |
1907 read_size = 0; | |
1908 ppktl = &ic->packet_buffer; | |
1909 for(;;) { | |
1910 /* check if one codec still needs to be handled */ | |
1911 for(i=0;i<ic->nb_streams;i++) { | |
1912 st = ic->streams[i]; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1913 if (!has_codec_parameters(st->codec)) |
0 | 1914 break; |
624 | 1915 /* variable fps and no guess at the real fps */ |
927 | 1916 if( st->codec->time_base.den >= 101LL*st->codec->time_base.num |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1917 && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO) |
624 | 1918 break; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1919 if(st->parser && st->parser->parser->split && !st->codec->extradata) |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
1920 break; |
0 | 1921 } |
1922 if (i == ic->nb_streams) { | |
1923 /* NOTE: if the format has no header, then we need to read | |
1924 some packets to get most of the streams, so we cannot | |
1925 stop here */ | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1926 if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) { |
0 | 1927 /* if we found the info for all the codecs, we can stop */ |
1928 ret = count; | |
1929 break; | |
1930 } | |
1931 } else { | |
1932 /* we did not get all the codec info, but we read too much data */ | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1933 if (read_size >= MAX_READ_SIZE) { |
0 | 1934 ret = count; |
1935 break; | |
1936 } | |
1937 } | |
1938 | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1939 /* NOTE: a new stream can be added there if no header in file |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1940 (AVFMTCTX_NOHEADER) */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1941 ret = av_read_frame_internal(ic, &pkt1); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1942 if (ret < 0) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1943 /* EOF or error */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1944 ret = -1; /* we could not have all the codec parameters before EOF */ |
651
6a5ba24b2c6b
fixing demuxing for short files where the framerate detection failed
michael
parents:
643
diff
changeset
|
1945 for(i=0;i<ic->nb_streams;i++) { |
6a5ba24b2c6b
fixing demuxing for short files where the framerate detection failed
michael
parents:
643
diff
changeset
|
1946 st = ic->streams[i]; |
1018
bddcb32bde33
provide more info on which streams lack codec parameters
michael
parents:
1003
diff
changeset
|
1947 if (!has_codec_parameters(st->codec)){ |
bddcb32bde33
provide more info on which streams lack codec parameters
michael
parents:
1003
diff
changeset
|
1948 char buf[256]; |
bddcb32bde33
provide more info on which streams lack codec parameters
michael
parents:
1003
diff
changeset
|
1949 avcodec_string(buf, sizeof(buf), st->codec, 0); |
bddcb32bde33
provide more info on which streams lack codec parameters
michael
parents:
1003
diff
changeset
|
1950 av_log(ic, AV_LOG_INFO, "Could not find codec parameters (%s)\n", buf); |
1139
ff241582890f
do not fail av_find_stream_info() if params for all streams could not be found
mru
parents:
1135
diff
changeset
|
1951 } else { |
ff241582890f
do not fail av_find_stream_info() if params for all streams could not be found
mru
parents:
1135
diff
changeset
|
1952 ret = 0; |
1018
bddcb32bde33
provide more info on which streams lack codec parameters
michael
parents:
1003
diff
changeset
|
1953 } |
651
6a5ba24b2c6b
fixing demuxing for short files where the framerate detection failed
michael
parents:
643
diff
changeset
|
1954 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1955 break; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1956 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1957 |
0 | 1958 pktl = av_mallocz(sizeof(AVPacketList)); |
1959 if (!pktl) { | |
1960 ret = AVERROR_NOMEM; | |
1961 break; | |
1962 } | |
1963 | |
1964 /* add the packet in the buffered packet list */ | |
1965 *ppktl = pktl; | |
1966 ppktl = &pktl->next; | |
1967 | |
1968 pkt = &pktl->pkt; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1969 *pkt = pkt1; |
885 | 1970 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1971 /* duplicate the packet */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1972 if (av_dup_packet(pkt) < 0) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1973 ret = AVERROR_NOMEM; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1974 break; |
0 | 1975 } |
1976 | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1977 read_size += pkt->size; |
0 | 1978 |
1979 st = ic->streams[pkt->stream_index]; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1980 st->codec_info_duration += pkt->duration; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1981 if (pkt->duration != 0) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1982 st->codec_info_nb_frames++; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
1983 |
772 | 1984 { |
750 | 1985 int index= pkt->stream_index; |
1986 int64_t last= last_dts[index]; | |
1987 int64_t duration= pkt->dts - last; | |
1988 | |
1989 if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>0){ | |
1990 if(duration*duration_count[index]*10/9 < duration_sum[index]){ | |
1991 duration_sum[index]= duration; | |
1992 duration_count[index]=1; | |
1993 }else{ | |
1994 int factor= av_rescale(duration, duration_count[index], duration_sum[index]); | |
1995 duration_sum[index] += duration; | |
1996 duration_count[index]+= factor; | |
1997 } | |
801
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
1998 if(st->codec_info_nb_frames == 0 && 0) |
772 | 1999 st->codec_info_duration += duration; |
620 | 2000 } |
2001 last_dts[pkt->stream_index]= pkt->dts; | |
2002 } | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2003 if(st->parser && st->parser->parser->split && !st->codec->extradata){ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2004 int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
2005 if(i){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2006 st->codec->extradata_size= i; |
1141
ef9bf68071d3
extradata may be used as bitstream reader input so allocate with padding
mru
parents:
1139
diff
changeset
|
2007 st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2008 memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size); |
1141
ef9bf68071d3
extradata may be used as bitstream reader input so allocate with padding
mru
parents:
1139
diff
changeset
|
2009 memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
797
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
2010 } |
f5a231a9a2f1
support changing in bitstream global headers into extradata style and back
michael
parents:
786
diff
changeset
|
2011 } |
885 | 2012 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2013 /* if still no information, we try to open the codec and to |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2014 decompress the frame. We try to avoid that in most cases as |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2015 it takes longer and uses more memory. For MPEG4, we need to |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2016 decompress for Quicktime. */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2017 if (!has_codec_parameters(st->codec) /*&& |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2018 (st->codec->codec_id == CODEC_ID_FLV1 || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2019 st->codec->codec_id == CODEC_ID_H264 || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2020 st->codec->codec_id == CODEC_ID_H263 || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2021 st->codec->codec_id == CODEC_ID_H261 || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2022 st->codec->codec_id == CODEC_ID_VORBIS || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2023 st->codec->codec_id == CODEC_ID_MJPEG || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2024 st->codec->codec_id == CODEC_ID_PNG || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2025 st->codec->codec_id == CODEC_ID_PAM || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2026 st->codec->codec_id == CODEC_ID_PGM || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2027 st->codec->codec_id == CODEC_ID_PGMYUV || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2028 st->codec->codec_id == CODEC_ID_PBM || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2029 st->codec->codec_id == CODEC_ID_PPM || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2030 st->codec->codec_id == CODEC_ID_SHORTEN || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2031 (st->codec->codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/) |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2032 try_decode_frame(st, pkt->data, pkt->size); |
885 | 2033 |
772 | 2034 if (av_rescale_q(st->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= MAX_STREAM_DURATION) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2035 break; |
0 | 2036 } |
2037 count++; | |
2038 } | |
2039 | |
801
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
2040 // close codecs which where opened in try_decode_frame() |
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
2041 for(i=0;i<ic->nb_streams;i++) { |
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
2042 st = ic->streams[i]; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2043 if(st->codec->codec) |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2044 avcodec_close(st->codec); |
801
bca2334ff177
dont open and close codec at every call of try_decode_frame() as this is not only slow but also fails if the previous frame is needed for setting some parameters correctly
michael
parents:
797
diff
changeset
|
2045 } |
0 | 2046 for(i=0;i<ic->nb_streams;i++) { |
2047 st = ic->streams[i]; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2048 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2049 if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_sample) |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2050 st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); |
620 | 2051 |
927 | 2052 if(duration_count[i] && st->codec->time_base.num*101LL <= st->codec->time_base.den && |
2053 st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->time_base.den){ | |
2054 int64_t num, den, error, best_error; | |
625 | 2055 |
750 | 2056 num= st->time_base.den*duration_count[i]; |
2057 den= st->time_base.num*duration_sum[i]; | |
885 | 2058 |
927 | 2059 best_error= INT64_MAX; |
2060 for(j=1; j<60*12; j++){ | |
2061 error= ABS(1001*12*num - 1001*j*den); | |
2062 if(error < best_error){ | |
2063 best_error= error; | |
2064 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, j, 12, INT_MAX); | |
2065 } | |
2066 } | |
2067 for(j=24; j<=30; j+=6){ | |
2068 error= ABS(1001*12*num - 1000*12*j*den); | |
2069 if(error < best_error){ | |
2070 best_error= error; | |
2071 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, j*1000, 1001, INT_MAX); | |
2072 } | |
750 | 2073 } |
620 | 2074 } |
2075 | |
578 | 2076 /* set real frame rate info */ |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2077 /* compute the real frame rate for telecine */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2078 if ((st->codec->codec_id == CODEC_ID_MPEG1VIDEO || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2079 st->codec->codec_id == CODEC_ID_MPEG2VIDEO) && |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2080 st->codec->sub_id == 2) { |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2081 if (st->codec_info_nb_frames >= 20) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2082 float coded_frame_rate, est_frame_rate; |
885 | 2083 est_frame_rate = ((double)st->codec_info_nb_frames * AV_TIME_BASE) / |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2084 (double)st->codec_info_duration ; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2085 coded_frame_rate = 1.0/av_q2d(st->codec->time_base); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2086 #if 0 |
885 | 2087 printf("telecine: coded_frame_rate=%0.3f est_frame_rate=%0.3f\n", |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2088 coded_frame_rate, est_frame_rate); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2089 #endif |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2090 /* if we detect that it could be a telecine, we |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2091 signal it. It would be better to do it at a |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2092 higher level as it can change in a film */ |
885 | 2093 if (coded_frame_rate >= 24.97 && |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2094 (est_frame_rate >= 23.5 && est_frame_rate < 24.5)) { |
743 | 2095 st->r_frame_rate = (AVRational){24000, 1001}; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2096 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2097 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2098 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2099 /* if no real frame rate, use the codec one */ |
743 | 2100 if (!st->r_frame_rate.num){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2101 st->r_frame_rate.num = st->codec->time_base.den; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2102 st->r_frame_rate.den = st->codec->time_base.num; |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
75
diff
changeset
|
2103 } |
0 | 2104 } |
2105 } | |
2106 | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2107 av_estimate_timings(ic); |
468 | 2108 #if 0 |
2109 /* correct DTS for b frame streams with no timestamps */ | |
2110 for(i=0;i<ic->nb_streams;i++) { | |
2111 st = ic->streams[i]; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2112 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
468 | 2113 if(b-frames){ |
2114 ppktl = &ic->packet_buffer; | |
2115 while(ppkt1){ | |
2116 if(ppkt1->stream_index != i) | |
2117 continue; | |
2118 if(ppkt1->pkt->dts < 0) | |
2119 break; | |
2120 if(ppkt1->pkt->pts != AV_NOPTS_VALUE) | |
2121 break; | |
2122 ppkt1->pkt->dts -= delta; | |
2123 ppkt1= ppkt1->next; | |
2124 } | |
2125 if(ppkt1) | |
2126 continue; | |
2127 st->cur_dts -= delta; | |
2128 } | |
2129 } | |
2130 } | |
2131 #endif | |
0 | 2132 return ret; |
2133 } | |
2134 | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2135 /*******************************************************/ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2136 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2137 /** |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2138 * start playing a network based stream (e.g. RTSP stream) at the |
885 | 2139 * current position |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2140 */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2141 int av_read_play(AVFormatContext *s) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2142 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2143 if (!s->iformat->read_play) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2144 return AVERROR_NOTSUPP; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2145 return s->iformat->read_play(s); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2146 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2147 |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2148 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2149 * Pause a network based stream (e.g. RTSP stream). |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2150 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2151 * Use av_read_play() to resume it. |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2152 */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2153 int av_read_pause(AVFormatContext *s) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2154 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2155 if (!s->iformat->read_pause) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2156 return AVERROR_NOTSUPP; |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2157 return s->iformat->read_pause(s); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2158 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2159 |
0 | 2160 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2161 * Close a media file (but not its codecs). |
0 | 2162 * |
2163 * @param s media file handle | |
2164 */ | |
2165 void av_close_input_file(AVFormatContext *s) | |
2166 { | |
172 | 2167 int i, must_open_file; |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
2168 AVStream *st; |
0 | 2169 |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2170 /* free previous packet */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2171 if (s->cur_st && s->cur_st->parser) |
885 | 2172 av_free_packet(&s->cur_pkt); |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2173 |
0 | 2174 if (s->iformat->read_close) |
2175 s->iformat->read_close(s); | |
2176 for(i=0;i<s->nb_streams;i++) { | |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
2177 /* free all data in a stream component */ |
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
2178 st = s->streams[i]; |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2179 if (st->parser) { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2180 av_parser_close(st->parser); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2181 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2182 av_free(st->index_entries); |
1120 | 2183 av_free(st->codec->extradata); |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2184 av_free(st->codec); |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
2185 av_free(st); |
0 | 2186 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
2187 flush_packet_queue(s); |
172 | 2188 must_open_file = 1; |
293
62cec412a186
make AVFMT_NOHEADER flag dynamic - added av_open_input_stream()
bellard
parents:
290
diff
changeset
|
2189 if (s->iformat->flags & AVFMT_NOFILE) { |
172 | 2190 must_open_file = 0; |
2191 } | |
2192 if (must_open_file) { | |
0 | 2193 url_fclose(&s->pb); |
2194 } | |
2195 av_freep(&s->priv_data); | |
2196 av_free(s); | |
2197 } | |
2198 | |
2199 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2200 * Add a new stream to a media file. |
0 | 2201 * |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2202 * Can only be called in the read_header() function. If the flag |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2203 * AVFMTCTX_NOHEADER is in the format context, then new streams |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2204 * can be added in read_packet too. |
0 | 2205 * |
2206 * @param s media file handle | |
885 | 2207 * @param id file format dependent stream id |
0 | 2208 */ |
2209 AVStream *av_new_stream(AVFormatContext *s, int id) | |
2210 { | |
2211 AVStream *st; | |
2212 | |
2213 if (s->nb_streams >= MAX_STREAMS) | |
2214 return NULL; | |
2215 | |
2216 st = av_mallocz(sizeof(AVStream)); | |
2217 if (!st) | |
2218 return NULL; | |
885 | 2219 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2220 st->codec= avcodec_alloc_context(); |
193 | 2221 if (s->iformat) { |
2222 /* no default bitrate if decoding */ | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2223 st->codec->bit_rate = 0; |
193 | 2224 } |
0 | 2225 st->index = s->nb_streams; |
2226 st->id = id; | |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2227 st->start_time = AV_NOPTS_VALUE; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2228 st->duration = AV_NOPTS_VALUE; |
468 | 2229 st->cur_dts = AV_NOPTS_VALUE; |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
2230 |
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
2231 /* default pts settings is MPEG like */ |
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
2232 av_set_pts_info(st, 33, 1, 90000); |
464 | 2233 st->last_IP_pts = AV_NOPTS_VALUE; |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
2234 |
0 | 2235 s->streams[s->nb_streams++] = st; |
2236 return st; | |
2237 } | |
2238 | |
2239 /************************************************************/ | |
2240 /* output media file */ | |
2241 | |
20 | 2242 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) |
2243 { | |
2244 int ret; | |
885 | 2245 |
32 | 2246 if (s->oformat->priv_data_size > 0) { |
2247 s->priv_data = av_mallocz(s->oformat->priv_data_size); | |
2248 if (!s->priv_data) | |
2249 return AVERROR_NOMEM; | |
2250 } else | |
2251 s->priv_data = NULL; | |
885 | 2252 |
20 | 2253 if (s->oformat->set_parameters) { |
2254 ret = s->oformat->set_parameters(s, ap); | |
2255 if (ret < 0) | |
2256 return ret; | |
2257 } | |
2258 return 0; | |
2259 } | |
2260 | |
0 | 2261 /** |
2262 * allocate the stream private data and write the stream header to an | |
2263 * output media file | |
2264 * | |
2265 * @param s media file handle | |
885 | 2266 * @return 0 if OK. AVERROR_xxx if error. |
0 | 2267 */ |
2268 int av_write_header(AVFormatContext *s) | |
2269 { | |
2270 int ret, i; | |
2271 AVStream *st; | |
2272 | |
839 | 2273 // some sanity checks |
2274 for(i=0;i<s->nb_streams;i++) { | |
2275 st = s->streams[i]; | |
2276 | |
2277 switch (st->codec->codec_type) { | |
2278 case CODEC_TYPE_AUDIO: | |
2279 if(st->codec->sample_rate<=0){ | |
2280 av_log(s, AV_LOG_ERROR, "sample rate not set\n"); | |
2281 return -1; | |
2282 } | |
2283 break; | |
2284 case CODEC_TYPE_VIDEO: | |
2285 if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FIXME audio too? | |
2286 av_log(s, AV_LOG_ERROR, "time base not set\n"); | |
2287 return -1; | |
2288 } | |
2289 if(st->codec->width<=0 || st->codec->height<=0){ | |
2290 av_log(s, AV_LOG_ERROR, "dimensions not set\n"); | |
2291 return -1; | |
2292 } | |
2293 break; | |
2294 } | |
2295 } | |
2296 | |
869 | 2297 if(s->oformat->write_header){ |
2298 ret = s->oformat->write_header(s); | |
2299 if (ret < 0) | |
2300 return ret; | |
2301 } | |
0 | 2302 |
2303 /* init PTS generation */ | |
2304 for(i=0;i<s->nb_streams;i++) { | |
840
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2305 int64_t den = AV_NOPTS_VALUE; |
0 | 2306 st = s->streams[i]; |
2307 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2308 switch (st->codec->codec_type) { |
0 | 2309 case CODEC_TYPE_AUDIO: |
840
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2310 den = (int64_t)st->time_base.num * st->codec->sample_rate; |
0 | 2311 break; |
2312 case CODEC_TYPE_VIDEO: | |
840
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2313 den = (int64_t)st->time_base.num * st->codec->time_base.den; |
0 | 2314 break; |
2315 default: | |
2316 break; | |
2317 } | |
840
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2318 if (den != AV_NOPTS_VALUE) { |
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2319 if (den <= 0) |
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2320 return AVERROR_INVALIDDATA; |
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2321 av_frac_init(&st->pts, 0, 0, den); |
8834d33b7ca1
minor fixes for invalid audio data patch by (Wolfram Gloger: wmglo, dent med uni-muenchen de)
michael
parents:
839
diff
changeset
|
2322 } |
0 | 2323 } |
2324 return 0; | |
2325 } | |
2326 | |
470 | 2327 //FIXME merge with compute_pkt_fields |
617
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2328 static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2329 int b_frames = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames); |
470 | 2330 int num, den, frame_size; |
0 | 2331 |
470 | 2332 // av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts:%lld dts:%lld cur_dts:%lld b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, b_frames, pkt->size, pkt->stream_index); |
885 | 2333 |
468 | 2334 /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE) |
2335 return -1;*/ | |
885 | 2336 |
468 | 2337 /* duration field */ |
470 | 2338 if (pkt->duration == 0) { |
2339 compute_frame_duration(&num, &den, st, NULL, pkt); | |
2340 if (den && num) { | |
2341 pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num); | |
2342 } | |
2343 } | |
409 | 2344 |
468 | 2345 //XXX/FIXME this is a temporary hack until all encoders output pts |
2346 if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !b_frames){ | |
2347 pkt->dts= | |
2348 // pkt->pts= st->cur_dts; | |
2349 pkt->pts= st->pts.val; | |
2350 } | |
2351 | |
885 | 2352 //calculate dts from pts |
468 | 2353 if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){ |
2354 if(b_frames){ | |
2355 if(st->last_IP_pts == AV_NOPTS_VALUE){ | |
470 | 2356 st->last_IP_pts= -pkt->duration; |
468 | 2357 } |
2358 if(st->last_IP_pts < pkt->pts){ | |
2359 pkt->dts= st->last_IP_pts; | |
2360 st->last_IP_pts= pkt->pts; | |
2361 }else | |
2362 pkt->dts= pkt->pts; | |
2363 }else | |
2364 pkt->dts= pkt->pts; | |
2365 } | |
885 | 2366 |
617
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2367 if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ |
881 | 2368 av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts); |
617
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2369 return -1; |
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2370 } |
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2371 if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){ |
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2372 av_log(NULL, AV_LOG_ERROR, "error, pts < dts\n"); |
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2373 return -1; |
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2374 } |
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2375 |
470 | 2376 // av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts2:%lld dts2:%lld\n", pkt->pts, pkt->dts); |
468 | 2377 st->cur_dts= pkt->dts; |
2378 st->pts.val= pkt->dts; | |
2379 | |
0 | 2380 /* update pts */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2381 switch (st->codec->codec_type) { |
0 | 2382 case CODEC_TYPE_AUDIO: |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2383 frame_size = get_audio_frame_size(st->codec, pkt->size); |
406
ea22a438ca79
fix obnoxious ogg_packet passing from encoder to muxer
michael
parents:
404
diff
changeset
|
2384 |
409 | 2385 /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay, |
406
ea22a438ca79
fix obnoxious ogg_packet passing from encoder to muxer
michael
parents:
404
diff
changeset
|
2386 but it would be better if we had the real timestamps from the encoder */ |
468 | 2387 if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) { |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
2388 av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); |
0 | 2389 } |
2390 break; | |
2391 case CODEC_TYPE_VIDEO: | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2392 av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num); |
0 | 2393 break; |
2394 default: | |
2395 break; | |
2396 } | |
617
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2397 return 0; |
470 | 2398 } |
2399 | |
2400 static void truncate_ts(AVStream *st, AVPacket *pkt){ | |
2401 int64_t pts_mask = (2LL << (st->pts_wrap_bits-1)) - 1; | |
885 | 2402 |
547 | 2403 // if(pkt->dts < 0) |
2404 // pkt->dts= 0; //this happens for low_delay=0 and b frames, FIXME, needs further invstigation about what we should do here | |
885 | 2405 |
470 | 2406 pkt->pts &= pts_mask; |
2407 pkt->dts &= pts_mask; | |
2408 } | |
2409 | |
2410 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2411 * Write a packet to an output media file. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2412 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2413 * The packet shall contain one audio or video frame. |
470 | 2414 * |
2415 * @param s media file handle | |
2416 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ... | |
2417 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted. | |
2418 */ | |
2419 int av_write_frame(AVFormatContext *s, AVPacket *pkt) | |
2420 { | |
554 | 2421 int ret; |
2422 | |
617
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2423 ret=compute_pkt_fields2(s->streams[pkt->stream_index], pkt); |
1245
e59b75051ded
dont be too picky about timestampsbeing wrong if the destination container is without timestamps and raw of the raw video / raw audio sort
michael
parents:
1244
diff
changeset
|
2424 if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) |
617
1ca4877e42f3
some sanity checks on what is muxed, invalid timestamps in mpeg are very common and lead to strange errors in the mpeg muxer otherwise
michael
parents:
616
diff
changeset
|
2425 return ret; |
885 | 2426 |
470 | 2427 truncate_ts(s->streams[pkt->stream_index], pkt); |
2428 | |
554 | 2429 ret= s->oformat->write_packet(s, pkt); |
2430 if(!ret) | |
2431 ret= url_ferror(&s->pb); | |
2432 return ret; | |
470 | 2433 } |
2434 | |
2435 /** | |
1252 | 2436 * Interleave a packet per DTS in an output media file. |
2437 * | |
2438 * Packets with pkt->destruct == av_destruct_packet will be freed inside this function, | |
2439 * so they cannot be used after it, note calling av_free_packet() on them is still safe. | |
2440 * | |
2441 * @param s media file handle | |
2442 * @param out the interleaved packet will be output here | |
2443 * @param in the input packet | |
2444 * @param flush 1 if no further packets are available as input and all | |
2445 * remaining packets should be output | |
2446 * @return 1 if a packet was output, 0 if no packet could be output, | |
2447 * < 0 if an error occured | |
470 | 2448 */ |
1251 | 2449 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ |
470 | 2450 AVPacketList *pktl, **next_point, *this_pktl; |
2451 int stream_count=0; | |
2452 int streams[MAX_STREAMS]; | |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2453 |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2454 if(pkt){ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2455 AVStream *st= s->streams[ pkt->stream_index]; |
470 | 2456 |
804 | 2457 // assert(pkt->destruct != av_destruct_packet); //FIXME |
470 | 2458 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2459 this_pktl = av_mallocz(sizeof(AVPacketList)); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2460 this_pktl->pkt= *pkt; |
804 | 2461 if(pkt->destruct == av_destruct_packet) |
2462 pkt->destruct= NULL; // non shared -> must keep original from being freed | |
2463 else | |
2464 av_dup_packet(&this_pktl->pkt); //shared -> must dup | |
470 | 2465 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2466 next_point = &s->packet_buffer; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2467 while(*next_point){ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2468 AVStream *st2= s->streams[ (*next_point)->pkt.stream_index]; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2469 int64_t left= st2->time_base.num * (int64_t)st ->time_base.den; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2470 int64_t right= st ->time_base.num * (int64_t)st2->time_base.den; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2471 if((*next_point)->pkt.dts * left > pkt->dts * right) //FIXME this can overflow |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2472 break; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2473 next_point= &(*next_point)->next; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2474 } |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2475 this_pktl->next= *next_point; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2476 *next_point= this_pktl; |
470 | 2477 } |
885 | 2478 |
470 | 2479 memset(streams, 0, sizeof(streams)); |
2480 pktl= s->packet_buffer; | |
2481 while(pktl){ | |
2482 //av_log(s, AV_LOG_DEBUG, "show st:%d dts:%lld\n", pktl->pkt.stream_index, pktl->pkt.dts); | |
2483 if(streams[ pktl->pkt.stream_index ] == 0) | |
2484 stream_count++; | |
2485 streams[ pktl->pkt.stream_index ]++; | |
2486 pktl= pktl->next; | |
2487 } | |
885 | 2488 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2489 if(s->nb_streams == stream_count || (flush && stream_count)){ |
470 | 2490 pktl= s->packet_buffer; |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2491 *out= pktl->pkt; |
885 | 2492 |
2493 s->packet_buffer= pktl->next; | |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2494 av_freep(&pktl); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2495 return 1; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2496 }else{ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2497 av_init_packet(out); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2498 return 0; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2499 } |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2500 } |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2501 |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2502 /** |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2503 * Interleaves a AVPacket correctly so it can be muxed. |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2504 * @param out the interleaved packet will be output here |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2505 * @param in the input packet |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2506 * @param flush 1 if no further packets are available as input and all |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2507 * remaining packets should be output |
885 | 2508 * @return 1 if a packet was output, 0 if no packet could be output, |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2509 * < 0 if an error occured |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2510 */ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2511 static int av_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2512 if(s->oformat->interleave_packet) |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2513 return s->oformat->interleave_packet(s, out, in, flush); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2514 else |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2515 return av_interleave_packet_per_dts(s, out, in, flush); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2516 } |
470 | 2517 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2518 /** |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2519 * Writes a packet to an output media file ensuring correct interleaving. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2520 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2521 * The packet must contain one audio or video frame. |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2522 * If the packets are already correctly interleaved the application should |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2523 * call av_write_frame() instead as its slightly faster, its also important |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2524 * to keep in mind that completly non interleaved input will need huge amounts |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2525 * of memory to interleave with this, so its prefereable to interleave at the |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2526 * demuxer level |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2527 * |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2528 * @param s media file handle |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2529 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ... |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2530 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted. |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2531 */ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2532 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2533 AVStream *st= s->streams[ pkt->stream_index]; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2534 |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2535 //FIXME/XXX/HACK drop zero sized packets |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2536 if(st->codec->codec_type == CODEC_TYPE_AUDIO && pkt->size==0) |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2537 return 0; |
717
a79f89d39c3c
discard dummy packets before doing inapropriate checks on them and failing as a result
michael
parents:
708
diff
changeset
|
2538 |
a79f89d39c3c
discard dummy packets before doing inapropriate checks on them and failing as a result
michael
parents:
708
diff
changeset
|
2539 //av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %Ld %Ld\n", pkt->size, pkt->dts, pkt->pts); |
1245
e59b75051ded
dont be too picky about timestampsbeing wrong if the destination container is without timestamps and raw of the raw video / raw audio sort
michael
parents:
1244
diff
changeset
|
2540 if(compute_pkt_fields2(st, pkt) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) |
717
a79f89d39c3c
discard dummy packets before doing inapropriate checks on them and failing as a result
michael
parents:
708
diff
changeset
|
2541 return -1; |
885 | 2542 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2543 if(pkt->dts == AV_NOPTS_VALUE) |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2544 return -1; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2545 |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2546 for(;;){ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2547 AVPacket opkt; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2548 int ret= av_interleave_packet(s, &opkt, pkt, 0); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2549 if(ret<=0) //FIXME cleanup needed for ret<0 ? |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2550 return ret; |
885 | 2551 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2552 truncate_ts(s->streams[opkt.stream_index], &opkt); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2553 ret= s->oformat->write_packet(s, &opkt); |
885 | 2554 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2555 av_free_packet(&opkt); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2556 pkt= NULL; |
885 | 2557 |
470 | 2558 if(ret<0) |
2559 return ret; | |
554 | 2560 if(url_ferror(&s->pb)) |
2561 return url_ferror(&s->pb); | |
470 | 2562 } |
0 | 2563 } |
2564 | |
2565 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2566 * @brief Write the stream trailer to an output media file and |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2567 * free the file private data. |
0 | 2568 * |
2569 * @param s media file handle | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2570 * @return 0 if OK. AVERROR_xxx if error. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2571 */ |
0 | 2572 int av_write_trailer(AVFormatContext *s) |
2573 { | |
540
26a477a5ebda
move free() of AVStream priv data to av_write_trailer()
michael
parents:
536
diff
changeset
|
2574 int ret, i; |
885 | 2575 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2576 for(;;){ |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2577 AVPacket pkt; |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2578 ret= av_interleave_packet(s, &pkt, NULL, 1); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2579 if(ret<0) //FIXME cleanup needed for ret<0 ? |
540
26a477a5ebda
move free() of AVStream priv data to av_write_trailer()
michael
parents:
536
diff
changeset
|
2580 goto fail; |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2581 if(!ret) |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2582 break; |
885 | 2583 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2584 truncate_ts(s->streams[pkt.stream_index], &pkt); |
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2585 ret= s->oformat->write_packet(s, &pkt); |
885 | 2586 |
536
76c47c58064f
move packet interleaving function into AVOutputFormat, so it can be overriden easily instead of doing reordering twice if the muxer needs some other interleaving then dts based
michael
parents:
535
diff
changeset
|
2587 av_free_packet(&pkt); |
885 | 2588 |
470 | 2589 if(ret<0) |
540
26a477a5ebda
move free() of AVStream priv data to av_write_trailer()
michael
parents:
536
diff
changeset
|
2590 goto fail; |
554 | 2591 if(url_ferror(&s->pb)) |
2592 goto fail; | |
470 | 2593 } |
2594 | |
869 | 2595 if(s->oformat->write_trailer) |
2596 ret = s->oformat->write_trailer(s); | |
540
26a477a5ebda
move free() of AVStream priv data to av_write_trailer()
michael
parents:
536
diff
changeset
|
2597 fail: |
554 | 2598 if(ret == 0) |
2599 ret=url_ferror(&s->pb); | |
540
26a477a5ebda
move free() of AVStream priv data to av_write_trailer()
michael
parents:
536
diff
changeset
|
2600 for(i=0;i<s->nb_streams;i++) |
26a477a5ebda
move free() of AVStream priv data to av_write_trailer()
michael
parents:
536
diff
changeset
|
2601 av_freep(&s->streams[i]->priv_data); |
0 | 2602 av_freep(&s->priv_data); |
2603 return ret; | |
2604 } | |
2605 | |
2606 /* "user interface" functions */ | |
2607 | |
2608 void dump_format(AVFormatContext *ic, | |
885 | 2609 int index, |
0 | 2610 const char *url, |
2611 int is_output) | |
2612 { | |
2613 int i, flags; | |
2614 char buf[256]; | |
2615 | |
885 | 2616 av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n", |
0 | 2617 is_output ? "Output" : "Input", |
885 | 2618 index, |
2619 is_output ? ic->oformat->name : ic->iformat->name, | |
0 | 2620 is_output ? "to" : "from", url); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2621 if (!is_output) { |
776 | 2622 av_log(NULL, AV_LOG_INFO, " Duration: "); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2623 if (ic->duration != AV_NOPTS_VALUE) { |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2624 int hours, mins, secs, us; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2625 secs = ic->duration / AV_TIME_BASE; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2626 us = ic->duration % AV_TIME_BASE; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2627 mins = secs / 60; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2628 secs %= 60; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2629 hours = mins / 60; |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2630 mins %= 60; |
885 | 2631 av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%01d", hours, mins, secs, |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2632 (10 * us) / AV_TIME_BASE); |
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2633 } else { |
776 | 2634 av_log(NULL, AV_LOG_INFO, "N/A"); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2635 } |
556
cb5f220888c0
print start_time patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
555
diff
changeset
|
2636 if (ic->start_time != AV_NOPTS_VALUE) { |
cb5f220888c0
print start_time patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
555
diff
changeset
|
2637 int secs, us; |
776 | 2638 av_log(NULL, AV_LOG_INFO, ", start: "); |
556
cb5f220888c0
print start_time patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
555
diff
changeset
|
2639 secs = ic->start_time / AV_TIME_BASE; |
cb5f220888c0
print start_time patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
555
diff
changeset
|
2640 us = ic->start_time % AV_TIME_BASE; |
776 | 2641 av_log(NULL, AV_LOG_INFO, "%d.%06d", |
556
cb5f220888c0
print start_time patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
555
diff
changeset
|
2642 secs, (int)av_rescale(us, 1000000, AV_TIME_BASE)); |
cb5f220888c0
print start_time patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
555
diff
changeset
|
2643 } |
776 | 2644 av_log(NULL, AV_LOG_INFO, ", bitrate: "); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2645 if (ic->bit_rate) { |
776 | 2646 av_log(NULL, AV_LOG_INFO,"%d kb/s", ic->bit_rate / 1000); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2647 } else { |
776 | 2648 av_log(NULL, AV_LOG_INFO, "N/A"); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2649 } |
776 | 2650 av_log(NULL, AV_LOG_INFO, "\n"); |
192
0316a506aeb0
initial duration/start_time generic support - displays stream duration and average total bitrate when using an input file
bellard
parents:
175
diff
changeset
|
2651 } |
0 | 2652 for(i=0;i<ic->nb_streams;i++) { |
2653 AVStream *st = ic->streams[i]; | |
855
379c4e948363
print more time_base fps stuff if av_log level is at debug or above
michael
parents:
851
diff
changeset
|
2654 int g= ff_gcd(st->time_base.num, st->time_base.den); |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
2655 avcodec_string(buf, sizeof(buf), st->codec, is_output); |
776 | 2656 av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i); |
0 | 2657 /* the pid is an important information, so we display it */ |
2658 /* XXX: add a generic system */ | |
2659 if (is_output) | |
2660 flags = ic->oformat->flags; | |
2661 else | |
2662 flags = ic->iformat->flags; | |
2663 if (flags & AVFMT_SHOW_IDS) { | |
776 | 2664 av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); |
0 | 2665 } |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
810
diff
changeset
|
2666 if (strlen(st->language) > 0) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
810
diff
changeset
|
2667 av_log(NULL, AV_LOG_INFO, "(%s)", st->language); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
810
diff
changeset
|
2668 } |
855
379c4e948363
print more time_base fps stuff if av_log level is at debug or above
michael
parents:
851
diff
changeset
|
2669 av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g); |
1119 | 2670 av_log(NULL, AV_LOG_INFO, ": %s", buf); |
855
379c4e948363
print more time_base fps stuff if av_log level is at debug or above
michael
parents:
851
diff
changeset
|
2671 if(st->codec->codec_type == CODEC_TYPE_VIDEO){ |
882 | 2672 if(st->r_frame_rate.den && st->r_frame_rate.num) |
2673 av_log(NULL, AV_LOG_INFO, ", %5.2f fps(r)", av_q2d(st->r_frame_rate)); | |
2674 /* else if(st->time_base.den && st->time_base.num) | |
2675 av_log(NULL, AV_LOG_INFO, ", %5.2f fps(m)", 1/av_q2d(st->time_base));*/ | |
2676 else | |
2677 av_log(NULL, AV_LOG_INFO, ", %5.2f fps(c)", 1/av_q2d(st->codec->time_base)); | |
855
379c4e948363
print more time_base fps stuff if av_log level is at debug or above
michael
parents:
851
diff
changeset
|
2678 } |
1119 | 2679 av_log(NULL, AV_LOG_INFO, "\n"); |
0 | 2680 } |
2681 } | |
2682 | |
2683 typedef struct { | |
168 | 2684 const char *abv; |
0 | 2685 int width, height; |
168 | 2686 int frame_rate, frame_rate_base; |
2687 } AbvEntry; | |
0 | 2688 |
168 | 2689 static AbvEntry frame_abvs[] = { |
204 | 2690 { "ntsc", 720, 480, 30000, 1001 }, |
2691 { "pal", 720, 576, 25, 1 }, | |
2692 { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */ | |
2693 { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */ | |
205 | 2694 { "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */ |
2695 { "spal", 768, 576, 25, 1 }, /* square pixel pal */ | |
168 | 2696 { "film", 352, 240, 24, 1 }, |
2697 { "ntsc-film", 352, 240, 24000, 1001 }, | |
2698 { "sqcif", 128, 96, 0, 0 }, | |
2699 { "qcif", 176, 144, 0, 0 }, | |
2700 { "cif", 352, 288, 0, 0 }, | |
2701 { "4cif", 704, 576, 0, 0 }, | |
0 | 2702 }; |
168 | 2703 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2704 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2705 * parses width and height out of string str. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2706 */ |
0 | 2707 int parse_image_size(int *width_ptr, int *height_ptr, const char *str) |
2708 { | |
2709 int i; | |
168 | 2710 int n = sizeof(frame_abvs) / sizeof(AbvEntry); |
0 | 2711 const char *p; |
2712 int frame_width = 0, frame_height = 0; | |
2713 | |
2714 for(i=0;i<n;i++) { | |
168 | 2715 if (!strcmp(frame_abvs[i].abv, str)) { |
2716 frame_width = frame_abvs[i].width; | |
2717 frame_height = frame_abvs[i].height; | |
0 | 2718 break; |
2719 } | |
2720 } | |
2721 if (i == n) { | |
2722 p = str; | |
2723 frame_width = strtol(p, (char **)&p, 10); | |
2724 if (*p) | |
2725 p++; | |
2726 frame_height = strtol(p, (char **)&p, 10); | |
2727 } | |
2728 if (frame_width <= 0 || frame_height <= 0) | |
2729 return -1; | |
2730 *width_ptr = frame_width; | |
2731 *height_ptr = frame_height; | |
2732 return 0; | |
2733 } | |
2734 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2735 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2736 * Converts frame rate from string to a fraction. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2737 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2738 * First we try to get an exact integer or fractional frame rate. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2739 * If this fails we convert the frame rate to a double and return |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2740 * an approximate fraction using the DEFAULT_FRAME_RATE_BASE. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2741 */ |
168 | 2742 int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg) |
2743 { | |
2744 int i; | |
2745 char* cp; | |
885 | 2746 |
168 | 2747 /* First, we check our abbreviation table */ |
2748 for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i) | |
2749 if (!strcmp(frame_abvs[i].abv, arg)) { | |
887 | 2750 *frame_rate = frame_abvs[i].frame_rate; |
2751 *frame_rate_base = frame_abvs[i].frame_rate_base; | |
2752 return 0; | |
2753 } | |
168 | 2754 |
2755 /* Then, we try to parse it as fraction */ | |
2756 cp = strchr(arg, '/'); | |
662
549e594a13c2
support colon-separated rates patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents:
652
diff
changeset
|
2757 if (!cp) |
549e594a13c2
support colon-separated rates patch by Roine Gustafsson <roine AT users DOT sourceforge DOT net>
mmu_man
parents:
652
diff
changeset
|
2758 cp = strchr(arg, ':'); |
168 | 2759 if (cp) { |
2760 char* cpp; | |
887 | 2761 *frame_rate = strtol(arg, &cpp, 10); |
2762 if (cpp != arg || cpp == cp) | |
2763 *frame_rate_base = strtol(cp+1, &cpp, 10); | |
2764 else | |
2765 *frame_rate = 0; | |
885 | 2766 } |
168 | 2767 else { |
2768 /* Finally we give up and parse it as double */ | |
1030 | 2769 AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE); |
2770 *frame_rate_base = time_base.den; | |
2771 *frame_rate = time_base.num; | |
168 | 2772 } |
2773 if (!*frame_rate || !*frame_rate_base) | |
2774 return -1; | |
2775 else | |
2776 return 0; | |
2777 } | |
2778 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2779 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2780 * Converts date string to number of seconds since Jan 1st, 1970. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2781 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2782 * @code |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2783 * Syntax: |
0 | 2784 * - If not a duration: |
2785 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]} | |
2786 * Time is localtime unless Z is suffixed to the end. In this case GMT | |
885 | 2787 * Return the date in micro seconds since 1970 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2788 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2789 * - If a duration: |
0 | 2790 * HH[:MM[:SS[.m...]]] |
2791 * S+[.m...] | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2792 * @endcode |
0 | 2793 */ |
907 | 2794 #ifndef CONFIG_WINCE |
65 | 2795 int64_t parse_date(const char *datestr, int duration) |
0 | 2796 { |
2797 const char *p; | |
65 | 2798 int64_t t; |
0 | 2799 struct tm dt; |
2800 int i; | |
2801 static const char *date_fmt[] = { | |
2802 "%Y-%m-%d", | |
2803 "%Y%m%d", | |
2804 }; | |
2805 static const char *time_fmt[] = { | |
2806 "%H:%M:%S", | |
2807 "%H%M%S", | |
2808 }; | |
2809 const char *q; | |
2810 int is_utc, len; | |
2811 char lastch; | |
477 | 2812 int negative = 0; |
406
ea22a438ca79
fix obnoxious ogg_packet passing from encoder to muxer
michael
parents:
404
diff
changeset
|
2813 |
ea22a438ca79
fix obnoxious ogg_packet passing from encoder to muxer
michael
parents:
404
diff
changeset
|
2814 #undef time |
0 | 2815 time_t now = time(0); |
2816 | |
2817 len = strlen(datestr); | |
2818 if (len > 0) | |
2819 lastch = datestr[len - 1]; | |
2820 else | |
2821 lastch = '\0'; | |
2822 is_utc = (lastch == 'z' || lastch == 'Z'); | |
2823 | |
2824 memset(&dt, 0, sizeof(dt)); | |
2825 | |
2826 p = datestr; | |
2827 q = NULL; | |
2828 if (!duration) { | |
2829 for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) { | |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
2830 q = small_strptime(p, date_fmt[i], &dt); |
0 | 2831 if (q) { |
2832 break; | |
2833 } | |
2834 } | |
2835 | |
2836 if (!q) { | |
2837 if (is_utc) { | |
2838 dt = *gmtime(&now); | |
2839 } else { | |
2840 dt = *localtime(&now); | |
2841 } | |
2842 dt.tm_hour = dt.tm_min = dt.tm_sec = 0; | |
2843 } else { | |
2844 p = q; | |
2845 } | |
2846 | |
2847 if (*p == 'T' || *p == 't' || *p == ' ') | |
2848 p++; | |
2849 | |
2850 for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) { | |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
2851 q = small_strptime(p, time_fmt[i], &dt); |
0 | 2852 if (q) { |
2853 break; | |
2854 } | |
2855 } | |
2856 } else { | |
887 | 2857 if (p[0] == '-') { |
2858 negative = 1; | |
2859 ++p; | |
2860 } | |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
229
diff
changeset
|
2861 q = small_strptime(p, time_fmt[0], &dt); |
0 | 2862 if (!q) { |
2863 dt.tm_sec = strtol(p, (char **)&q, 10); | |
2864 dt.tm_min = 0; | |
2865 dt.tm_hour = 0; | |
2866 } | |
2867 } | |
2868 | |
2869 /* Now we have all the fields that we can get */ | |
2870 if (!q) { | |
2871 if (duration) | |
2872 return 0; | |
2873 else | |
65 | 2874 return now * int64_t_C(1000000); |
0 | 2875 } |
2876 | |
2877 if (duration) { | |
2878 t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; | |
2879 } else { | |
2880 dt.tm_isdst = -1; /* unknown */ | |
2881 if (is_utc) { | |
2882 t = mktimegm(&dt); | |
2883 } else { | |
2884 t = mktime(&dt); | |
2885 } | |
2886 } | |
2887 | |
2888 t *= 1000000; | |
2889 | |
2890 if (*q == '.') { | |
2891 int val, n; | |
2892 q++; | |
2893 for (val = 0, n = 100000; n >= 1; n /= 10, q++) { | |
885 | 2894 if (!isdigit(*q)) |
0 | 2895 break; |
2896 val += n * (*q - '0'); | |
2897 } | |
2898 t += val; | |
2899 } | |
477 | 2900 return negative ? -t : t; |
0 | 2901 } |
907 | 2902 #endif /* CONFIG_WINCE */ |
0 | 2903 |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2904 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2905 * Attempts to find a specific tag in a URL. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2906 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2907 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2908 * Return 1 if found. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2909 */ |
0 | 2910 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) |
2911 { | |
2912 const char *p; | |
2913 char tag[128], *q; | |
2914 | |
2915 p = info; | |
2916 if (*p == '?') | |
2917 p++; | |
2918 for(;;) { | |
2919 q = tag; | |
2920 while (*p != '\0' && *p != '=' && *p != '&') { | |
2921 if ((q - tag) < sizeof(tag) - 1) | |
2922 *q++ = *p; | |
2923 p++; | |
2924 } | |
2925 *q = '\0'; | |
2926 q = arg; | |
2927 if (*p == '=') { | |
2928 p++; | |
2929 while (*p != '&' && *p != '\0') { | |
2930 if ((q - arg) < arg_size - 1) { | |
2931 if (*p == '+') | |
2932 *q++ = ' '; | |
2933 else | |
2934 *q++ = *p; | |
2935 } | |
2936 p++; | |
2937 } | |
2938 *q = '\0'; | |
2939 } | |
885 | 2940 if (!strcmp(tag, tag1)) |
0 | 2941 return 1; |
2942 if (*p != '&') | |
2943 break; | |
2944 p++; | |
2945 } | |
2946 return 0; | |
2947 } | |
2948 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2949 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2950 * Returns in 'buf' the path with '%d' replaced by number. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2951 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2952 * Also handles the '%0nd' format where 'n' is the total number |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2953 * of digits and '%%'. Return 0 if OK, and -1 if format error. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
2954 */ |
0 | 2955 int get_frame_filename(char *buf, int buf_size, |
2956 const char *path, int number) | |
2957 { | |
2958 const char *p; | |
290
7a3ed84008ec
GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents:
230
diff
changeset
|
2959 char *q, buf1[20], c; |
7a3ed84008ec
GCC 3.3.2 warnings patch by (Panagiotis Issaris <takis at lumumba dot luc dot ac dot be>)
michael
parents:
230
diff
changeset
|
2960 int nd, len, percentd_found; |
0 | 2961 |
2962 q = buf; | |
2963 p = path; | |
2964 percentd_found = 0; | |
2965 for(;;) { | |
2966 c = *p++; | |
2967 if (c == '\0') | |
2968 break; | |
2969 if (c == '%') { | |
9
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2970 do { |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2971 nd = 0; |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2972 while (isdigit(*p)) { |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2973 nd = nd * 10 + *p++ - '0'; |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2974 } |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2975 c = *p++; |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2976 } while (isdigit(c)); |
97e61383cb81
* Extend the syntax of a filename for the img reader to allow looping. Thus
philipjsg
parents:
7
diff
changeset
|
2977 |
0 | 2978 switch(c) { |
2979 case '%': | |
2980 goto addchar; | |
2981 case 'd': | |
2982 if (percentd_found) | |
2983 goto fail; | |
2984 percentd_found = 1; | |
2985 snprintf(buf1, sizeof(buf1), "%0*d", nd, number); | |
2986 len = strlen(buf1); | |
2987 if ((q - buf + len) > buf_size - 1) | |
2988 goto fail; | |
2989 memcpy(q, buf1, len); | |
2990 q += len; | |
2991 break; | |
2992 default: | |
2993 goto fail; | |
2994 } | |
2995 } else { | |
2996 addchar: | |
2997 if ((q - buf) < buf_size - 1) | |
2998 *q++ = c; | |
2999 } | |
3000 } | |
3001 if (!percentd_found) | |
3002 goto fail; | |
3003 *q = '\0'; | |
3004 return 0; | |
3005 fail: | |
3006 *q = '\0'; | |
3007 return -1; | |
3008 } | |
3009 | |
3010 /** | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3011 * Print nice hexa dump of a buffer |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3012 * @param f stream for output |
0 | 3013 * @param buf buffer |
3014 * @param size buffer size | |
3015 */ | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3016 void av_hex_dump(FILE *f, uint8_t *buf, int size) |
0 | 3017 { |
3018 int len, i, j, c; | |
3019 | |
3020 for(i=0;i<size;i+=16) { | |
3021 len = size - i; | |
3022 if (len > 16) | |
3023 len = 16; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3024 fprintf(f, "%08x ", i); |
0 | 3025 for(j=0;j<16;j++) { |
3026 if (j < len) | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3027 fprintf(f, " %02x", buf[i+j]); |
0 | 3028 else |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3029 fprintf(f, " "); |
0 | 3030 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3031 fprintf(f, " "); |
0 | 3032 for(j=0;j<len;j++) { |
3033 c = buf[i+j]; | |
3034 if (c < ' ' || c > '~') | |
3035 c = '.'; | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3036 fprintf(f, "%c", c); |
0 | 3037 } |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3038 fprintf(f, "\n"); |
0 | 3039 } |
3040 } | |
3041 | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3042 /** |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3043 * Print on 'f' a nice dump of a packet |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3044 * @param f stream for output |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3045 * @param pkt packet to dump |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3046 * @param dump_payload true if the payload must be displayed too |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3047 */ |
743 | 3048 //FIXME needs to know the time_base |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3049 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3050 { |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3051 fprintf(f, "stream #%d:\n", pkt->stream_index); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3052 fprintf(f, " keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0)); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3053 fprintf(f, " duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE); |
333 | 3054 /* DTS is _always_ valid after av_read_frame() */ |
3055 fprintf(f, " dts="); | |
3056 if (pkt->dts == AV_NOPTS_VALUE) | |
3057 fprintf(f, "N/A"); | |
3058 else | |
3059 fprintf(f, "%0.3f", (double)pkt->dts / AV_TIME_BASE); | |
303
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3060 /* PTS may be not known if B frames are present */ |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3061 fprintf(f, " pts="); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3062 if (pkt->pts == AV_NOPTS_VALUE) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3063 fprintf(f, "N/A"); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3064 else |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3065 fprintf(f, "%0.3f", (double)pkt->pts / AV_TIME_BASE); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3066 fprintf(f, "\n"); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3067 fprintf(f, " size=%d\n", pkt->size); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3068 if (dump_payload) |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3069 av_hex_dump(f, pkt->data, pkt->size); |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3070 } |
2833c2311b66
initial av_read_frame() and av_seek_frame() support
bellard
parents:
293
diff
changeset
|
3071 |
0 | 3072 void url_split(char *proto, int proto_size, |
511
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3073 char *authorization, int authorization_size, |
0 | 3074 char *hostname, int hostname_size, |
3075 int *port_ptr, | |
3076 char *path, int path_size, | |
3077 const char *url) | |
3078 { | |
3079 const char *p; | |
3080 char *q; | |
3081 int port; | |
3082 | |
3083 port = -1; | |
3084 | |
3085 p = url; | |
3086 q = proto; | |
3087 while (*p != ':' && *p != '\0') { | |
3088 if ((q - proto) < proto_size - 1) | |
3089 *q++ = *p; | |
3090 p++; | |
3091 } | |
3092 if (proto_size > 0) | |
3093 *q = '\0'; | |
511
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3094 if (authorization_size > 0) |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3095 authorization[0] = '\0'; |
0 | 3096 if (*p == '\0') { |
3097 if (proto_size > 0) | |
3098 proto[0] = '\0'; | |
3099 if (hostname_size > 0) | |
3100 hostname[0] = '\0'; | |
3101 p = url; | |
3102 } else { | |
511
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3103 char *at,*slash; // PETR: position of '@' character and '/' character |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3104 |
0 | 3105 p++; |
3106 if (*p == '/') | |
3107 p++; | |
3108 if (*p == '/') | |
3109 p++; | |
511
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3110 at = strchr(p,'@'); // PETR: get the position of '@' |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3111 slash = strchr(p,'/'); // PETR: get position of '/' - end of hostname |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3112 if (at && slash && at > slash) at = NULL; // PETR: not interested in '@' behind '/' |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3113 |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3114 q = at ? authorization : hostname; // PETR: if '@' exists starting with auth. |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3115 |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3116 while ((at || *p != ':') && *p != '/' && *p != '?' && *p != '\0') { // PETR: |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3117 if (*p == '@') { // PETR: passed '@' |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3118 if (authorization_size > 0) |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3119 *q = '\0'; |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3120 q = hostname; |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3121 at = NULL; |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3122 } else if (!at) { // PETR: hostname |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3123 if ((q - hostname) < hostname_size - 1) |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3124 *q++ = *p; |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3125 } else { |
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3126 if ((q - authorization) < authorization_size - 1) |
0 | 3127 *q++ = *p; |
511
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
502
diff
changeset
|
3128 } |
0 | 3129 p++; |
3130 } | |
3131 if (hostname_size > 0) | |
3132 *q = '\0'; | |
3133 if (*p == ':') { | |
3134 p++; | |
3135 port = strtoul(p, (char **)&p, 10); | |
3136 } | |
3137 } | |
3138 if (port_ptr) | |
3139 *port_ptr = port; | |
3140 pstrcpy(path, path_size, p); | |
3141 } | |
3142 | |
3143 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3144 * Set the pts for a given stream. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3145 * |
885 | 3146 * @param s stream |
0 | 3147 * @param pts_wrap_bits number of bits effectively used by the pts |
885 | 3148 * (used for wrap control, 33 is the value for MPEG) |
3149 * @param pts_num numerator to convert to seconds (MPEG: 1) | |
0 | 3150 * @param pts_den denominator to convert to seconds (MPEG: 90000) |
3151 */ | |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
3152 void av_set_pts_info(AVStream *s, int pts_wrap_bits, |
0 | 3153 int pts_num, int pts_den) |
3154 { | |
3155 s->pts_wrap_bits = pts_wrap_bits; | |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
3156 s->time_base.num = pts_num; |
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
453
diff
changeset
|
3157 s->time_base.den = pts_den; |
0 | 3158 } |
3159 | |
3160 /* fraction handling */ | |
3161 | |
3162 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3163 * f = val + (num / den) + 0.5. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3164 * |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3165 * 'num' is normalized so that it is such as 0 <= num < den. |
0 | 3166 * |
3167 * @param f fractional number | |
3168 * @param val integer value | |
3169 * @param num must be >= 0 | |
885 | 3170 * @param den must be >= 1 |
0 | 3171 */ |
1135
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
3172 static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) |
0 | 3173 { |
3174 num += (den >> 1); | |
3175 if (num >= den) { | |
3176 val += num / den; | |
3177 num = num % den; | |
3178 } | |
3179 f->val = val; | |
3180 f->num = num; | |
3181 f->den = den; | |
3182 } | |
3183 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3184 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3185 * Set f to (val + 0.5). |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3186 */ |
1135
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
3187 static void av_frac_set(AVFrac *f, int64_t val) |
0 | 3188 { |
3189 f->val = val; | |
3190 f->num = f->den >> 1; | |
3191 } | |
3192 | |
3193 /** | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3194 * Fractionnal addition to f: f = f + (incr / f->den). |
0 | 3195 * |
3196 * @param f fractional number | |
3197 * @param incr increment, can be positive or negative | |
3198 */ | |
1135
107f90e1551b
cleanup patch from Diego Petten <flameeyes@gentoo.org>
lu_zero
parents:
1127
diff
changeset
|
3199 static void av_frac_add(AVFrac *f, int64_t incr) |
0 | 3200 { |
65 | 3201 int64_t num, den; |
0 | 3202 |
3203 num = f->num + incr; | |
3204 den = f->den; | |
3205 if (num < 0) { | |
3206 f->val += num / den; | |
3207 num = num % den; | |
3208 if (num < 0) { | |
3209 num += den; | |
3210 f->val--; | |
3211 } | |
3212 } else if (num >= den) { | |
3213 f->val += num / den; | |
3214 num = num % den; | |
3215 } | |
3216 f->num = num; | |
3217 } | |
20 | 3218 |
3219 /** | |
3220 * register a new image format | |
3221 * @param img_fmt Image format descriptor | |
3222 */ | |
3223 void av_register_image_format(AVImageFormat *img_fmt) | |
3224 { | |
3225 AVImageFormat **p; | |
3226 | |
3227 p = &first_image_format; | |
3228 while (*p != NULL) p = &(*p)->next; | |
3229 *p = img_fmt; | |
3230 img_fmt->next = NULL; | |
3231 } | |
3232 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3233 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3234 * Guesses image format based on data in the image. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3235 */ |
20 | 3236 AVImageFormat *av_probe_image_format(AVProbeData *pd) |
3237 { | |
3238 AVImageFormat *fmt1, *fmt; | |
3239 int score, score_max; | |
3240 | |
3241 fmt = NULL; | |
3242 score_max = 0; | |
3243 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) { | |
3244 if (fmt1->img_probe) { | |
3245 score = fmt1->img_probe(pd); | |
3246 if (score > score_max) { | |
3247 score_max = score; | |
3248 fmt = fmt1; | |
3249 } | |
3250 } | |
3251 } | |
3252 return fmt; | |
3253 } | |
3254 | |
802
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3255 /** |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3256 * Guesses image format based on file name extensions. |
ea0e995ac4a8
part of the 'libavformat/utils.c doxygen documentation' patch by (Daniel Kristjansson: danielk, cat nyu edu)
michael
parents:
801
diff
changeset
|
3257 */ |
20 | 3258 AVImageFormat *guess_image_format(const char *filename) |
3259 { | |
3260 AVImageFormat *fmt1; | |
3261 | |
3262 for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) { | |
3263 if (fmt1->extensions && match_ext(filename, fmt1->extensions)) | |
3264 return fmt1; | |
3265 } | |
3266 return NULL; | |
3267 } | |
3268 | |
3269 /** | |
885 | 3270 * Read an image from a stream. |
20 | 3271 * @param gb byte stream containing the image |
3272 * @param fmt image format, NULL if probing is required | |
3273 */ | |
3274 int av_read_image(ByteIOContext *pb, const char *filename, | |
3275 AVImageFormat *fmt, | |
3276 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque) | |
3277 { | |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
3278 uint8_t buf[PROBE_BUF_MIN]; |
20 | 3279 AVProbeData probe_data, *pd = &probe_data; |
3280 offset_t pos; | |
3281 int ret; | |
3282 | |
3283 if (!fmt) { | |
64 | 3284 pd->filename = filename; |
20 | 3285 pd->buf = buf; |
3286 pos = url_ftell(pb); | |
922
7f20b3ce1100
dynamically increase probe buffer until format is detected
michael
parents:
915
diff
changeset
|
3287 pd->buf_size = get_buffer(pb, buf, PROBE_BUF_MIN); |
20 | 3288 url_fseek(pb, pos, SEEK_SET); |
3289 fmt = av_probe_image_format(pd); | |
3290 } | |
3291 if (!fmt) | |
3292 return AVERROR_NOFMT; | |
3293 ret = fmt->img_read(pb, alloc_cb, opaque); | |
3294 return ret; | |
3295 } | |
3296 | |
3297 /** | |
3298 * Write an image to a stream. | |
3299 * @param pb byte stream for the image output | |
3300 * @param fmt image format | |
3301 * @param img image data and informations | |
3302 */ | |
3303 int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img) | |
3304 { | |
3305 return fmt->img_write(pb, img); | |
3306 } | |
3307 |