Mercurial > libavformat.hg
annotate img2.c @ 1388:3172bf94c066 libavformat
Use proper PRI?64 macros for %ll? format to fix printf format warnings:
utils.c:833: warning: format ¡Æ%lld¡Ç expects type ¡Ælong long int¡Ç, but argument 5 has type ¡Æint64_t¡Ç
utils.c:833: warning: format ¡Æ%lld¡Ç expects type ¡Ælong long int¡Ç, but argument 6 has type ¡Æint64_t¡Ç
utils.c:854: warning: format ¡Æ%lld¡Ç expects type ¡Ælong long int¡Ç, but argument 5 has type ¡Æint64_t¡Ç
utils.c:854: warning: format ¡Æ%lld¡Ç expects type ¡Ælong long int¡Ç, but argument 6 has type ¡Æint64_t¡Ç
asf.c:872: warning: format ¡Æ%Lx¡Ç expects type ¡Ælong long unsigned int¡Ç, but argument 4 has type ¡Æint64_t¡Ç
mov.c:1754: warning: format ¡Æ%llx¡Ç expects type ¡Ælong long unsigned int¡Ç, but argument 5 has type ¡Æint64_t¡Ç
Approved by Michael.
author | rathann |
---|---|
date | Sat, 14 Oct 2006 20:43:39 +0000 |
parents | 0899bfe4105c |
children | 403621d48275 |
rev | line source |
---|---|
497 | 1 /* |
2 * Image format | |
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. | |
4 * Copyright (c) 2004 Michael Niedermayer | |
5 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1291
diff
changeset
|
6 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1291
diff
changeset
|
7 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1291
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
497 | 9 * modify it under the terms of the GNU Lesser General Public |
10 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1291
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
497 | 12 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1291
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
497 | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1291
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
497 | 21 */ |
22 #include "avformat.h" | |
23 | |
24 typedef struct { | |
25 int img_first; | |
26 int img_last; | |
27 int img_number; | |
28 int img_count; | |
29 int is_pipe; | |
30 char path[1024]; | |
31 } VideoData; | |
32 | |
33 typedef struct { | |
34 enum CodecID id; | |
35 const char *str; | |
36 } IdStrMap; | |
37 | |
38 static const IdStrMap img_tags[] = { | |
39 { CODEC_ID_MJPEG , "jpeg"}, | |
40 { CODEC_ID_MJPEG , "jpg"}, | |
41 { CODEC_ID_LJPEG , "ljpg"}, | |
581 | 42 { CODEC_ID_PNG , "png"}, |
583 | 43 { CODEC_ID_PPM , "ppm"}, |
44 { CODEC_ID_PGM , "pgm"}, | |
45 { CODEC_ID_PGMYUV , "pgmyuv"}, | |
46 { CODEC_ID_PBM , "pbm"}, | |
47 { CODEC_ID_PAM , "pam"}, | |
497 | 48 { CODEC_ID_MPEG1VIDEO, "mpg1-img"}, |
49 { CODEC_ID_MPEG2VIDEO, "mpg2-img"}, | |
50 { CODEC_ID_MPEG4 , "mpg4-img"}, | |
51 { CODEC_ID_FFV1 , "ffv1-img"}, | |
635 | 52 { CODEC_ID_RAWVIDEO , "y"}, |
875 | 53 { CODEC_ID_BMP , "bmp"}, |
497 | 54 {0, NULL} |
55 }; | |
56 | |
635 | 57 static int sizes[][2] = { |
58 { 640, 480 }, | |
59 { 720, 480 }, | |
60 { 720, 576 }, | |
61 { 352, 288 }, | |
62 { 352, 240 }, | |
63 { 160, 128 }, | |
64 { 512, 384 }, | |
65 { 640, 352 }, | |
66 { 640, 240 }, | |
67 }; | |
68 | |
69 static int infer_size(int *width_ptr, int *height_ptr, int size) | |
70 { | |
71 int i; | |
72 | |
73 for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) { | |
74 if ((sizes[i][0] * sizes[i][1]) == size) { | |
75 *width_ptr = sizes[i][0]; | |
76 *height_ptr = sizes[i][1]; | |
77 return 0; | |
78 } | |
79 } | |
80 return -1; | |
81 } | |
497 | 82 static enum CodecID av_str2id(const IdStrMap *tags, const char *str) |
83 { | |
530 | 84 str= strrchr(str, '.'); |
85 if(!str) return CODEC_ID_NONE; | |
86 str++; | |
497 | 87 |
88 while (tags->id) { | |
89 int i; | |
90 for(i=0; toupper(tags->str[i]) == toupper(str[i]); i++){ | |
91 if(tags->str[i]==0 && str[i]==0) | |
92 return tags->id; | |
93 } | |
94 | |
95 tags++; | |
96 } | |
97 return CODEC_ID_NONE; | |
98 } | |
99 | |
100 /* return -1 if no image found */ | |
885 | 101 static int find_image_range(int *pfirst_index, int *plast_index, |
497 | 102 const char *path) |
103 { | |
104 char buf[1024]; | |
105 int range, last_index, range1, first_index; | |
106 | |
107 /* find the first image */ | |
108 for(first_index = 0; first_index < 5; first_index++) { | |
1291
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
109 if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ |
885 | 110 *pfirst_index = |
498 | 111 *plast_index = 1; |
112 return 0; | |
113 } | |
497 | 114 if (url_exist(buf)) |
115 break; | |
116 } | |
117 if (first_index == 5) | |
118 goto fail; | |
885 | 119 |
497 | 120 /* find the last image */ |
121 last_index = first_index; | |
122 for(;;) { | |
123 range = 0; | |
124 for(;;) { | |
125 if (!range) | |
126 range1 = 1; | |
127 else | |
128 range1 = 2 * range; | |
1291
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
129 if (av_get_frame_filename(buf, sizeof(buf), path, |
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
130 last_index + range1) < 0) |
497 | 131 goto fail; |
132 if (!url_exist(buf)) | |
133 break; | |
134 range = range1; | |
135 /* just in case... */ | |
136 if (range >= (1 << 30)) | |
137 goto fail; | |
138 } | |
139 /* we are sure than image last_index + range exists */ | |
140 if (!range) | |
141 break; | |
142 last_index += range; | |
143 } | |
144 *pfirst_index = first_index; | |
145 *plast_index = last_index; | |
146 return 0; | |
147 fail: | |
148 return -1; | |
149 } | |
150 | |
151 | |
152 static int image_probe(AVProbeData *p) | |
153 { | |
1291
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
154 if (av_filename_number_test(p->filename) && av_str2id(img_tags, p->filename)) |
497 | 155 return AVPROBE_SCORE_MAX; |
156 else | |
157 return 0; | |
158 } | |
159 | |
583 | 160 enum CodecID av_guess_image2_codec(const char *filename){ |
161 return av_str2id(img_tags, filename); | |
162 } | |
163 | |
497 | 164 static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) |
165 { | |
166 VideoData *s = s1->priv_data; | |
167 int first_index, last_index; | |
168 AVStream *st; | |
169 | |
170 s1->ctx_flags |= AVFMTCTX_NOHEADER; | |
171 | |
172 st = av_new_stream(s1, 0); | |
173 if (!st) { | |
174 return -ENOMEM; | |
175 } | |
176 | |
639 | 177 pstrcpy(s->path, sizeof(s->path), s1->filename); |
497 | 178 s->img_number = 0; |
179 s->img_count = 0; | |
885 | 180 |
497 | 181 /* find format */ |
182 if (s1->iformat->flags & AVFMT_NOFILE) | |
183 s->is_pipe = 0; | |
574 | 184 else{ |
497 | 185 s->is_pipe = 1; |
574 | 186 st->need_parsing= 1; |
187 } | |
885 | 188 |
1003 | 189 if (!ap->time_base.num) { |
743 | 190 av_set_pts_info(st, 60, 1, 25); |
497 | 191 } else { |
743 | 192 av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); |
497 | 193 } |
885 | 194 |
1003 | 195 if(ap->width && ap->height){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
196 st->codec->width = ap->width; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
197 st->codec->height= ap->height; |
635 | 198 } |
885 | 199 |
497 | 200 if (!s->is_pipe) { |
201 if (find_image_range(&first_index, &last_index, s->path) < 0) | |
622 | 202 return AVERROR_IO; |
497 | 203 s->img_first = first_index; |
204 s->img_last = last_index; | |
205 s->img_number = first_index; | |
206 /* compute duration */ | |
207 st->start_time = 0; | |
743 | 208 st->duration = last_index - first_index + 1; |
497 | 209 } |
885 | 210 |
583 | 211 if(ap->video_codec_id){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
212 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:
764
diff
changeset
|
213 st->codec->codec_id = ap->video_codec_id; |
583 | 214 }else if(ap->audio_codec_id){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
215 st->codec->codec_type = CODEC_TYPE_AUDIO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
216 st->codec->codec_id = ap->audio_codec_id; |
583 | 217 }else{ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
218 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:
764
diff
changeset
|
219 st->codec->codec_id = av_str2id(img_tags, s->path); |
583 | 220 } |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
221 if(st->codec->codec_type == CODEC_TYPE_VIDEO && ap->pix_fmt != PIX_FMT_NONE) |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
222 st->codec->pix_fmt = ap->pix_fmt; |
497 | 223 |
224 return 0; | |
225 } | |
226 | |
227 static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) | |
228 { | |
229 VideoData *s = s1->priv_data; | |
230 char filename[1024]; | |
635 | 231 int i; |
232 int size[3]={0}, ret[3]={0}; | |
233 ByteIOContext f1[3], *f[3]= {&f1[0], &f1[1], &f1[2]}; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
234 AVCodecContext *codec= s1->streams[0]->codec; |
497 | 235 |
236 if (!s->is_pipe) { | |
237 /* loop over input */ | |
1175
8b53c0f3e7ad
add loop_input to AVFormatContext, getting rid of old hack
mru
parents:
1169
diff
changeset
|
238 if (s1->loop_input && s->img_number > s->img_last) { |
497 | 239 s->img_number = s->img_first; |
590 | 240 } |
1291
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
241 if (av_get_frame_filename(filename, sizeof(filename), |
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
242 s->path, s->img_number)<0 && s->img_number > 1) |
497 | 243 return AVERROR_IO; |
635 | 244 for(i=0; i<3; i++){ |
245 if (url_fopen(f[i], filename, URL_RDONLY) < 0) | |
246 return AVERROR_IO; | |
764
cdb845a57ae4
drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol)
aurel
parents:
743
diff
changeset
|
247 size[i]= url_fsize(f[i]); |
885 | 248 |
635 | 249 if(codec->codec_id != CODEC_ID_RAWVIDEO) |
250 break; | |
251 filename[ strlen(filename) - 1 ]= 'U' + i; | |
252 } | |
885 | 253 |
635 | 254 if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width) |
255 infer_size(&codec->width, &codec->height, size[0]); | |
497 | 256 } else { |
635 | 257 f[0] = &s1->pb; |
258 if (url_feof(f[0])) | |
497 | 259 return AVERROR_IO; |
635 | 260 size[0]= 4096; |
497 | 261 } |
262 | |
635 | 263 av_new_packet(pkt, size[0] + size[1] + size[2]); |
497 | 264 pkt->stream_index = 0; |
265 pkt->flags |= PKT_FLAG_KEY; | |
266 | |
635 | 267 pkt->size= 0; |
268 for(i=0; i<3; i++){ | |
269 if(size[i]){ | |
270 ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]); | |
271 if (!s->is_pipe) | |
272 url_fclose(f[i]); | |
273 if(ret[i]>0) | |
274 pkt->size += ret[i]; | |
275 } | |
497 | 276 } |
277 | |
635 | 278 if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) { |
497 | 279 av_free_packet(pkt); |
280 return AVERROR_IO; /* signal EOF */ | |
281 } else { | |
282 s->img_count++; | |
283 s->img_number++; | |
284 return 0; | |
285 } | |
286 } | |
287 | |
288 static int img_read_close(AVFormatContext *s1) | |
289 { | |
290 return 0; | |
291 } | |
292 | |
903
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
293 #ifdef CONFIG_MUXERS |
497 | 294 /******************************************************/ |
295 /* image output */ | |
296 | |
297 static int img_write_header(AVFormatContext *s) | |
298 { | |
299 VideoData *img = s->priv_data; | |
300 | |
301 img->img_number = 1; | |
639 | 302 pstrcpy(img->path, sizeof(img->path), s->filename); |
497 | 303 |
304 /* find format */ | |
305 if (s->oformat->flags & AVFMT_NOFILE) | |
306 img->is_pipe = 0; | |
307 else | |
308 img->is_pipe = 1; | |
885 | 309 |
497 | 310 return 0; |
311 } | |
312 | |
313 static int img_write_packet(AVFormatContext *s, AVPacket *pkt) | |
314 { | |
315 VideoData *img = s->priv_data; | |
635 | 316 ByteIOContext pb1[3], *pb[3]= {&pb1[0], &pb1[1], &pb1[2]}; |
497 | 317 char filename[1024]; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
318 AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec; |
635 | 319 int i; |
497 | 320 |
321 if (!img->is_pipe) { | |
1291
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
322 if (av_get_frame_filename(filename, sizeof(filename), |
185190bdc185
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
gpoirier
parents:
1175
diff
changeset
|
323 img->path, img->img_number) < 0 && img->img_number>1) |
497 | 324 return AVERROR_IO; |
635 | 325 for(i=0; i<3; i++){ |
326 if (url_fopen(pb[i], filename, URL_WRONLY) < 0) | |
327 return AVERROR_IO; | |
885 | 328 |
635 | 329 if(codec->codec_id != CODEC_ID_RAWVIDEO) |
330 break; | |
331 filename[ strlen(filename) - 1 ]= 'U' + i; | |
332 } | |
497 | 333 } else { |
635 | 334 pb[0] = &s->pb; |
497 | 335 } |
885 | 336 |
635 | 337 if(codec->codec_id == CODEC_ID_RAWVIDEO){ |
731 | 338 int ysize = codec->width * codec->height; |
339 put_buffer(pb[0], pkt->data , ysize); | |
340 put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2); | |
341 put_buffer(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2); | |
635 | 342 put_flush_packet(pb[1]); |
343 put_flush_packet(pb[2]); | |
344 url_fclose(pb[1]); | |
345 url_fclose(pb[2]); | |
346 }else{ | |
347 put_buffer(pb[0], pkt->data, pkt->size); | |
348 } | |
349 put_flush_packet(pb[0]); | |
497 | 350 if (!img->is_pipe) { |
635 | 351 url_fclose(pb[0]); |
497 | 352 } |
353 | |
354 img->img_number++; | |
355 return 0; | |
356 } | |
357 | |
358 static int img_write_trailer(AVFormatContext *s) | |
359 { | |
360 return 0; | |
361 } | |
362 | |
903
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
363 #endif /* CONFIG_MUXERS */ |
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
364 |
497 | 365 /* input */ |
1169 | 366 #ifdef CONFIG_IMAGE2_DEMUXER |
367 AVInputFormat image2_demuxer = { | |
497 | 368 "image2", |
369 "image2 sequence", | |
370 sizeof(VideoData), | |
371 image_probe, | |
372 img_read_header, | |
373 img_read_packet, | |
374 img_read_close, | |
375 NULL, | |
376 NULL, | |
498 | 377 AVFMT_NOFILE, |
497 | 378 }; |
1169 | 379 #endif |
380 #ifdef CONFIG_IMAGE2PIPE_DEMUXER | |
381 AVInputFormat image2pipe_demuxer = { | |
497 | 382 "image2pipe", |
383 "piped image2 sequence", | |
384 sizeof(VideoData), | |
385 NULL, /* no probe */ | |
386 img_read_header, | |
387 img_read_packet, | |
388 img_read_close, | |
389 NULL, | |
390 }; | |
1169 | 391 #endif |
497 | 392 |
393 /* output */ | |
1169 | 394 #ifdef CONFIG_IMAGE2_MUXER |
395 AVOutputFormat image2_muxer = { | |
497 | 396 "image2", |
397 "image2 sequence", | |
398 "", | |
399 "", | |
400 sizeof(VideoData), | |
401 CODEC_ID_NONE, | |
402 CODEC_ID_MJPEG, | |
403 img_write_header, | |
404 img_write_packet, | |
405 img_write_trailer, | |
498 | 406 AVFMT_NOFILE, |
497 | 407 }; |
1169 | 408 #endif |
409 #ifdef CONFIG_IMAGE2PIPE_MUXER | |
410 AVOutputFormat image2pipe_muxer = { | |
497 | 411 "image2pipe", |
412 "piped image2 sequence", | |
413 "", | |
414 "", | |
415 sizeof(VideoData), | |
416 CODEC_ID_NONE, | |
417 CODEC_ID_MJPEG, | |
418 img_write_header, | |
419 img_write_packet, | |
420 img_write_trailer, | |
421 }; | |
903
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
422 #endif |