[FFmpeg-devel] [PATCH] av_find_best_stream

Michael Niedermayer michaelni
Sat Dec 25 20:39:23 CET 2010


On Fri, Dec 24, 2010 at 06:59:08PM +0100, Nicolas George wrote:
[...]>
>  /**
> + * 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.
> + * If the decoder parameter is non-NULL, av_find_best_stream will find the
> + * default decoder for the stream's codec; streams for which no decoder can
> + * be found are ignored.
> + *
> + * @param ic                media file handle
> + * @param type              stream type: video, audio, subtitles, etc.
> + * @param wanted_stream_nb  user-requested stream number,
> + *                          or -1 for automatic selection
> + * @param related_stream    try to find a stream related (eg. in the same
> + *                          program) to this one, or -1 if none
> + * @param decoder_ret       if non-NULL, returns the decoder for the
> + *                          selected stream
> + * @param flags             flags; none are currently defined
> + * @return  the non-negative stream number in case of success,
> + *          AVERROR_STREAM_NOT_FOUND if no stream with the requested type
> + *          could be found,
> + *          AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
> + * @note  If av_find_best_stream returns successfully and decoder_ret is not
> + *        NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
> + */
> +int av_find_best_stream(AVFormatContext *ic,
> +                        enum AVMediaType type,
> +                        int wanted_stream_nb,
> +                        int related_stream,
> +                        AVCodec **decoder_ret,
> +                        int flags);
> +
> +/**
>   * Read a transport packet from a media file.
>   *
>   *
This function is obsolete and should never be used.
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 61aa7d4..ed24d31 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2458,6 +2458,69 @@ int av_find_stream_info(AVFormatContext *ic)
>      return ret;
>  }
>  
> +static AVProgram *find_program_from_stream(AVFormatContext *ic, int s)
> +{
> +    int i, j;
> +
> +    for (i = 0; i < ic->nb_programs; i++)
> +        for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
> +            if (ic->programs[i]->stream_index[j] == s)
> +                return ic->programs[i];
> +    return NULL;
> +}
> +
> +int av_find_best_stream(AVFormatContext *ic,
> +                        enum AVMediaType type,
> +                        int wanted_stream_nb,
> +                        int related_stream,
> +                        AVCodec **decoder_ret,
> +                        int flags)
> +{
> +    int i, nb_streams = ic->nb_streams, stream_number = 0;
> +    int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1;
> +    unsigned *program = NULL;
> +    AVCodec *decoder = NULL, *best_decoder = NULL;
> +
> +#undef printf
> +    if (related_stream >= 0 && wanted_stream_nb < 0) {
> +        AVProgram *p = find_program_from_stream(ic, related_stream);
> +        if (p) {
> +            program = p->stream_index;
> +            nb_streams = p->nb_stream_indexes;
> +        }
> +    }
> +    for (i = 0; i < nb_streams; i++) {
> +        AVStream *st = ic->streams[program ? program[i] : i];
> +        AVCodecContext *avctx = st->codec;

> +        ic->streams[i]->discard = AVDISCARD_ALL;

the dox seem not to mention this


[...]
--
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

DNS cache poisoning attacks, popular search engine, Google internet authority
dont be evil, please
-------------- 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/20101225/0af87ab1/attachment.pgp>



More information about the ffmpeg-devel mailing list