Mercurial > libavformat.hg
comparison img2.c @ 498:7c8687cb7f27 libavformat
support single images, remove copy/paste junk
author | michael |
---|---|
date | Thu, 15 Jul 2004 20:15:40 +0000 |
parents | d95e74ef39e0 |
children | c7219ac0b694 |
comparison
equal
deleted
inserted
replaced
497:d95e74ef39e0 | 498:7c8687cb7f27 |
---|---|
78 char buf[1024]; | 78 char buf[1024]; |
79 int range, last_index, range1, first_index; | 79 int range, last_index, range1, first_index; |
80 | 80 |
81 /* find the first image */ | 81 /* find the first image */ |
82 for(first_index = 0; first_index < 5; first_index++) { | 82 for(first_index = 0; first_index < 5; first_index++) { |
83 if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0) | 83 if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ |
84 goto fail; | 84 *pfirst_index = |
85 *plast_index = 1; | |
86 return 0; | |
87 } | |
85 if (url_exist(buf)) | 88 if (url_exist(buf)) |
86 break; | 89 break; |
87 } | 90 } |
88 if (first_index == 5) | 91 if (first_index == 5) |
89 goto fail; | 92 goto fail; |
130 | 133 |
131 static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) | 134 static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) |
132 { | 135 { |
133 VideoData *s = s1->priv_data; | 136 VideoData *s = s1->priv_data; |
134 int first_index, last_index; | 137 int first_index, last_index; |
135 char buf[1024]; | |
136 ByteIOContext pb1, *f = &pb1; | |
137 AVStream *st; | 138 AVStream *st; |
138 | 139 |
139 s1->ctx_flags |= AVFMTCTX_NOHEADER; | 140 s1->ctx_flags |= AVFMTCTX_NOHEADER; |
140 | 141 |
141 st = av_new_stream(s1, 0); | 142 st = av_new_stream(s1, 0); |
171 /* compute duration */ | 172 /* compute duration */ |
172 st->start_time = 0; | 173 st->start_time = 0; |
173 st->duration = ((int64_t)AV_TIME_BASE * | 174 st->duration = ((int64_t)AV_TIME_BASE * |
174 (last_index - first_index + 1) * | 175 (last_index - first_index + 1) * |
175 st->codec.frame_rate_base) / st->codec.frame_rate; | 176 st->codec.frame_rate_base) / st->codec.frame_rate; |
176 if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0) | |
177 goto fail; | |
178 if (url_fopen(f, buf, URL_RDONLY) < 0) | |
179 goto fail; | |
180 } else { | |
181 f = &s1->pb; | |
182 } | |
183 | |
184 if (!s->is_pipe) { | |
185 url_fclose(f); | |
186 } else { | |
187 url_fseek(f, 0, SEEK_SET); | |
188 } | 177 } |
189 | 178 |
190 st->codec.codec_type = CODEC_TYPE_VIDEO; | 179 st->codec.codec_type = CODEC_TYPE_VIDEO; |
191 st->codec.codec_id = av_str2id(img_tags, s->path); | 180 st->codec.codec_id = av_str2id(img_tags, s->path); |
192 | 181 |
193 return 0; | 182 return 0; |
194 | 183 |
195 if (!s->is_pipe) | |
196 url_fclose(f); | |
197 fail: | 184 fail: |
198 av_free(s); | 185 av_free(s); |
199 return AVERROR_IO; | 186 return AVERROR_IO; |
200 } | 187 } |
201 | 188 |
210 /* loop over input */ | 197 /* loop over input */ |
211 /* if (loop_input && s->img_number > s->img_last) { | 198 /* if (loop_input && s->img_number > s->img_last) { |
212 s->img_number = s->img_first; | 199 s->img_number = s->img_first; |
213 }*/ | 200 }*/ |
214 if (get_frame_filename(filename, sizeof(filename), | 201 if (get_frame_filename(filename, sizeof(filename), |
215 s->path, s->img_number) < 0) | 202 s->path, s->img_number)<0 && s->img_number > 1) |
216 return AVERROR_IO; | 203 return AVERROR_IO; |
217 f = &f1; | 204 f = &f1; |
218 if (url_fopen(f, filename, URL_RDONLY) < 0) | 205 if (url_fopen(f, filename, URL_RDONLY) < 0) |
219 return AVERROR_IO; | 206 return AVERROR_IO; |
220 } else { | 207 } else { |
276 ByteIOContext pb1, *pb; | 263 ByteIOContext pb1, *pb; |
277 char filename[1024]; | 264 char filename[1024]; |
278 | 265 |
279 if (!img->is_pipe) { | 266 if (!img->is_pipe) { |
280 if (get_frame_filename(filename, sizeof(filename), | 267 if (get_frame_filename(filename, sizeof(filename), |
281 img->path, img->img_number) < 0) | 268 img->path, img->img_number) < 0 && img->img_number>1) |
282 return AVERROR_IO; | 269 return AVERROR_IO; |
283 pb = &pb1; | 270 pb = &pb1; |
284 if (url_fopen(pb, filename, URL_WRONLY) < 0) | 271 if (url_fopen(pb, filename, URL_WRONLY) < 0) |
285 return AVERROR_IO; | 272 return AVERROR_IO; |
286 } else { | 273 } else { |
312 img_read_header, | 299 img_read_header, |
313 img_read_packet, | 300 img_read_packet, |
314 img_read_close, | 301 img_read_close, |
315 NULL, | 302 NULL, |
316 NULL, | 303 NULL, |
317 AVFMT_NOFILE | AVFMT_NEEDNUMBER, | 304 AVFMT_NOFILE, |
318 }; | 305 }; |
319 | 306 |
320 static AVInputFormat image2pipe_iformat = { | 307 static AVInputFormat image2pipe_iformat = { |
321 "image2pipe", | 308 "image2pipe", |
322 "piped image2 sequence", | 309 "piped image2 sequence", |
340 CODEC_ID_NONE, | 327 CODEC_ID_NONE, |
341 CODEC_ID_MJPEG, | 328 CODEC_ID_MJPEG, |
342 img_write_header, | 329 img_write_header, |
343 img_write_packet, | 330 img_write_packet, |
344 img_write_trailer, | 331 img_write_trailer, |
345 AVFMT_NOFILE | AVFMT_NEEDNUMBER, | 332 AVFMT_NOFILE, |
346 }; | 333 }; |
347 | 334 |
348 static AVOutputFormat image2pipe_oformat = { | 335 static AVOutputFormat image2pipe_oformat = { |
349 "image2pipe", | 336 "image2pipe", |
350 "piped image2 sequence", | 337 "piped image2 sequence", |