[FFmpeg-devel] [PATCH] libavformat/matroskadec.c: Parse stream durations set by mkvmerge and populate them in AVStream.

Sasi Inguva isasi at google.com
Sat Aug 1 00:56:06 CEST 2015


The syntax is the normal syntax HH:MM:SS used everywhere.
av_parse_time can parse both  [-]HH:MM:SS[.m...]]]  and  [-]S+[.m...]
syntax for duration. So if mkvmerge outputs 1200.00 secs in duration it
would be able to parse that also .

On Fri, Jul 31, 2015 at 3:31 PM, wm4 <nfxjfg at googlemail.com> wrote:

> On Fri, 31 Jul 2015 13:00:02 -0700
> Sasi Inguva <isasi at google.com> wrote:
>
> > Signed-off-by: Sasi Inguva <isasi at google.com>
> > ---
> >  libavformat/matroskadec.c | 20 ++++++++++++++++++--
> >  1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> > index 1807cae..03b564e 100644
> > --- a/libavformat/matroskadec.c
> > +++ b/libavformat/matroskadec.c
> > @@ -41,6 +41,7 @@
> >  #include "libavutil/lzo.h"
> >  #include "libavutil/mathematics.h"
> >  #include "libavutil/opt.h"
> > +#include "libavutil/parseutils.h"
> >  #include "libavutil/time_internal.h"
> >
> >  #include "libavcodec/bytestream.h"
> > @@ -1418,10 +1419,25 @@ static void
> matroska_convert_tags(AVFormatContext *s)
> >                                           &chapter[j].chapter->metadata,
> NULL);
> >          } else if (tags[i].target.trackuid) {
> >              MatroskaTrack *track = matroska->tracks.elem;
> > -            for (j = 0; j < matroska->tracks.nb_elem; j++)
> > -                if (track[j].uid == tags[i].target.trackuid &&
> track[j].stream)
> > +            for (j = 0; j < matroska->tracks.nb_elem; j++) {
> > +                if (track[j].uid == tags[i].target.trackuid &&
> track[j].stream) {
>
> Adding the { and } seems redundant, but personally I don't mind.
>
> > +                    MatroskaTag *track_tags = tags[i].tag.elem;
> > +                    int64_t track_duration_ms;
> > +                    for (int ind = 0; ind < tags[i].tag.nb_elem; ++ind)
> {
> > +                        if (track_tags[ind].name &&
> > +                            !av_strcasecmp(track_tags[ind].name,
> "duration") &&
> > +                            track_tags[ind].string &&
> > +                            (av_parse_time(&track_duration_ms,
> track_tags[ind].string, 1) == 0)) {
>
> Who says the syntax mkvmerge writes and the syntax av_parse_time() will
> always be the same? I'm not sure if we should rely on this.
>
> > +                            track[j].stream->duration =
> av_rescale_q(track_duration_ms,
> > +
> (AVRational){ 1, 1000000 },
> > +
> track[j].stream->time_base);
> > +                        }
> > +                    }
> > +
> >                      matroska_convert_tag(s, &tags[i].tag,
> >                                           &track[j].stream->metadata,
> NULL);
> > +                }
> > +            }
> >          } else {
> >              matroska_convert_tag(s, &tags[i].tag, &s->metadata,
> >                                   tags[i].target.type);
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list