]> git.sesse.net Git - ffmpeg/commitdiff
srtenc: Add timing-less "subrip" encoder.
authorPhilip Langdale <philipl@overt.org>
Sun, 12 Aug 2012 21:18:35 +0000 (14:18 -0700)
committerPhilip Langdale <philipl@overt.org>
Thu, 16 Aug 2012 03:46:54 +0000 (20:46 -0700)
Unsurprisingly, if a timing-less subrip decoder is desireable, an
encoder is as well. With this in place, we can move on to remove
the use of the old encoder/decoder with embedded timing and move
all timing handling the (de)muxer where they belong.

Signed-off-by: Philip Langdale <philipl@overt.org>
Changelog
libavcodec/Makefile
libavcodec/allcodecs.c
libavcodec/srtenc.c
libavcodec/version.h
libavformat/srtenc.c
tests/fate/subtitles.mak
tests/ref/fate/sub-subripenc [new file with mode: 0644]

index 1bbe690cc931c7e023a418c89f841f0c2468f693..5a08d8f2aa717ac1666bc771cb6dc172e13407e2 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -46,6 +46,7 @@ version next:
 - asetpts filter
 - hue filter
 - ICO muxer
+- SubRip encoder and decoder without embedded timing
 
 
 version 0.11:
index bab97e4767a3ff1cf14c73386389ab3d456277c0..ed861aeaa6c80dc0343ee1ce3d6a504695450889 100644 (file)
@@ -409,6 +409,7 @@ 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_SUBRIP_ENCODER)          += srtenc.o ass_split.o
 OBJS-$(CONFIG_SUBVIEWER_DECODER)       += subviewerdec.o ass.o
 OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER)         += sunrastenc.o
index f7ae4498b37d9fce826ba979efa8c6c9f93fe53e..98147732ed4eba794734402811d2178ba1bbec82 100644 (file)
@@ -415,7 +415,7 @@ void avcodec_register_all(void)
     REGISTER_DECODER (REALTEXT, realtext);
     REGISTER_DECODER (SAMI, sami);
     REGISTER_ENCDEC  (SRT, srt);
-    REGISTER_DECODER (SUBRIP, subrip);
+    REGISTER_ENCDEC  (SUBRIP, subrip);
     REGISTER_DECODER (SUBVIEWER, subviewer);
     REGISTER_ENCDEC  (XSUB, xsub);
 
index 9e152c70c7ecb77063a9e550adea8efac40fd262..dfc4e6c47cfcba9cba07dfea4e6396e867ac566e 100644 (file)
@@ -252,16 +252,18 @@ static int srt_encode_frame(AVCodecContext *avctx,
 
         dialog = ff_ass_split_dialog(s->ass_ctx, sub->rects[i]->ass, 0, &num);
         for (; dialog && num--; dialog++) {
-            int sh, sm, ss, sc = 10 * dialog->start;
-            int eh, em, es, ec = 10 * dialog->end;
-            sh = sc/3600000;  sc -= 3600000*sh;
-            sm = sc/  60000;  sc -=   60000*sm;
-            ss = sc/   1000;  sc -=    1000*ss;
-            eh = ec/3600000;  ec -= 3600000*eh;
-            em = ec/  60000;  ec -=   60000*em;
-            es = ec/   1000;  ec -=    1000*es;
-            srt_print(s,"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n",
-                      ++s->count, sh, sm, ss, sc, eh, em, es, ec);
+            if (avctx->codec->id == CODEC_ID_SRT) {
+                int sh, sm, ss, sc = 10 * dialog->start;
+                int eh, em, es, ec = 10 * dialog->end;
+                sh = sc/3600000;  sc -= 3600000*sh;
+                sm = sc/  60000;  sc -=   60000*sm;
+                ss = sc/   1000;  sc -=    1000*ss;
+                eh = ec/3600000;  ec -= 3600000*eh;
+                em = ec/  60000;  ec -=   60000*em;
+                es = ec/   1000;  ec -=    1000*es;
+                srt_print(s,"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n",
+                          ++s->count, sh, sm, ss, sc, eh, em, es, ec);
+            }
             s->alignment_applied = 0;
             s->dialog_start = s->ptr - 2;
             srt_style_apply(s, dialog->style);
@@ -289,9 +291,10 @@ static int srt_encode_close(AVCodecContext *avctx)
     return 0;
 }
 
+#if CONFIG_SRT_ENCODER
 AVCodec ff_srt_encoder = {
     .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,
     .priv_data_size = sizeof(SRTContext),
@@ -299,3 +302,17 @@ AVCodec ff_srt_encoder = {
     .encode         = srt_encode_frame,
     .close          = srt_encode_close,
 };
+#endif
+
+#if CONFIG_SUBRIP_ENCODER
+AVCodec ff_subrip_encoder = {
+    .name           = "subrip",
+    .long_name      = NULL_IF_CONFIG_SMALL("SubRip subtitle"),
+    .type           = AVMEDIA_TYPE_SUBTITLE,
+    .id             = AV_CODEC_ID_SUBRIP,
+    .priv_data_size = sizeof(SRTContext),
+    .init           = srt_encode_init,
+    .encode         = srt_encode_frame,
+    .close          = srt_encode_close,
+};
+#endif
index f2c5151a3e30e229e64c85ce62b7eafcb2ccacf8..7f4db0b56685ab860b9ba1d556e1af01ea1307c4 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 52
+#define LIBAVCODEC_VERSION_MINOR 53
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
index 7fe559f487a4eb4f4710421c57dd3c78fc940afb..6b8278fa80e59d18a296a7d9e5d806c9e9d25667 100644 (file)
@@ -42,6 +42,7 @@ static int srt_write_header(AVFormatContext *avf)
         return AVERROR(EINVAL);
     }
     if (avf->streams[0]->codec->codec_id != AV_CODEC_ID_TEXT &&
+        avf->streams[0]->codec->codec_id != AV_CODEC_ID_SUBRIP &&
         avf->streams[0]->codec->codec_id != AV_CODEC_ID_SRT) {
         av_log(avf, AV_LOG_ERROR,
                "Unsupported subtitles codec: %s\n",
index 59c55a56a5e87060cea82d1fdc17bedb2ce8e6be..aa0b50ddddc947fe5e13534dd8b60169771798b0 100644 (file)
@@ -19,6 +19,9 @@ fate-sub-sami: CMD = md5 -i $(SAMPLES)/sub/SAMI_capability_tester.smi -f ass
 FATE_SUBTITLES += fate-sub-srt
 fate-sub-srt: CMD = md5 -i $(SAMPLES)/sub/SubRip_capability_tester.srt -f ass
 
+FATE_SUBTITLES += fate-sub-subripenc
+fate-sub-subripenc: CMD = md5 -i $(SAMPLES)/sub/MovText_capability_tester.mp4 -scodec subrip -f srt
+
 FATE_SUBTITLES += fate-sub-subviewer
 fate-sub-subviewer: CMD = md5 -i $(SAMPLES)/sub/SubViewer_capability_tester.sub -f ass
 
diff --git a/tests/ref/fate/sub-subripenc b/tests/ref/fate/sub-subripenc
new file mode 100644 (file)
index 0000000..7daa4f5
--- /dev/null
@@ -0,0 +1 @@
+bd520f85238abf9df292374aed54681a