[FFmpeg-devel] Fwd: libavformat/segment : add option to increment timecode

Stefano Sabatini stefasab at gmail.com
Sat Jan 30 10:44:48 CET 2016


On date Friday 2016-01-29 17:38:13 +0100, Martin Vignali encoded:
> 2016-01-29 12:35 GMT+01:00 Stefano Sabatini <stefasab at gmail.com>:
[...]
> > +        AVDictionaryEntry * tcr = av_dict_get(s->metadata, "timecode",
> > NULL, 0);
> > > +        if (tcr){
> > > +            if (s->nb_streams > 0){
> >
> > > +                rate = s->streams[0]->avg_frame_rate;//Get fps from
> > first stream
> >
> > this looks a bit arbitrary, why the first stream?
> >
> > > +                err = av_timecode_init_from_string(&tc, rate,
> > tcr->value, s);
> > > +                if (err < 0)
> > > +                    return err;
> >
> > > +                tc.start += (int)(seg->time / 1000000.) *
> > av_q2d(rate);//second count * fps
> >
> > You're losing precision here. Consider using the rescaling utilities
> > in libavutil/mathematics.h or something like (seg->time * rate.num) /
> > (rate.den * 1000000).
[...]
> Thanks you for your comments, i will make the modifications.
> 
> For the fps issue, you're right, i use the first stream because in my tests
> it's always the video stream.
> Is there a better way, to get fps ? without choosing one of the stream ?

My guess is that timecode is always related to a video stream, right?

In this case you can loop through the streams and selects the first
video stream (check also the select_reference_stream() function in
segment.c).
-- 
FFmpeg = Fantastic and Free Martial Peaceless Ermetic Gadget


More information about the ffmpeg-devel mailing list