[FFmpeg-cvslog] srtdec: Add timing-less "subrip" decoder.

Philip Langdale git at videolan.org
Thu Aug 16 07:03:30 CEST 2012


ffmpeg | branch: master | Philip Langdale <philipl at overt.org> | Sat Aug 11 20:27:51 2012 -0700| [6af680fa070ebc5081045e4b24ceaa4fccfa89b4] | committer: Philip Langdale

srtdec: Add timing-less "subrip" decoder.

After various discussions, we concluded that, amongst other things,
it made sense to have a separate subrip decoder that did not use
in-band timing information, and rather relied on the ffmpeg level
timing.

As this is 90% the same as the existing srt decoder, it's implemented
in the same file.

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

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

 libavcodec/Makefile    |    1 +
 libavcodec/allcodecs.c |    1 +
 libavcodec/avcodec.h   |    1 +
 libavcodec/srtdec.c    |   31 +++++++++++++++++++++++++++----
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index a8e4e88..bab97e4 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -408,6 +408,7 @@ OBJS-$(CONFIG_SONIC_LS_ENCODER)        += sonic.o
 OBJS-$(CONFIG_SP5X_DECODER)            += sp5xdec.o mjpegdec.o mjpeg.o
 OBJS-$(CONFIG_SRT_DECODER)             += srtdec.o ass.o
 OBJS-$(CONFIG_SRT_ENCODER)             += srtenc.o ass_split.o
+OBJS-$(CONFIG_SUBRIP_DECODER)          += srtdec.o ass.o
 OBJS-$(CONFIG_SUBVIEWER_DECODER)       += subviewerdec.o ass.o
 OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER)         += sunrastenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 6b42c30..f7ae449 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -415,6 +415,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER (REALTEXT, realtext);
     REGISTER_DECODER (SAMI, sami);
     REGISTER_ENCDEC  (SRT, srt);
+    REGISTER_DECODER (SUBRIP, subrip);
     REGISTER_DECODER (SUBVIEWER, subviewer);
     REGISTER_ENCDEC  (XSUB, xsub);
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 07a9e10..372d0cf 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -441,6 +441,7 @@ enum AVCodecID {
     AV_CODEC_ID_SAMI       = MKBETAG('S','A','M','I'),
     AV_CODEC_ID_REALTEXT   = MKBETAG('R','T','X','T'),
     AV_CODEC_ID_SUBVIEWER  = MKBETAG('S','u','b','V'),
+    AV_CODEC_ID_SUBRIP     = MKBETAG('S','R','i','p'),
 
     /* other specific kind of codecs (generally used for attachments) */
     AV_CODEC_ID_FIRST_UNKNOWN = 0x18000,           ///< A dummy ID pointing at the start of various fake codecs.
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 13e4f9c..3d3ace0 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -217,9 +217,19 @@ static int srt_decode_frame(AVCodecContext *avctx,
         return avpkt->size;
 
     while (ptr < end && *ptr) {
-        ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2);
-        if (!ptr)
-            break;
+        if (avctx->codec->id == CODEC_ID_SRT) {
+            ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2);
+            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});
+            ts_end   = av_rescale_q(avpkt->pts + avpkt->duration,
+                                    avctx->time_base,
+                                    (AVRational){1,100});
+        }
         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);
@@ -229,11 +239,24 @@ static int srt_decode_frame(AVCodecContext *avctx,
     return avpkt->size;
 }
 
+#if CONFIG_SRT_DECODER
 AVCodec ff_srt_decoder = {
     .name         = "srt",
-    .long_name    = NULL_IF_CONFIG_SMALL("SubRip subtitle"),
+    .long_name    = NULL_IF_CONFIG_SMALL("SubRip subtitle with embedded timing"),
     .type         = AVMEDIA_TYPE_SUBTITLE,
     .id           = AV_CODEC_ID_SRT,
     .init         = ff_ass_subtitle_header_default,
     .decode       = srt_decode_frame,
 };
+#endif
+
+#if CONFIG_SUBRIP_DECODER
+AVCodec ff_subrip_decoder = {
+    .name         = "subrip",
+    .long_name    = NULL_IF_CONFIG_SMALL("SubRip subtitle"),
+    .type         = AVMEDIA_TYPE_SUBTITLE,
+    .id           = AV_CODEC_ID_SUBRIP,
+    .init         = ff_ass_subtitle_header_default,
+    .decode       = srt_decode_frame,
+};
+#endif



More information about the ffmpeg-cvslog mailing list