OLD | NEW |
1 /* | 1 /* |
2 * AVI demuxer | 2 * AVI demuxer |
3 * Copyright (c) 2001 Fabrice Bellard | 3 * Copyright (c) 2001 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 AVIStream *ast; | 125 AVIStream *ast; |
126 int i; | 126 int i; |
127 int64_t last_pos= -1; | 127 int64_t last_pos= -1; |
128 int64_t filesize= url_fsize(s->pb); | 128 int64_t filesize= url_fsize(s->pb); |
129 | 129 |
130 #ifdef DEBUG_SEEK | 130 #ifdef DEBUG_SEEK |
131 av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d
chunk_id:%X base:%16"PRIX64"\n", | 131 av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d
chunk_id:%X base:%16"PRIX64"\n", |
132 longs_pre_entry,index_type, entries_in_use, chunk_id, base); | 132 longs_pre_entry,index_type, entries_in_use, chunk_id, base); |
133 #endif | 133 #endif |
134 | 134 |
135 if(stream_id > s->nb_streams || stream_id < 0) | 135 if(stream_id >= s->nb_streams || stream_id < 0) |
136 return -1; | 136 return -1; |
137 st= s->streams[stream_id]; | 137 st= s->streams[stream_id]; |
138 ast = st->priv_data; | 138 ast = st->priv_data; |
139 | 139 |
140 if(index_sub_type) | 140 if(index_sub_type) |
141 return -1; | 141 return -1; |
142 | 142 |
143 get_le32(pb); | 143 get_le32(pb); |
144 | 144 |
145 if(index_type && longs_pre_entry != 2) | 145 if(index_type && longs_pre_entry != 2) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 pos= st->index_entries[0].pos; | 220 pos= st->index_entries[0].pos; |
221 size= st->index_entries[0].size; | 221 size= st->index_entries[0].size; |
222 ts= st->index_entries[0].timestamp; | 222 ts= st->index_entries[0].timestamp; |
223 | 223 |
224 for(j=0; j<size; j+=max){ | 224 for(j=0; j<size; j+=max){ |
225 av_add_index_entry(st, pos+j, ts+j, FFMIN(max, size-j), 0, AVINDEX_K
EYFRAME); | 225 av_add_index_entry(st, pos+j, ts+j, FFMIN(max, size-j), 0, AVINDEX_K
EYFRAME); |
226 } | 226 } |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 static int avi_read_tag(AVFormatContext *s, const char *key, unsigned int size) | 230 static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t
size) |
231 { | 231 { |
232 ByteIOContext *pb = s->pb; | 232 ByteIOContext *pb = s->pb; |
233 char *value; | 233 char key[5] = {0}, *value; |
234 | 234 |
235 size += (size & 1); | 235 size += (size & 1); |
236 | 236 |
237 if (size == UINT_MAX) | 237 if (size == UINT_MAX) |
238 return -1; | 238 return -1; |
239 value = av_malloc(size+1); | 239 value = av_malloc(size+1); |
240 if (!value) | 240 if (!value) |
241 return -1; | 241 return -1; |
242 get_strz(pb, value, size); | 242 get_buffer(pb, value, size); |
| 243 value[size]=0; |
243 | 244 |
| 245 AV_WL32(key, tag); |
| 246 |
| 247 if(st) |
| 248 return av_metadata_set2(&st->metadata, key, value, |
| 249 AV_METADATA_DONT_STRDUP_VAL); |
| 250 else |
244 return av_metadata_set2(&s->metadata, key, value, | 251 return av_metadata_set2(&s->metadata, key, value, |
245 AV_METADATA_DONT_STRDUP_VAL); | 252 AV_METADATA_DONT_STRDUP_VAL); |
246 } | 253 } |
247 | 254 |
| 255 static void avi_read_info(AVFormatContext *s, uint64_t end) |
| 256 { |
| 257 while (url_ftell(s->pb) < end) { |
| 258 uint32_t tag = get_le32(s->pb); |
| 259 uint32_t size = get_le32(s->pb); |
| 260 avi_read_tag(s, NULL, tag, size); |
| 261 } |
| 262 } |
| 263 |
248 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) | 264 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) |
249 { | 265 { |
250 AVIContext *avi = s->priv_data; | 266 AVIContext *avi = s->priv_data; |
251 ByteIOContext *pb = s->pb; | 267 ByteIOContext *pb = s->pb; |
252 unsigned int tag, tag1, handler; | 268 unsigned int tag, tag1, handler; |
253 int codec_type, stream_index, frame_period, bit_rate; | 269 int codec_type, stream_index, frame_period, bit_rate; |
254 unsigned int size; | 270 unsigned int size; |
255 int i; | 271 int i; |
256 AVStream *st; | 272 AVStream *st; |
257 AVIStream *ast = NULL; | 273 AVIStream *ast = NULL; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 #ifdef DEBUG | 305 #ifdef DEBUG |
290 print_tag("list", tag1, 0); | 306 print_tag("list", tag1, 0); |
291 #endif | 307 #endif |
292 if (tag1 == MKTAG('m', 'o', 'v', 'i')) { | 308 if (tag1 == MKTAG('m', 'o', 'v', 'i')) { |
293 avi->movi_list = url_ftell(pb) - 4; | 309 avi->movi_list = url_ftell(pb) - 4; |
294 if(size) avi->movi_end = avi->movi_list + size + (size & 1); | 310 if(size) avi->movi_end = avi->movi_list + size + (size & 1); |
295 else avi->movi_end = url_fsize(pb); | 311 else avi->movi_end = url_fsize(pb); |
296 dprintf(NULL, "movi end=%"PRIx64"\n", avi->movi_end); | 312 dprintf(NULL, "movi end=%"PRIx64"\n", avi->movi_end); |
297 goto end_of_header; | 313 goto end_of_header; |
298 } | 314 } |
| 315 else if (tag1 == MKTAG('I', 'N', 'F', 'O')) |
| 316 avi_read_info(s, list_end); |
| 317 |
299 break; | 318 break; |
300 case MKTAG('d', 'm', 'l', 'h'): | 319 case MKTAG('d', 'm', 'l', 'h'): |
301 avi->is_odml = 1; | 320 avi->is_odml = 1; |
302 url_fskip(pb, size + (size & 1)); | 321 url_fskip(pb, size + (size & 1)); |
303 break; | 322 break; |
304 case MKTAG('a', 'm', 'v', 'h'): | 323 case MKTAG('a', 'm', 'v', 'h'): |
305 amv_file_format=1; | 324 amv_file_format=1; |
306 case MKTAG('a', 'v', 'i', 'h'): | 325 case MKTAG('a', 'v', 'i', 'h'): |
307 /* AVI header */ | 326 /* AVI header */ |
308 /* using frame_period is bad idea */ | 327 /* using frame_period is bad idea */ |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 get_le32(pb); //nbFieldsPerFrame | 613 get_le32(pb); //nbFieldsPerFrame |
595 | 614 |
596 if(active_aspect.num && active_aspect.den && active.num && activ
e.den){ | 615 if(active_aspect.num && active_aspect.den && active.num && activ
e.den){ |
597 st->sample_aspect_ratio= av_div_q(active_aspect, active); | 616 st->sample_aspect_ratio= av_div_q(active_aspect, active); |
598 //av_log(s, AV_LOG_ERROR, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect
.den, active.num, active.den); | 617 //av_log(s, AV_LOG_ERROR, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect
.den, active.num, active.den); |
599 } | 618 } |
600 size -= 9*4; | 619 size -= 9*4; |
601 } | 620 } |
602 url_fseek(pb, size, SEEK_CUR); | 621 url_fseek(pb, size, SEEK_CUR); |
603 break; | 622 break; |
604 case MKTAG('I', 'N', 'A', 'M'): | 623 case MKTAG('s', 't', 'r', 'n'): |
605 avi_read_tag(s, "Title", size); | 624 if(s->nb_streams){ |
606 break; | 625 avi_read_tag(s, s->streams[s->nb_streams-1], tag, size); |
607 case MKTAG('I', 'A', 'R', 'T'): | 626 break; |
608 avi_read_tag(s, "Artist", size); | 627 } |
609 break; | |
610 case MKTAG('I', 'C', 'O', 'P'): | |
611 avi_read_tag(s, "Copyright", size); | |
612 break; | |
613 case MKTAG('I', 'C', 'M', 'T'): | |
614 avi_read_tag(s, "Comment", size); | |
615 break; | |
616 case MKTAG('I', 'G', 'N', 'R'): | |
617 avi_read_tag(s, "Genre", size); | |
618 break; | |
619 case MKTAG('I', 'P', 'R', 'D'): | |
620 avi_read_tag(s, "Album", size); | |
621 break; | |
622 case MKTAG('I', 'P', 'R', 'T'): | |
623 avi_read_tag(s, "Track", size); | |
624 break; | |
625 default: | 628 default: |
626 if(size > 1000000){ | 629 if(size > 1000000){ |
627 av_log(s, AV_LOG_ERROR, "Something went wrong during header pars
ing, " | 630 av_log(s, AV_LOG_ERROR, "Something went wrong during header pars
ing, " |
628 "I will ignore it and try to continue an
yway.\n"); | 631 "I will ignore it and try to continue an
yway.\n"); |
629 avi->movi_list = url_ftell(pb) - 4; | 632 avi->movi_list = url_ftell(pb) - 4; |
630 avi->movi_end = url_fsize(pb); | 633 avi->movi_end = url_fsize(pb); |
631 goto end_of_header; | 634 goto end_of_header; |
632 } | 635 } |
633 /* skip tag */ | 636 /* skip tag */ |
634 size += (size & 1); | 637 size += (size & 1); |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 | 1176 |
1174 AVInputFormat avi_demuxer = { | 1177 AVInputFormat avi_demuxer = { |
1175 "avi", | 1178 "avi", |
1176 NULL_IF_CONFIG_SMALL("AVI format"), | 1179 NULL_IF_CONFIG_SMALL("AVI format"), |
1177 sizeof(AVIContext), | 1180 sizeof(AVIContext), |
1178 avi_probe, | 1181 avi_probe, |
1179 avi_read_header, | 1182 avi_read_header, |
1180 avi_read_packet, | 1183 avi_read_packet, |
1181 avi_read_close, | 1184 avi_read_close, |
1182 avi_read_seek, | 1185 avi_read_seek, |
| 1186 .metadata_conv = ff_avi_metadata_conv, |
1183 }; | 1187 }; |
OLD | NEW |