Revision 9150f42e

View differences:

libav/img.c
169 169
    int ret;
170 170
    ByteIOContext f1, *f;
171 171

  
172
    snprintf(filename, sizeof(filename), s->path, s->img_number);
172
    if (get_frame_filename(filename, sizeof(filename),
173
                           s->path, s->img_number) < 0)
174
        return -EIO;
173 175
    
174 176
    if (!s->is_pipe) {
175 177
        f = &f1;
......
223 225
    { 160, 128 },
224 226
    { 512, 384 },
225 227
    { 640, 352 },
228
    { 640, 240 },
226 229
};
227 230

  
228 231
static int infer_size(int *width_ptr, int *height_ptr, int size)
......
288 291
    if (!s->is_pipe) {
289 292
        /* try to find the first image */
290 293
        for(i=0;i<5;i++) {
291
            snprintf(buf, sizeof(buf), s->path, s->img_number);
294
            if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
295
                goto fail;
292 296
            if (url_fopen(f, buf, URL_RDONLY) >= 0)
293 297
                break;
294 298
            s->img_number++;
......
543 547
        return -EIO;
544 548
    }
545 549
    
546
    snprintf(filename, sizeof(filename), img->path, img->img_number);
550
    if (get_frame_filename(filename, sizeof(filename), 
551
                           img->path, img->img_number) < 0)
552
        return -EIO;
547 553

  
548 554
    if (!img->is_pipe) {
549 555
        pb = &pb1;
......
596 602
    img_read_packet,
597 603
    img_read_close,
598 604
    NULL,
599
    AVFMT_NOFILE,
605
    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
600 606
};
601 607

  
602 608
AVFormat pgmyuv_format = {
......
614 620
    img_read_packet,
615 621
    img_read_close,
616 622
    NULL,
617
    AVFMT_NOFILE,
623
    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
618 624
};
619 625

  
620 626
AVFormat ppm_format = {
......
632 638
    img_read_packet,
633 639
    img_read_close,
634 640
    NULL,
635
    AVFMT_NOFILE,
641
    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
636 642
};
637 643

  
638 644
AVFormat imgyuv_format = {
......
650 656
    img_read_packet,
651 657
    img_read_close,
652 658
    NULL,
653
    AVFMT_NOFILE,
659
    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
654 660
};
655 661

  
656 662
AVFormat pgmpipe_format = {
libav/jpeg.c
1 1
/*
2
 * Miscellaneous MJPEG based formats
3
 * Copyright (c) 2000 Gerard Lantau.
2
 * JPEG based formats
3
 * Copyright (c) 2000, 2001 Gerard Lantau.
4 4
 *
5 5
 * This program is free software; you can redistribute it and/or modify
6 6
 * it under the terms of the GNU General Public License as published by
......
126 126
    char filename[1024];
127 127
    ByteIOContext f1, *pb = &f1;
128 128

  
129
    snprintf(filename, sizeof(filename), s->path, s->img_number);
129
    if (get_frame_filename(filename, sizeof(filename), 
130
                           s->path, s->img_number) < 0)
131
        return -EIO;
130 132
    if (url_fopen(pb, filename, URL_WRONLY) < 0)
131 133
        return -EIO;
132 134

  
......
173 175

  
174 176
    /* try to find the first image */
175 177
    for(i=0;i<5;i++) {
176
        snprintf(buf, sizeof(buf), s->path, s->img_number);
178
        if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
179
            goto fail;
177 180
        if (url_fopen(f, buf, URL_RDONLY) >= 0)
178 181
            break;
179 182
        s->img_number++;
......
201 204
    int size;
202 205
    ByteIOContext f1, *f = &f1;
203 206

  
204
    snprintf(filename, sizeof(filename), s->path, s->img_number);
207
    if (get_frame_filename(filename, sizeof(filename), 
208
                           s->path, s->img_number) < 0)
209
        return -EIO;
205 210
    
206 211
    f = &f1;
207 212
    if (url_fopen(f, filename, URL_RDONLY) < 0)
......
241 246
    jpeg_read_packet,
242 247
    jpeg_read_close,
243 248
    NULL,
244
    AVFMT_NOFILE,
249
    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
245 250
};
libav/utils.c
548 548
    return 0;
549 549
}
550 550

  
551
/* Return in 'buf' the path with '%d' replaced by number. Also handles
552
   the '%0nd' format where 'n' is the total number of digits and
553
   '%%'. Return 0 if OK, and -1 if format error */
554
int get_frame_filename(char *buf, int buf_size,
555
                       const char *path, int number)
556
{
557
    const char *p;
558
    char *q, buf1[20];
559
    int nd, len, c, percentd_found;
560

  
561
    q = buf;
562
    p = path;
563
    percentd_found = 0;
564
    for(;;) {
565
        c = *p++;
566
        if (c == '\0')
567
            break;
568
        if (c == '%') {
569
            nd = 0;
570
            while (*p >= '0' && *p <= '9') {
571
                nd = nd * 10 + *p++ - '0';
572
            }
573
            c = *p++;
574
            switch(c) {
575
            case '%':
576
                goto addchar;
577
            case 'd':
578
                if (percentd_found)
579
                    goto fail;
580
                percentd_found = 1;
581
                snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
582
                len = strlen(buf1);
583
                if ((q - buf + len) > buf_size - 1)
584
                    goto fail;
585
                memcpy(q, buf1, len);
586
                q += len;
587
                break;
588
            default:
589
                goto fail;
590
            }
591
        } else {
592
        addchar:
593
            if ((q - buf) < buf_size - 1)
594
                *q++ = c;
595
        }
596
    }
597
    if (!percentd_found)
598
        goto fail;
599
    *q = '\0';
600
    return 0;
601
 fail:
602
    *q = '\0';
603
    return -1;
604
}
605

  
606

  

Also available in: Unified diff