[FFmpeg-devel] ByteIOContext probe + img2 patch

Justin Foutts jmfoutts at yahoo.com
Sun Sep 4 06:52:48 CEST 2011


All of these changes were necessary for me to avformat_open_input() .png's with custom ByteIOContext.  WARNING: I have swapped the img2 is_pipe logic but only verified the is_pipe case!
diff --git a/libavformat/img2.c b/libavformat/img2.cindex 77145cb..f3fea4a 100644--- a/libavformat/img2.c+++ b/libavformat/img2.c@@ -248,7 +248,7 @@ static int read_header(AVFormatContext *s1, AVFormatParameters *ap)     s->img_count = 0;      /* find format */-    if (s1->iformat->flags & AVFMT_NOFILE)+    if (s1->iformat->flags & AVFMT_NOFILE == 0)         s->is_pipe = 0;     else{         s->is_pipe = 1;@@ -330,7 +330,7 @@ static int read_packet(AVFormatContext *s1, AVPacket *pkt)         f[0] = s1->pb;         if (url_feof(f[0]))             return AVERROR(EIO);-        size[0]= 4096;+        size[0]= avio_size(f[0]);     }      av_new_packet(pkt, size[0] + size[1] + size[2]);@@ -371,7 +371,7 @@ static int write_header(AVFormatContext *s)     av_strlcpy(img->path, s->filename, sizeof(img->path));      /* find format */-    if (s->oformat->flags & AVFMT_NOFILE)+    if
 (s->oformat->flags & AVFMT_NOFILE == 0)         img->is_pipe = 0;     else         img->is_pipe = 1;diff --git a/libavformat/utils.c b/libavformat/utils.cindex 1017d52..a035a7e 100644--- a/libavformat/utils.c+++ b/libavformat/utils.c@@ -601,8 +601,14 @@ static int init_input(AVFormatContext *s, const char *filename)     int ret;     AVProbeData pd = {filename, NULL, 0}; -    if (s->pb) {+    if (s->pb)         s->flags |= AVFMT_FLAG_CUSTOM_IO;++    if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) ||+        (!s->iformat && (s->iformat = av_probe_input_format(&pd, 0))))+        return 0;++    if (s->pb) {         if (!s->iformat)             return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0);         else if (s->iformat->flags & AVFMT_NOFILE)@@ -611,10 +617,6 @@ static int init_input(AVFormatContext *s, const char *filename)         return 0;     } -    if (
 (s->iformat && s->iformat->flags & AVFMT_NOFILE) ||-        (!s->iformat && (s->iformat = av_probe_input_format(&pd, 0))))-        return 0;-     if ((ret = avio_open(&s->pb, filename, AVIO_FLAG_READ)) < 0)         return ret;     if (s->iformat) 


More information about the ffmpeg-devel mailing list