]> git.sesse.net Git - ffmpeg/commitdiff
Add SubViewer v1 subtitles demuxer and decoder.
authorClément Bœsch <ubitux@gmail.com>
Fri, 28 Dec 2012 23:04:44 +0000 (00:04 +0100)
committerClément Bœsch <ubitux@gmail.com>
Sun, 30 Dec 2012 23:01:58 +0000 (00:01 +0100)
14 files changed:
Changelog
doc/general.texi
libavcodec/Makefile
libavcodec/allcodecs.c
libavcodec/avcodec.h
libavcodec/codec_desc.c
libavcodec/textdec.c
libavcodec/version.h
libavformat/Makefile
libavformat/allformats.c
libavformat/subviewer1dec.c [new file with mode: 0644]
libavformat/version.h
tests/fate/subtitles.mak
tests/ref/fate/sub-subviewer1 [new file with mode: 0644]

index cc77eb248d3d8577b1684f70ead52d370b88fdb8..4ebeae36e428ea3c3fa3f0e470cb2ec7591eb919 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -51,7 +51,7 @@ version <next>:
 - pp (postproc) filter ported from MPlayer
 - NIST Sphere demuxer
 - av_basename and av_dirname
-- MPL2, VPlayer, MPlayer, AQTitle and PJS subtitles demuxers and decoders
+- MPL2, VPlayer, MPlayer, AQTitle, PJS and SubViewer v1 subtitles demuxers and decoders
 
 
 version 1.0:
index 24870b60f769cf4ac0980bc987012a13e80e0587..ea513ff13a231d0917d09ada109333de9071d5b2 100644 (file)
@@ -933,6 +933,7 @@ performance on systems without hardware floating point support).
 @item SAMI             @tab   @tab X @tab   @tab X
 @item SSA/ASS          @tab X @tab X @tab X @tab X
 @item SubRip (SRT)     @tab X @tab X @tab X @tab X
+@item SubViewer v1     @tab   @tab X @tab   @tab X
 @item SubViewer        @tab   @tab X @tab   @tab X
 @item TED Talks captions @tab @tab X @tab   @tab X
 @item VobSub (IDX+SUB) @tab   @tab X @tab   @tab X
index f8dd0810971e39991237318bffc7336cb75e8e78..27c9a1139b792b21f30a7e990ea828b72ef1529e 100644 (file)
@@ -402,6 +402,7 @@ 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_SUBVIEWER1_DECODER)      += textdec.o ass.o
 OBJS-$(CONFIG_SUBVIEWER_DECODER)       += subviewerdec.o ass.o
 OBJS-$(CONFIG_SUNRAST_DECODER)         += sunrast.o
 OBJS-$(CONFIG_SUNRAST_ENCODER)         += sunrastenc.o
index d519a3e97761d9c04d4f464f2fb3543facad168b..987b87723c49991a35dca52b50dc82a198423f84 100644 (file)
@@ -456,6 +456,7 @@ void avcodec_register_all(void)
     REGISTER_ENCDEC (SRT,               srt);
     REGISTER_ENCDEC (SUBRIP,            subrip);
     REGISTER_DECODER(SUBVIEWER,         subviewer);
+    REGISTER_DECODER(SUBVIEWER1,        subviewer1);
     REGISTER_DECODER(TEXT,              text);
     REGISTER_DECODER(VPLAYER,           vplayer);
     REGISTER_DECODER(WEBVTT,            webvtt);
index 782b46b6ce065bdbc44511d374c896b0ba328c69..012a31c7e7f88fc637cc0805a76cd9a8fcdf3322 100644 (file)
@@ -463,6 +463,7 @@ enum AVCodecID {
     AV_CODEC_ID_JACOSUB    = MKBETAG('J','S','U','B'),
     AV_CODEC_ID_SAMI       = MKBETAG('S','A','M','I'),
     AV_CODEC_ID_REALTEXT   = MKBETAG('R','T','X','T'),
+    AV_CODEC_ID_SUBVIEWER1 = MKBETAG('S','b','V','1'),
     AV_CODEC_ID_SUBVIEWER  = MKBETAG('S','u','b','V'),
     AV_CODEC_ID_SUBRIP     = MKBETAG('S','R','i','p'),
     AV_CODEC_ID_WEBVTT     = MKBETAG('W','V','T','T'),
index 13ebcecef67c691423996e3e6a0c30832c2ed763..d721780218bbf6c50611b8a793bc75bc7cf32c91 100644 (file)
@@ -2440,6 +2440,12 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .name      = "realtext",
         .long_name = NULL_IF_CONFIG_SMALL("RealText subtitle"),
     },
+    {
+        .id        = AV_CODEC_ID_SUBVIEWER1,
+        .type      = AVMEDIA_TYPE_SUBTITLE,
+        .name      = "subviewer1",
+        .long_name = NULL_IF_CONFIG_SMALL("SubViewer v1 subtitle"),
+    },
     {
         .id        = AV_CODEC_ID_SUBVIEWER,
         .type      = AVMEDIA_TYPE_SUBTITLE,
index 32af644150c1b4ecc30c4ae925e0f351422098d2..9b97bacabd31815574d1ecb763e86dead177a14f 100644 (file)
@@ -128,7 +128,7 @@ AVCodec ff_text_decoder = {
 };
 #endif
 
-#if CONFIG_VPLAYER_DECODER || CONFIG_PJS_DECODER
+#if CONFIG_VPLAYER_DECODER || CONFIG_PJS_DECODER || CONFIG_TEXT_DECODER
 
 static int linebreak_init(AVCodecContext *avctx)
 {
@@ -169,4 +169,20 @@ AVCodec ff_pjs_decoder = {
 };
 #endif
 
+#if CONFIG_SUBVIEWER1_DECODER
+#define subviewer1_options options
+DECLARE_CLASS(subviewer1);
+
+AVCodec ff_subviewer1_decoder = {
+    .name           = "subviewer1",
+    .priv_data_size = sizeof(TextContext),
+    .long_name      = NULL_IF_CONFIG_SMALL("SubViewer1 subtitle"),
+    .type           = AVMEDIA_TYPE_SUBTITLE,
+    .id             = AV_CODEC_ID_SUBVIEWER1,
+    .decode         = text_decode_frame,
+    .init           = linebreak_init,
+    .priv_class     = &subviewer1_decoder_class,
+};
+#endif
+
 #endif /* text subtitles with '|' line break */
index bdd94b4e56559a2e3759e9e775b19c13883b08b2..af58490975ee6f493aa88a0eefdb434cdab1b75d 100644 (file)
@@ -29,7 +29,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 83
+#define LIBAVCODEC_VERSION_MINOR 84
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
index ce1d8f43fb8a1729c07400ae69cc576a4d92fe4f..d77b3bd09e50f8b127f67a7b36af69bc04a25f2b 100644 (file)
@@ -348,6 +348,7 @@ OBJS-$(CONFIG_SPDIF_MUXER)               += spdif.o spdifenc.o
 OBJS-$(CONFIG_SRT_DEMUXER)               += srtdec.o
 OBJS-$(CONFIG_SRT_MUXER)                 += srtenc.o
 OBJS-$(CONFIG_STR_DEMUXER)               += psxstr.o
+OBJS-$(CONFIG_SUBVIEWER1_DEMUXER)        += subviewer1dec.o
 OBJS-$(CONFIG_SUBVIEWER_DEMUXER)         += subviewerdec.o
 OBJS-$(CONFIG_SWF_DEMUXER)               += swfdec.o swf.o
 OBJS-$(CONFIG_SWF_MUXER)                 += swfenc.o swf.o
index 42878ecab6c818239c2c74f103766878a521054c..b3455b53fe2f896b3f7277cb553673ed655cd665 100644 (file)
@@ -259,6 +259,7 @@ void av_register_all(void)
     REGISTER_MUXDEMUX(SPDIF,            spdif);
     REGISTER_MUXDEMUX(SRT,              srt);
     REGISTER_DEMUXER (STR,              str);
+    REGISTER_DEMUXER (SUBVIEWER1,       subviewer1);
     REGISTER_DEMUXER (SUBVIEWER,        subviewer);
     REGISTER_MUXDEMUX(SWF,              swf);
     REGISTER_DEMUXER (TAK,              tak);
diff --git a/libavformat/subviewer1dec.c b/libavformat/subviewer1dec.c
new file mode 100644 (file)
index 0000000..0dc1942
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2012 Clément Bœsch
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * SubViewer v1 subtitle demuxer
+ */
+
+#include "avformat.h"
+#include "internal.h"
+#include "subtitles.h"
+
+typedef struct {
+    FFDemuxSubtitlesQueue q;
+} SubViewer1Context;
+
+static int subviewer1_probe(AVProbeData *p)
+{
+    const unsigned char *ptr = p->buf;
+
+    if (strstr(ptr, "******** START SCRIPT ********"))
+        return AVPROBE_SCORE_MAX / 2;
+    return 0;
+}
+
+static int subviewer1_read_header(AVFormatContext *s)
+{
+    int delay = 0;
+    AVPacket *sub = NULL;
+    SubViewer1Context *subviewer1 = s->priv_data;
+    AVStream *st = avformat_new_stream(s, NULL);
+
+    if (!st)
+        return AVERROR(ENOMEM);
+    avpriv_set_pts_info(st, 64, 1, 1);
+    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+    st->codec->codec_id   = AV_CODEC_ID_SUBVIEWER1;
+
+    while (!url_feof(s->pb)) {
+        char line[4096];
+        int len = ff_get_line(s->pb, line, sizeof(line));
+        int hh, mm, ss;
+
+        if (!len)
+            break;
+
+        if (!strncmp(line, "[DELAY]", 7)) {
+            ff_get_line(s->pb, line, sizeof(line));
+            sscanf(line, "%d", &delay);
+        }
+
+        if (sscanf(line, "[%d:%d:%d]", &hh, &mm, &ss) == 3) {
+            const int64_t pos = avio_tell(s->pb);
+            int64_t pts_start = hh*3600LL + mm*60LL + ss + delay;
+
+            len = ff_get_line(s->pb, line, sizeof(line));
+            line[strcspn(line, "\r\n")] = 0;
+            if (!*line) {
+                if (sub)
+                    sub->duration = pts_start - sub->pts;
+            } else {
+                sub = ff_subtitles_queue_insert(&subviewer1->q, line, len, 0);
+                if (!sub)
+                    return AVERROR(ENOMEM);
+                sub->pos = pos;
+                sub->pts = pts_start;
+                sub->duration = -1;
+            }
+        }
+    }
+
+    ff_subtitles_queue_finalize(&subviewer1->q);
+    return 0;
+}
+
+static int subviewer1_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    SubViewer1Context *subviewer1 = s->priv_data;
+    return ff_subtitles_queue_read_packet(&subviewer1->q, pkt);
+}
+
+static int subviewer1_read_seek(AVFormatContext *s, int stream_index,
+                               int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
+{
+    SubViewer1Context *subviewer1 = s->priv_data;
+    return ff_subtitles_queue_seek(&subviewer1->q, s, stream_index,
+                                   min_ts, ts, max_ts, flags);
+}
+
+static int subviewer1_read_close(AVFormatContext *s)
+{
+    SubViewer1Context *subviewer1 = s->priv_data;
+    ff_subtitles_queue_clean(&subviewer1->q);
+    return 0;
+}
+
+AVInputFormat ff_subviewer1_demuxer = {
+    .name           = "subviewer1",
+    .long_name      = NULL_IF_CONFIG_SMALL("SubViewer v1 subtitle format"),
+    .priv_data_size = sizeof(SubViewer1Context),
+    .read_probe     = subviewer1_probe,
+    .read_header    = subviewer1_read_header,
+    .read_packet    = subviewer1_read_packet,
+    .read_seek2     = subviewer1_read_seek,
+    .read_close     = subviewer1_read_close,
+    .extensions     = "sub",
+};
index f3cc75a5517734e8ac9b0dfcb3c0b28bf9b60ea5..90d47d02d197cd31c5eb2e2ae088d3a0085edb50 100644 (file)
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 55
+#define LIBAVFORMAT_VERSION_MINOR 56
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
index 3562dffb11e009e985d921660f9d6e5d60d435b3..812873eeb4ebbd49ba677e137e7d7010db14c6f2 100644 (file)
@@ -37,6 +37,9 @@ fate-sub-srt: CMD = md5 -i $(SAMPLES)/sub/SubRip_capability_tester.srt -f ass
 FATE_SUBTITLES-$(call ALLYES, MOV_DEMUXER MOVTEXT_DECODER SUBRIP_ENCODER) += fate-sub-subripenc
 fate-sub-subripenc: CMD = md5 -i $(SAMPLES)/sub/MovText_capability_tester.mp4 -scodec subrip -f srt
 
+FATE_SUBTITLES_ASS-$(call DEMDEC, SUBVIEWER1, SUBVIEWER1) += fate-sub-subviewer1
+fate-sub-subviewer1: CMD = md5 -i $(SAMPLES)/sub/SubViewer1_capability_tester.sub -f ass
+
 FATE_SUBTITLES_ASS-$(call DEMDEC, SUBVIEWER, SUBVIEWER) += fate-sub-subviewer
 fate-sub-subviewer: CMD = md5 -i $(SAMPLES)/sub/SubViewer_capability_tester.sub -f ass
 
diff --git a/tests/ref/fate/sub-subviewer1 b/tests/ref/fate/sub-subviewer1
new file mode 100644 (file)
index 0000000..116fce7
--- /dev/null
@@ -0,0 +1 @@
+0c2096fedf7c971742b2e879bb303ce9