[FFmpeg-devel] [PATCH 3/4] ffmpeg: add get_best_input_stream_index function

Stefano Sabatini stefasab at gmail.com
Sat Mar 24 12:49:49 CET 2012


On date Thursday 2012-03-22 16:50:40 +0100, Clément Bœsch encoded:
> From: Matthieu Bouron <matthieu.bouron at smartjog.com>
> 
> ---
>  ffmpeg.c |   76 +++++++++++++++++++++++++++++++++++++++----------------------
>  1 files changed, 48 insertions(+), 28 deletions(-)
> 
> diff --git a/ffmpeg.c b/ffmpeg.c
> index 32286e2..305fdfa 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -3185,6 +3185,47 @@ static int transcode(OutputFile *output_files, int nb_output_files,
>      return ret;
>  }
>  
> +static int get_best_input_stream_index(enum AVMediaType type)
> +{
> +    int i, idx = -1, area = 0, channels = 0;
> +
> +    switch (type) {
> +    case AVMEDIA_TYPE_VIDEO:
> +        /* video: highest resolution */
> +        for (i = 0; i < nb_input_streams; i++) {
> +            InputStream *ist = &input_streams[i];
> +            if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
> +                ist->st->codec->width * ist->st->codec->height > area) {
> +                area = ist->st->codec->width * ist->st->codec->height;
> +                idx = i;
> +            }
> +        }
> +        break;
> +    case AVMEDIA_TYPE_AUDIO:
> +        /* audio: most channels */

While at it also please use more idiot-proof comments, for example
this could be: "select the audio stream with most channels"

[...]

Looks nice otherwise.
-- 
FFmpeg = Fancy and Fast Magical Plastic Elastic Governor


More information about the ffmpeg-devel mailing list