[SCM] libav/experimental: fixed image number syntax problems

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 15:30:03 UTC 2013


The following commit has been merged in the experimental branch:
commit 9150f42ed529f41533211618e3ce2895742e71a9
Author: Fabrice Bellard <fabrice at bellard.org>
Date:   Sun Sep 16 21:50:48 2001 +0000

    fixed image number syntax problems
    
    
    Originally committed as revision 128 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libav/img.c b/libav/img.c
index b64dfdb..710530b 100644
--- a/libav/img.c
+++ b/libav/img.c
@@ -169,7 +169,9 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
     int ret;
     ByteIOContext f1, *f;
 
-    snprintf(filename, sizeof(filename), s->path, s->img_number);
+    if (get_frame_filename(filename, sizeof(filename),
+                           s->path, s->img_number) < 0)
+        return -EIO;
     
     if (!s->is_pipe) {
         f = &f1;
@@ -223,6 +225,7 @@ static int sizes[][2] = {
     { 160, 128 },
     { 512, 384 },
     { 640, 352 },
+    { 640, 240 },
 };
 
 static int infer_size(int *width_ptr, int *height_ptr, int size)
@@ -288,7 +291,8 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
     if (!s->is_pipe) {
         /* try to find the first image */
         for(i=0;i<5;i++) {
-            snprintf(buf, sizeof(buf), s->path, s->img_number);
+            if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
+                goto fail;
             if (url_fopen(f, buf, URL_RDONLY) >= 0)
                 break;
             s->img_number++;
@@ -543,7 +547,9 @@ static int img_write_packet(AVFormatContext *s, int stream_index,
         return -EIO;
     }
     
-    snprintf(filename, sizeof(filename), img->path, img->img_number);
+    if (get_frame_filename(filename, sizeof(filename), 
+                           img->path, img->img_number) < 0)
+        return -EIO;
 
     if (!img->is_pipe) {
         pb = &pb1;
@@ -596,7 +602,7 @@ AVFormat pgm_format = {
     img_read_packet,
     img_read_close,
     NULL,
-    AVFMT_NOFILE,
+    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
 };
 
 AVFormat pgmyuv_format = {
@@ -614,7 +620,7 @@ AVFormat pgmyuv_format = {
     img_read_packet,
     img_read_close,
     NULL,
-    AVFMT_NOFILE,
+    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
 };
 
 AVFormat ppm_format = {
@@ -632,7 +638,7 @@ AVFormat ppm_format = {
     img_read_packet,
     img_read_close,
     NULL,
-    AVFMT_NOFILE,
+    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
 };
 
 AVFormat imgyuv_format = {
@@ -650,7 +656,7 @@ AVFormat imgyuv_format = {
     img_read_packet,
     img_read_close,
     NULL,
-    AVFMT_NOFILE,
+    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
 };
 
 AVFormat pgmpipe_format = {
diff --git a/libav/jpeg.c b/libav/jpeg.c
index 3d1463a..531e797 100644
--- a/libav/jpeg.c
+++ b/libav/jpeg.c
@@ -1,6 +1,6 @@
 /*
- * Miscellaneous MJPEG based formats
- * Copyright (c) 2000 Gerard Lantau.
+ * JPEG based formats
+ * Copyright (c) 2000, 2001 Gerard Lantau.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -126,7 +126,9 @@ static int jpeg_write_packet(AVFormatContext *s1, int stream_index,
     char filename[1024];
     ByteIOContext f1, *pb = &f1;
 
-    snprintf(filename, sizeof(filename), s->path, s->img_number);
+    if (get_frame_filename(filename, sizeof(filename), 
+                           s->path, s->img_number) < 0)
+        return -EIO;
     if (url_fopen(pb, filename, URL_WRONLY) < 0)
         return -EIO;
 
@@ -173,7 +175,8 @@ static int jpeg_read_header(AVFormatContext *s1, AVFormatParameters *ap)
 
     /* try to find the first image */
     for(i=0;i<5;i++) {
-        snprintf(buf, sizeof(buf), s->path, s->img_number);
+        if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
+            goto fail;
         if (url_fopen(f, buf, URL_RDONLY) >= 0)
             break;
         s->img_number++;
@@ -201,7 +204,9 @@ static int jpeg_read_packet(AVFormatContext *s1, AVPacket *pkt)
     int size;
     ByteIOContext f1, *f = &f1;
 
-    snprintf(filename, sizeof(filename), s->path, s->img_number);
+    if (get_frame_filename(filename, sizeof(filename), 
+                           s->path, s->img_number) < 0)
+        return -EIO;
     
     f = &f1;
     if (url_fopen(f, filename, URL_RDONLY) < 0)
@@ -241,5 +246,5 @@ AVFormat jpeg_format = {
     jpeg_read_packet,
     jpeg_read_close,
     NULL,
-    AVFMT_NOFILE,
+    AVFMT_NOFILE | AVFMT_NEEDNUMBER,
 };
diff --git a/libav/utils.c b/libav/utils.c
index 87f3f01..a2bc404 100644
--- a/libav/utils.c
+++ b/libav/utils.c
@@ -548,3 +548,59 @@ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
     return 0;
 }
 
+/* Return in 'buf' the path with '%d' replaced by number. Also handles
+   the '%0nd' format where 'n' is the total number of digits and
+   '%%'. Return 0 if OK, and -1 if format error */
+int get_frame_filename(char *buf, int buf_size,
+                       const char *path, int number)
+{
+    const char *p;
+    char *q, buf1[20];
+    int nd, len, c, percentd_found;
+
+    q = buf;
+    p = path;
+    percentd_found = 0;
+    for(;;) {
+        c = *p++;
+        if (c == '\0')
+            break;
+        if (c == '%') {
+            nd = 0;
+            while (*p >= '0' && *p <= '9') {
+                nd = nd * 10 + *p++ - '0';
+            }
+            c = *p++;
+            switch(c) {
+            case '%':
+                goto addchar;
+            case 'd':
+                if (percentd_found)
+                    goto fail;
+                percentd_found = 1;
+                snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
+                len = strlen(buf1);
+                if ((q - buf + len) > buf_size - 1)
+                    goto fail;
+                memcpy(q, buf1, len);
+                q += len;
+                break;
+            default:
+                goto fail;
+            }
+        } else {
+        addchar:
+            if ((q - buf) < buf_size - 1)
+                *q++ = c;
+        }
+    }
+    if (!percentd_found)
+        goto fail;
+    *q = '\0';
+    return 0;
+ fail:
+    *q = '\0';
+    return -1;
+}
+
+

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list