[FFmpeg-devel] [PATCH 1/2] lavc/srtdec: make read_ts preserve the millisecond.

Nicolas George nicolas.george at normalesup.org
Sun Sep 2 10:03:17 CEST 2012


The times are also changed to int64_t.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavcodec/srtdec.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index f32521f..12b7e0c 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -184,21 +184,21 @@ static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end,
     return in;
 }
 
-static const char *read_ts(const char *buf, int *ts_start, int *ts_end,
+static const char *read_ts(const char *buf, int64_t *ts_start, int64_t *ts_end,
                            int *x1, int *y1, int *x2, int *y2)
 {
-    int i, hs, ms, ss, he, me, se;
+    int i, hs, ms, ss, mss, he, me, se, mse;
 
     for (i=0; i<2; i++) {
         /* try to read timestamps in either the first or second line */
         int c = sscanf(buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d"
                        "%*[ ]X1:%u X2:%u Y1:%u Y2:%u",
-                       &hs, &ms, &ss, ts_start, &he, &me, &se, ts_end,
+                       &hs, &ms, &ss, &mss, &he, &me, &se, &mse,
                        x1, x2, y1, y2);
         buf += strcspn(buf, "\n") + 1;
         if (c >= 8) {
-            *ts_start = 100*(ss + 60*(ms + 60*hs)) + *ts_start/10;
-            *ts_end   = 100*(se + 60*(me + 60*he)) + *ts_end  /10;
+            *ts_start = (int64_t)1000*(ss + 60*(ms + 60*hs)) + mss;
+            *ts_end   = (int64_t)1000*(se + 60*(me + 60*he)) + mse;
             return buf;
         }
     }
@@ -209,7 +209,8 @@ static int srt_decode_frame(AVCodecContext *avctx,
                             void *data, int *got_sub_ptr, AVPacket *avpkt)
 {
     AVSubtitle *sub = data;
-    int ts_start, ts_end, x1 = -1, y1 = -1, x2 = -1, y2 = -1;
+    int64_t ts_start, ts_end;
+    int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
     char buffer[2048];
     const char *ptr = avpkt->data;
     const char *end = avpkt->data + avpkt->size;
@@ -223,17 +224,16 @@ static int srt_decode_frame(AVCodecContext *avctx,
             if (!ptr)
                 break;
         } else {
-            // Do final divide-by-10 outside rescale to force rounding down.
             ts_start = av_rescale_q(avpkt->pts,
                                     avctx->time_base,
-                                    (AVRational){1,100});
+                                    (AVRational){1,1000});
             ts_end   = av_rescale_q(avpkt->pts + avpkt->duration,
                                     avctx->time_base,
-                                    (AVRational){1,100});
+                                    (AVRational){1,1000});
         }
         ptr = srt_to_ass(avctx, buffer, buffer+sizeof(buffer), ptr,
                          x1, y1, x2, y2);
-        ff_ass_add_rect(sub, buffer, ts_start, ts_end-ts_start, 0);
+        ff_ass_add_rect(sub, buffer, ts_start / 10, ts_end / 10 - ts_start / 10, 0);
     }
 
     *got_sub_ptr = sub->num_rects > 0;
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list