[FFmpeg-devel] [RFC] lavf/tee per-output stream selection
Stefano Sabatini
stefasab at gmail.com
Sun Aug 4 13:55:47 CEST 2013
On date Sunday 2013-08-04 12:07:14 +0200, Nicolas George encoded:
> Le sextidi 16 thermidor, an CCXXI, Stefano Sabatini a écrit :
> > >From 7b08890d825abc7df66bd49e8cbb1f4ae5c888b1 Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefasab at gmail.com>
> > Date: Sat, 3 Aug 2013 11:23:59 +0200
> > Subject: [PATCH] lavf/tee: add special select option
> >
> > TODO: bump micro
> > ---
> > doc/muxers.texi | 5 +++++
> > libavformat/tee.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
> > 2 files changed, 45 insertions(+), 8 deletions(-)
> >
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index 7c5a1c8..37a1734 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -844,6 +844,11 @@ The BNF description of the bitstream filters specification is given by:
> > @var{BSF} ::= @var{BSF_NAME}[+ at var{STREAM_SPECIFIER}]
> > @var{BSFS} ::= @var{BSF}[, at var{BSFS}]
> > @end example
> > +
> > + at item select
> > +Select the streams that should be mapped to the slave output,
> > +specified by a stream specifier. If not specified, this defaults to
> > +all the input streams.
>
> Examples may be welcome. Is it possible to have several stream specifiers,
> i.e. map "video + English audio + French audio" to "video + English audio"
> and "video + French audio"?
This is something I considered, but requires either an extension of
the specifier syntax or a local hack.
For example we may extend the specifier to take into account
compositions like a+v, and consider the language like in a[lang=en]+v.
Composition is probably a good idea since it would extend other parts
of the codebase for free (e.g. ffprobe -select_streams a0+v1). As for
the language thing I'm open to suggestions.
>
> > @end table
> >
> > Example: encode something and both archive it in a WebM file and stream it
> > diff --git a/libavformat/tee.c b/libavformat/tee.c
> > index 90947c7..4604ab4 100644
> > --- a/libavformat/tee.c
> > +++ b/libavformat/tee.c
> > @@ -30,6 +30,7 @@
> > typedef struct {
> > AVFormatContext *fmt_ctx;
> > AVBitStreamFilterContext **bsf_ctxs; ///< bitstream filters per stream
>
> > + int *stream_map; ///< map between input and output streams, disabled streams are set to -1
>
> Nit: please try to keep lines below 80 chars.
>
> Also, the comment is unclear about the direction of the map, it could be
> either:
>
> stream_num_in_slave = stream_map[stream_num_in_global]
> stream_num_in_global = stream_map[stream_num_in_slave]
>
> > } TeeSlave;
> >
> > typedef struct TeeContext {
> > @@ -179,9 +180,10 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
> > AVDictionary *options = NULL;
> > AVDictionaryEntry *entry;
> > char *filename;
> > - char *format = NULL, *bsfs = NULL;
> > + char *format = NULL, *bsfs = NULL, *select = NULL;
> > AVFormatContext *avf2 = NULL;
> > AVStream *st, *st2;
> > + int stream_count;
> >
> > if ((ret = parse_slave_options(avf, slave, &options, &filename)) < 0)
> > return ret;
> > @@ -195,14 +197,42 @@ static int open_slave(AVFormatContext *avf, char *slave, TeeSlave *tee_slave)
> > entry->value = NULL; /* prevent it from being freed */
> > av_dict_set(&options, "bsfs", NULL, 0);
> > }
> > + if ((entry = av_dict_get(options, "select", NULL, 0))) {
> > + select = entry->value;
> > + entry->value = NULL; /* prevent it from being freed */
> > + av_dict_set(&options, "select", NULL, 0);
> > + }
>
> This hunk really needs factoring.
>
> >
> > ret = avformat_alloc_output_context2(&avf2, NULL, format, filename);
> > if (ret < 0)
> > goto fail;
> > av_free(format);
> >
> > + tee_slave->stream_map = av_calloc(avf->nb_streams, sizeof(int));
>
> sizeof(*tee_slave->stream_map)
>
> > + if (!tee_slave->stream_map) {
> > + ret = AVERROR(ENOMEM);
> > + goto fail;
> > + }
> > +
> > + stream_count = 0;
> > for (i = 0; i < avf->nb_streams; i++) {
> > st = avf->streams[i];
>
> > + if (select && select[0]) {
>
> Why select[0]?
The empty string is parsed as "all", I can drop the check though.
[...]
--
FFmpeg = Fundamental Fascinating Mastodontic Peaceless Evil Gadget
More information about the ffmpeg-devel
mailing list