It supports passing options to codecs.
---
libavformat/avformat.h | 19 +++++++++++++++++++
libavformat/utils.c | 16 +++++++++++-----
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index b09a321..f224b4d 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1067,6 +1067,25 @@ AVFormatContext *avformat_alloc_context(void);
int av_find_stream_info(AVFormatContext *ic);
/**
+ * Read packets of a media file to get stream information. This
+ * is useful for file formats with no headers such as MPEG. This
+ * function also computes the real framerate in case of MPEG-2 repeat
+ * frame mode.
+ * The logical file position is not changed by this function;
+ * examined packets may be buffered for later processing.
+ *
+ * @param s media file handle
+ * @param options If non-NULL, an s.nb_streams long array of pointers
+ * metadata, where i-th member contains options for
+ * codec corresponding to i-th stream.
+ * On return each metadata will be filled with options that
were not found.
+ * @return >=0 if OK, AVERROR_xxx on error
+ * @todo Let the user decide somehow what information is needed so that
+ * we do not waste time getting stuff the user does not need.
+ */
+int avformat_find_stream_info(AVFormatContext *ic, AVMetadata **options);
+
+/**
* Find the "best" stream in the file.
* The best stream is determined according to various heuristics as the most
* likely to be what the user expects.
diff --git a/libavformat/utils.c b/libavformat/utils.c
index ab3d0c8..499696b 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2122,7 +2122,7 @@ static int has_decode_delay_been_guessed(AVStream *st)
st->codec_info_nb_frames >= 6 + st->codec->has_b_frames;
}
-static int try_decode_frame(AVStream *st, AVPacket *avpkt)
+static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVMetadata
**options)
{
int16_t *samples;
AVCodec *codec;
@@ -2133,7 +2133,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt)
codec = avcodec_find_decoder(st->codec->codec_id);
if (!codec)
return -1;
- ret = avcodec_open(st->codec, codec);
+ ret = avcodec_open2(st->codec, codec, options);
if (ret < 0)
return ret;
}
@@ -2254,10 +2254,16 @@ static int tb_unreliable(AVCodecContext *c){
int av_find_stream_info(AVFormatContext *ic)
{
+ return avformat_find_stream_info(ic, NULL);
+}
+
+int avformat_find_stream_info(AVFormatContext *ic, AVMetadata **options)
+{
int i, count, ret, read_size, j;
AVStream *st;
AVPacket pkt1, *pkt;
int64_t old_offset = avio_tell(ic->pb);
+ int orig_nb_streams = ic->nb_streams; // new streams might appear,
no options for those
for(i=0;i<ic->nb_streams;i++) {
AVCodec *codec;
@@ -2294,12 +2300,12 @@ int av_find_stream_info(AVFormatContext *ic)
/* Ensure that subtitle_header is properly set. */
if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
&& codec && !st->codec->codec)
- avcodec_open(st->codec, codec);
+ avcodec_open2(st->codec, codec, options ? &options[i] : NULL);
//try to just open decoders, in case this is enough to get parameters
if(!has_codec_parameters(st->codec)){
if (codec && !st->codec->codec)
- avcodec_open(st->codec, codec);
+ avcodec_open2(st->codec, codec, options ? &options[i] : NULL);
}
}
@@ -2432,7 +2438,7 @@ int av_find_stream_info(AVFormatContext *ic)
it takes longer and uses more memory. For MPEG-4, we need to
decompress for QuickTime. */
if (!has_codec_parameters(st->codec) ||
!has_decode_delay_been_guessed(st))
- try_decode_frame(st, pkt);
+ try_decode_frame(st, pkt, (options && i <= orig_nb_streams )?
&options[i] : NULL);
st->codec_info_nb_frames++;
count++;
--
1.7.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel