[FFmpeg-devel] [PATCH 2/2] lavc/srtdec: set subtitle timing in the structure.

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


Also fix the time base used for the packet timestamps.

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

diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 12b7e0c..87ab6f4 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -209,7 +209,7 @@ static int srt_decode_frame(AVCodecContext *avctx,
                             void *data, int *got_sub_ptr, AVPacket *avpkt)
 {
     AVSubtitle *sub = data;
-    int64_t ts_start, ts_end;
+    int64_t ts_packet, ts_start, ts_end;
     int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
     char buffer[2048];
     const char *ptr = avpkt->data;
@@ -218,22 +218,25 @@ static int srt_decode_frame(AVCodecContext *avctx,
     if (avpkt->size <= 0)
         return avpkt->size;
 
+    ts_packet = av_rescale_q(avpkt->pts,
+                             avctx->pkt_timebase,
+                             (AVRational){1, 1000});
     while (ptr < end && *ptr) {
         if (avctx->codec->id == CODEC_ID_SRT) {
             ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2);
             if (!ptr)
                 break;
         } else {
-            ts_start = av_rescale_q(avpkt->pts,
-                                    avctx->time_base,
-                                    (AVRational){1,1000});
+            ts_start = ts_packet;
             ts_end   = av_rescale_q(avpkt->pts + avpkt->duration,
-                                    avctx->time_base,
+                                    avctx->pkt_timebase,
                                     (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 / 10, ts_end / 10 - ts_start / 10, 0);
+        sub->start_display_time = ts_start - ts_packet;
+        sub->end_display_time   = ts_end   - ts_packet;
     }
 
     *got_sub_ptr = sub->num_rects > 0;
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list