[PATCH] avformat: add support for codecs to set probe fallbacks

Anssi Hannula anssi.hannula
Tue Jul 20 19:44:22 CEST 2010


---
 libavformat/avformat.h |   14 +++++++++++++-
 libavformat/utils.c    |    8 ++++++++
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 076b8c8..19d711b 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -22,7 +22,7 @@
 #define AVFORMAT_AVFORMAT_H
 
 #define LIBAVFORMAT_VERSION_MAJOR 52
-#define LIBAVFORMAT_VERSION_MINOR 76
+#define LIBAVFORMAT_VERSION_MINOR 77
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -536,6 +536,18 @@ typedef struct AVStream {
      * Number of frames that have been demuxed during av_find_stream_info()
      */
     int codec_info_nb_frames;
+
+    /**
+     * Number of bytes to probe until probe_fallback_codec_id is selected.
+     * Not part of public API.
+     */
+    int probe_fallback_bytes;
+
+    /**
+     * Codec id to select if no codec probed in probe_fallback_bytes bytes.
+     * Not part of public API.
+     */
+    enum CodecID probe_fallback_codec_id;
 } AVStream;
 
 #define AV_PROGRAM_RUNNING 1
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 6fa4dff..4f38002 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -707,6 +707,9 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt)
                     pd->buf_size=0;
                     av_freep(&pd->buf);
                     av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
+                } else if(st->probe_fallback_bytes && pd->buf_size >= st->probe_fallback_bytes) {
+                    st->codec->codec_id = st->probe_fallback_codec_id;
+                    av_log(s, AV_LOG_DEBUG, "selected fallback codec id for stream %d\n", st->index);
                 }
             }
         }
@@ -2256,6 +2259,11 @@ int av_find_stream_info(AVFormatContext *ic)
                 st = ic->streams[i];
                 if (!has_codec_parameters(st->codec)){
                     char buf[256];
+                    if (st->probe_fallback_bytes) {
+                        st->codec->codec_id = st->probe_fallback_codec_id;
+                        ret = 0;
+                        continue;
+                    }
                     avcodec_string(buf, sizeof(buf), st->codec, 0);
                     av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf);
                 } else {
-- 
1.7.1


--Boundary-00=_u8QSMQD2zqD3MrD--



More information about the ffmpeg-devel mailing list