comparison img.c @ 199:66a05c4f8350 libavformat

suppressed frame number modulus hack - added loop_input hack which I find easier to understand
author bellard
date Sun, 24 Aug 2003 21:20:44 +0000
parents e3cfb9131dfa
children 8ca8b6bc24a5
comparison
equal deleted inserted replaced
198:64dbc0b60dbe 199:66a05c4f8350
18 */ 18 */
19 #include <unistd.h> 19 #include <unistd.h>
20 #include "avformat.h" 20 #include "avformat.h"
21 #include "os_support.h" 21 #include "os_support.h"
22 22
23 /* XXX: this is a hack */
24 int loop_input = 0;
25
23 typedef struct { 26 typedef struct {
24 int width; 27 int width;
25 int height; 28 int height;
29 int img_first;
30 int img_last;
26 int img_number; 31 int img_number;
32 int img_count;
27 int img_size; 33 int img_size;
28 AVImageFormat *img_fmt; 34 AVImageFormat *img_fmt;
29 int pix_fmt; 35 int pix_fmt;
30 int is_pipe; 36 int is_pipe;
31 char path[1024]; 37 char path[1024];
119 if (ap && ap->image_format) 125 if (ap && ap->image_format)
120 s->img_fmt = ap->image_format; 126 s->img_fmt = ap->image_format;
121 127
122 strcpy(s->path, s1->filename); 128 strcpy(s->path, s1->filename);
123 s->img_number = 0; 129 s->img_number = 0;
124 130 s->img_count = 0;
131
125 /* find format */ 132 /* find format */
126 if (s1->iformat->flags & AVFMT_NOFILE) 133 if (s1->iformat->flags & AVFMT_NOFILE)
127 s->is_pipe = 0; 134 s->is_pipe = 0;
128 else 135 else
129 s->is_pipe = 1; 136 s->is_pipe = 1;
137 } 144 }
138 145
139 if (!s->is_pipe) { 146 if (!s->is_pipe) {
140 if (find_image_range(&first_index, &last_index, s->path) < 0) 147 if (find_image_range(&first_index, &last_index, s->path) < 0)
141 goto fail; 148 goto fail;
149 s->img_first = first_index;
150 s->img_last = last_index;
142 s->img_number = first_index; 151 s->img_number = first_index;
143 /* compute duration */ 152 /* compute duration */
144 st->start_time = 0; 153 st->start_time = 0;
145 st->duration = ((int64_t)AV_TIME_BASE * 154 st->duration = ((int64_t)AV_TIME_BASE *
146 (last_index - first_index + 1) * 155 (last_index - first_index + 1) *
196 char filename[1024]; 205 char filename[1024];
197 int ret; 206 int ret;
198 ByteIOContext f1, *f; 207 ByteIOContext f1, *f;
199 208
200 if (!s->is_pipe) { 209 if (!s->is_pipe) {
210 /* loop over input */
211 if (loop_input && s->img_number > s->img_last) {
212 s->img_number = s->img_first;
213 }
201 if (get_frame_filename(filename, sizeof(filename), 214 if (get_frame_filename(filename, sizeof(filename),
202 s->path, s->img_number) < 0) 215 s->path, s->img_number) < 0)
203 return -EIO; 216 return -EIO;
204 f = &f1; 217 f = &f1;
205 if (url_fopen(f, filename, URL_RDONLY) < 0) 218 if (url_fopen(f, filename, URL_RDONLY) < 0)
221 234
222 if (ret < 0) { 235 if (ret < 0) {
223 av_free_packet(pkt); 236 av_free_packet(pkt);
224 return -EIO; /* signal EOF */ 237 return -EIO; /* signal EOF */
225 } else { 238 } else {
226 pkt->pts = av_rescale((int64_t)s->img_number * s1->streams[0]->codec.frame_rate_base, s1->pts_den, s1->streams[0]->codec.frame_rate) / s1->pts_num; 239 /* XXX: computing this pts is not necessary as it is done in
240 the generic code too */
241 pkt->pts = av_rescale((int64_t)s->img_count * s1->streams[0]->codec.frame_rate_base, s1->pts_den, s1->streams[0]->codec.frame_rate) / s1->pts_num;
242 s->img_count++;
227 s->img_number++; 243 s->img_number++;
228 return 0; 244 return 0;
229 } 245 }
230 } 246 }
231 247