Commit faa94061 authored by Clément Bœsch's avatar Clément Bœsch

Add SubViewer v1 subtitles demuxer and decoder.

parent 7b434027
......@@ -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:
......
......@@ -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
......
......@@ -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
......
......@@ -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);
......
......@@ -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'),
......
......@@ -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,
......
......@@ -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 */
......@@ -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, \
......
......@@ -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
......
......@@ -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);
......
/*
* 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",
};
......@@ -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, \
......
......@@ -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
......
0c2096fedf7c971742b2e879bb303ce9
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment