[FFmpeg-devel] [PATCH] MPEG-TS/-PS : better probing for duration and start-time for all streams in a container

Gaullier Nicolas nicolas.gaullier at arkena.com
Thu Jun 19 19:26:31 CEST 2014


>> Finally, I decided to split the patch to keep only the duration update.
>> For the record, it is to replace ff_read_packet that returns packet 
>> with "uncomputed" zero duration, and a reset for last_dts to disable a non relevant warning due to the retry process.
>> (FATE pass ok)
>
>ive the suspicion that replacing this call is not trivial
>
>either way, please test your code against a wider range of samples if you happen to have some random ones laying around that you can easily test or maybe download some from >http://samples.ffmpeg.org/
>
>for example
>https://trac.ffmpeg.org/raw-attachment/ticket/3658/tv.800000.100_cut.ts
>
>ffmpeg -i tv.800000.100_cut.ts -codec copy -f framecrc -
>
>will fail after the patch about 1/3 into the file

It seems it is more secure to simply duplicate the computing routine from compute_pkt_fields to estimate_timings_from_pts.
If you think it is worth creating a new function to avoid doubling source code, please restructure it as you want.

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 517d919..b25576e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2477,7 +2477,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
 {
     AVPacket pkt1, *pkt = &pkt1;
     AVStream *st;
-    int read_size, i, ret;
+    int num, den, read_size, i, ret;
     int found_duration = 0;
     int is_end;
     int64_t filesize, offset, duration;
@@ -2525,6 +2525,15 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
             if (pkt->pts != AV_NOPTS_VALUE &&
                 (st->start_time != AV_NOPTS_VALUE ||
                  st->first_dts  != AV_NOPTS_VALUE)) {
+                if (pkt->duration == 0) {
+                    ff_compute_frame_duration(&num, &den, st, st->parser, pkt);
+                    if (den && num) {
+                        pkt->duration = av_rescale_rnd(1,
+                                           num * (int64_t) st->time_base.den,
+                                           den * (int64_t) st->time_base.num,
+                                           AV_ROUND_DOWN);
+                    }
+                }
                 duration = pkt->pts + pkt->duration;
                 found_duration = 1;
                 if (st->start_time != AV_NOPTS_VALUE)



More information about the ffmpeg-devel mailing list