[FFmpeg-devel] [PATCH 1/2] img2: do not use CODEC_ID_RAWVIDEO to trigger processing of independant y/u/v image files

Peter Ross pross
Sat Feb 12 04:25:43 CET 2011


This patch allows img2 to support other CODEC_ID_RAWVIDEO image file formats.
---
I have split up the original img2-raw patch, to make it more clear. Cheers,

 libavformat/img2.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavformat/img2.c b/libavformat/img2.c
index 9583eea..57b9386 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -31,6 +31,7 @@ typedef struct {
     int img_number;
     int img_count;
     int is_pipe;
+    int is_y;         /**< process independent y,u,v image files */
     char path[1024];
 } VideoData;
 
@@ -240,6 +241,8 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap)
         st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
         st->codec->codec_id = s1->audio_codec_id;
     }else{
+        const char *str= strrchr(s->path, '.');
+        s->is_y = str && !strcasecmp(str + 1, "y");
         st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
         st->codec->codec_id = av_str2id(img_tags, s->path);
     }
@@ -277,7 +280,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
             }
             size[i]= url_fsize(f[i]);
 
-            if(codec->codec_id != CODEC_ID_RAWVIDEO)
+            if(!s->is_y)
                 break;
             filename[ strlen(filename) - 1 ]= 'U' + i;
         }
@@ -323,6 +326,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)
 static int write_header(AVFormatContext *s)
 {
     VideoData *img = s->priv_data;
+    const char *str;
 
     img->img_number = 1;
     av_strlcpy(img->path, s->filename, sizeof(img->path));
@@ -333,6 +337,8 @@ static int write_header(AVFormatContext *s)
     else
         img->is_pipe = 1;
 
+    str = strrchr(img->path, '.');
+    img->is_y = str && !strcasecmp(str + 1, "y");
     return 0;
 }
 
@@ -358,7 +364,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
                 return AVERROR(EIO);
             }
 
-            if(codec->codec_id != CODEC_ID_RAWVIDEO)
+            if(!img->is_y)
                 break;
             filename[ strlen(filename) - 1 ]= 'U' + i;
         }
@@ -366,7 +372,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         pb[0] = s->pb;
     }
 
-    if(codec->codec_id == CODEC_ID_RAWVIDEO){
+    if(img->is_y){
         int ysize = codec->width * codec->height;
         put_buffer(pb[0], pkt->data        , ysize);
         put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
-- 
1.7.1


-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20110212/4e9ff63e/attachment.pgp>



More information about the ffmpeg-devel mailing list