[FFmpeg-devel] [PATCH 4/4] ffmpeg: add -amerge option to merge audio streams.

Stefano Sabatini stefasab at gmail.com
Sat Mar 24 14:24:59 CET 2012


On date Thursday 2012-03-22 16:50:41 +0100, Clément Bœsch encoded:
> From: Clément Bœsch <clement.boesch at smartjog.com>
> 
> Work done in collaboration with Matthieu Bouron <matthieu.bouron at smartjog.com>.
> ---
>  Changelog       |    1 +
>  doc/ffmpeg.texi |   40 ++++++++++++++------
>  ffmpeg.c        |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 138 insertions(+), 14 deletions(-)
[...]  
> +static int opt_amerge(OptionsContext *o, const char *opt, const char *arg)
> +{
> +#if !CONFIG_LAVFI_INDEV
> +    av_log(NULL, AV_LOG_ERROR, "Audio merge is only supported with lavfi device enabled.\n");
> +#else
> +    int i, nb_astreams = 0;
> +    const int auto_ist_pick = !o->nb_stream_maps;

> +    char *afilter, lavfi_map_buf[32];
> +    AVBPrint lavfi;

nit++:
lavfi         -> lavfi_graph_buf
afilter       -> lavfi_graph_str

or similiar looks more intelligible to me

> +
> +#define DO_MAP(stream_idx) do {                                             \
> +    const int file_index = input_streams[stream_idx].file_index;            \
> +    snprintf(lavfi_map_buf, sizeof(lavfi_map_buf), "%d:%d",                 \
> +             file_index, stream_idx - input_files[file_index].ist_index);   \
> +    parse_option(o, "map", lavfi_map_buf, options);                         \
> +} while (0)
> +
> +    if (!nb_input_files) {
> +        av_log(NULL, AV_LOG_FATAL, "No input specified before calling -amerge\n");
> +        return AVERROR(EINVAL);
> +    }
> +
> +    /* auto input stream pick mode if user has not specified any -map. This
> +     * allows command line such as:
> +     *   ffmpeg -i merge-my-audio-streams.mpg -c:v copy -amerge out.mpg */
> +    if (auto_ist_pick) {
> +
> +        /* best video stream */
> +        i = get_best_input_stream_index(AVMEDIA_TYPE_VIDEO);
> +        if (i >= 0)
> +            DO_MAP(i);
> +
> +        /* all audio streams (so they are all merged) */
> +        for (i = 0; i < nb_input_streams; i++)
> +            if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
> +                DO_MAP(i);
> +    }
> +
> +    /* prepare the audio sources based on all the audio mapped streams and
> +     * disable the audio maps */
> +    av_bprint_init(&lavfi, 256, 1);
> +    for (i = 0; i < o->nb_stream_maps; i++) {
> +        const StreamMap *map = &o->stream_maps[i];
> +        const char *ifname = input_files[map->file_index].ctx->filename;
> +        const InputStream *ist;
> +
> +        ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
> +        if (map->disabled || map->protected || ist->st->codec->codec_type != AVMEDIA_TYPE_AUDIO)
> +            continue;
> +        av_bprintf(&lavfi, "\namovie=%s:si=%d [a%d];", ifname, map->stream_index, nb_astreams++);

I see this is quite limited. Suppose that the user wants to specify a
seek point or time, or in general codec/format options for the input
file, this won't be possible. We can surely add such options to movie,
but in general mapping ffmpeg options to *movie options will be a
problem, and very hard to maintain, since they use rather different
logics.

[...]
-- 
FFmpeg = Frenzy and Faithless Majestic Philosofic Eretic God


More information about the ffmpeg-devel mailing list