[FFmpeg-devel] [PATCH] lavf/segment: add reference_stream option

Stefano Sabatini stefasab at gmail.com
Wed Dec 26 21:21:53 CET 2012


On date Wednesday 2012-12-26 19:39:50 +0000, Paul B Mahol encoded:
> On 12/22/12, Stefano Sabatini <stefasab at gmail.com> wrote:
> > ---
> >  doc/muxers.texi       |   11 ++++++++-
> >  libavformat/segment.c |   64
> > +++++++++++++++++++++++++++++++++++++++----------
> >  2 files changed, 61 insertions(+), 14 deletions(-)
> >
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index 25cf565..e8c4a52 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -493,7 +493,9 @@ streaming output formats, i.e. which do not require
> > global headers,
> >  and is recommended for outputting e.g. to MPEG transport stream segments.
> >  @code{ssegment} is a shorter alias for @code{stream_segment}.
> >
> > -Every segment starts with a video keyframe, if a video stream is present.
> > +Every segment starts with a keyframe of the selected reference stream,
> > +which is set through the @option{reference_stream} option.
> > +
> >  Note that if you want accurate splitting for a video file, you need to
> >  make the input key frames correspond to the exact splitting times
> >  expected by the segmenter, or the segment muxer will start the new
> > @@ -509,6 +511,13 @@ the option @var{segment_list}. The list type is
> > specified by the
> >  The segment muxer supports the following options:
> >
> >  @table @option
> > + at item reference_stream @var{specifier}
> > +Set the reference stream, as specified by the string @var{specifier}.
> > +If @var{specifier} is set to @code{auto}, the reference is choosen
> > +automatically. Otherwise it is a stream specifier (see the ``Stream
> > +specifiers'' chapter in the ffmpeg manual). The default value is
> > +``auto''.
> > +
> >  @item segment_format @var{format}
> >  Override the inner container format, by default it is guessed by the
> > filename
> >  extension.
> > diff --git a/libavformat/segment.c b/libavformat/segment.c
> > index dc9b9c8..b46de10 100644
> > --- a/libavformat/segment.c
> > +++ b/libavformat/segment.c
> > @@ -74,7 +74,9 @@ typedef struct {
> >      int  write_header_trailer; /**< Set by a private option. */
> >
> >      int reset_timestamps;  ///< reset timestamps at the begin of each
> > segment
> > -    int has_video;
> > +    char *reference_stream_specifier; ///< reference stream specifier
> > +    int   reference_stream_index;
> > +
> >      double start_time, end_time;
> >      int64_t start_pts, start_dts;
> >      int is_first_pkt;      ///< tells if it is the first packet in the
> > segment
> > @@ -398,14 +400,51 @@ static int seg_write_header(AVFormatContext *s)
> >      if (seg->list_type == LIST_TYPE_EXT)
> >          av_log(s, AV_LOG_WARNING, "'ext' list type option is deprecated in
> > favor of 'csv'\n");
> >
> > -    for (i = 0; i < s->nb_streams; i++)
> > -        seg->has_video +=
> > -            (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO);
> > +    seg->reference_stream_index = -1;
> > +    if (!strcmp(seg->reference_stream_specifier, "auto")) {
> > +        int first_id[AVMEDIA_TYPE_NB];
> > +
> > +        for (i = 0; i < AVMEDIA_TYPE_NB; i++)
> > +            first_id[i] = -1;
> > +
> > +        for (i = 0; i < s->nb_streams; i++) {
> > +            enum AVMediaType type_priority_list[] = {
> 

> static const?

Will fix it.

> Move somewhere else?

I'd prefer to keep it in context.

> Is this actually used?

See below.

> 
> > +                AVMEDIA_TYPE_VIDEO,
> > +                AVMEDIA_TYPE_AUDIO,
> > +                AVMEDIA_TYPE_SUBTITLE,
> > +                AVMEDIA_TYPE_DATA,
> > +                AVMEDIA_TYPE_ATTACHMENT
> > +            };
> > +            enum AVMediaType type = s->streams[i]->codec->codec_type;
> > +            first_id[type] = FFMAX(first_id[type], i);
> > +
> > +            for (i = 0; i < FF_ARRAY_ELEMS(type_priority_list); i++)
> > +                if ((seg->reference_stream_index = first_id[i]) >= 0)
> > +                    break;
> > +        }
[...]
-- 
FFmpeg = Fundamental Fanciful Mortal Patchable Elastic Goblin


More information about the ffmpeg-devel mailing list