[FFmpeg-cvslog] avformat/srtdec: Write duration into packet from srt demuxer.

Philip Langdale git at videolan.org
Sat Aug 4 21:09:42 CEST 2012


ffmpeg | branch: master | Philip Langdale <philipl at overt.org> | Sat Jun  2 16:15:38 2012 -0700| [7b24be557fda34a1dc7e67d6c9f835cc4103e07e] | committer: Philip Langdale

avformat/srtdec: Write duration into packet from srt demuxer.

The current demuxer does not bother to write packet durations,
which makes it impossible to remux into a new format.

Signed-off-by: Philip Langdale <philipl at overt.org>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7b24be557fda34a1dc7e67d6c9f835cc4103e07e
---

 libavformat/srtdec.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/libavformat/srtdec.c b/libavformat/srtdec.c
index 8eba5ab..28b18b4 100644
--- a/libavformat/srtdec.c
+++ b/libavformat/srtdec.c
@@ -51,16 +51,23 @@ static int srt_read_header(AVFormatContext *s)
     return 0;
 }
 
-static int64_t get_pts(const char *buf)
+static int64_t get_pts(const char *buf, int *duration)
 {
-    int i, v, hour, min, sec, hsec;
+    int i, hour, min, sec, hsec;
+    int he, me, se, mse;
 
     for (i=0; i<2; i++) {
-        if (sscanf(buf, "%d:%2d:%2d%*1[,.]%3d --> %*d:%*2d:%*2d%*1[,.]%3d",
-                   &hour, &min, &sec, &hsec, &v) == 5) {
+        int64_t start, end;
+        if (sscanf(buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d",
+                   &hour, &min, &sec, &hsec, &he, &me, &se, &mse) == 8) {
             min += 60*hour;
             sec += 60*min;
-            return sec*1000+hsec;
+            start = sec*1000+hsec;
+            me += 60*he;
+            se += 60*me;
+            end = se*1000+mse;
+            *duration = end - start;
+            return start;
         }
         buf += strcspn(buf, "\n") + 1;
     }
@@ -87,7 +94,7 @@ static int srt_read_packet(AVFormatContext *s, AVPacket *pkt)
         memcpy(pkt->data, buffer, pkt->size);
         pkt->flags |= AV_PKT_FLAG_KEY;
         pkt->pos = pos;
-        pkt->pts = pkt->dts = get_pts(pkt->data);
+        pkt->pts = pkt->dts = get_pts(pkt->data, &(pkt->duration));
     }
     return res;
 }



More information about the ffmpeg-cvslog mailing list