1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Added STL demuxer and decoder

Signed-off-by: Clément Bœsch <u@pkh.me>
This commit is contained in:
Eejya Singh 2014-10-21 01:55:39 +05:30 committed by Clément Bœsch
parent 27c61c32ce
commit 6dc99fdf0e
14 changed files with 208 additions and 5 deletions

View File

@ -6,6 +6,7 @@ version <next>:
- SUP/PGS subtitle demuxer
- ffprobe -show_pixel_formats option
- CAST128 symmetric block cipher, ECB mode
- STL subtitle demuxer and decoder
version 2.4:
- Icecast protocol

View File

@ -1031,6 +1031,7 @@ performance on systems without hardware floating point support).
@item PJS (Phoenix) @tab @tab X @tab @tab X
@item RealText @tab @tab X @tab @tab X
@item SAMI @tab @tab X @tab @tab X
@item Spruce format (STL) @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

View File

@ -429,6 +429,7 @@ OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o
OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o
OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o
OBJS-$(CONFIG_SRT_ENCODER) += srtenc.o ass_split.o
OBJS-$(CONFIG_STL_DECODER) += textdec.o ass.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

View File

@ -490,6 +490,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(REALTEXT, realtext);
REGISTER_DECODER(SAMI, sami);
REGISTER_ENCDEC (SRT, srt);
REGISTER_DECODER(STL, stl);
REGISTER_ENCDEC (SUBRIP, subrip);
REGISTER_DECODER(SUBVIEWER, subviewer);
REGISTER_DECODER(SUBVIEWER1, subviewer1);

View File

@ -509,6 +509,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_STL = MKBETAG('S','p','T','L'),
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'),

View File

@ -2634,6 +2634,13 @@ static const AVCodecDescriptor codec_descriptors[] = {
.long_name = NULL_IF_CONFIG_SMALL("RealText subtitle"),
.props = AV_CODEC_PROP_TEXT_SUB,
},
{
.id = AV_CODEC_ID_STL,
.type = AVMEDIA_TYPE_SUBTITLE,
.name = "stl",
.long_name = NULL_IF_CONFIG_SMALL("Spruce subtitle format"),
.props = AV_CODEC_PROP_TEXT_SUB,
},
{
.id = AV_CODEC_ID_SUBVIEWER1,
.type = AVMEDIA_TYPE_SUBTITLE,

View File

@ -88,7 +88,7 @@ AVCodec ff_text_decoder = {
};
#endif
#if CONFIG_VPLAYER_DECODER || CONFIG_PJS_DECODER || CONFIG_SUBVIEWER1_DECODER
#if CONFIG_VPLAYER_DECODER || CONFIG_PJS_DECODER || CONFIG_SUBVIEWER1_DECODER || CONFIG_STL_DECODER
static int linebreak_init(AVCodecContext *avctx)
{
@ -113,6 +113,22 @@ AVCodec ff_vplayer_decoder = {
};
#endif
#if CONFIG_STL_DECODER
#define stl_options options
DECLARE_CLASS(stl);
AVCodec ff_stl_decoder = {
.name = "stl",
.long_name = NULL_IF_CONFIG_SMALL("Spruce subtitle format"),
.priv_data_size = sizeof(TextContext),
.type = AVMEDIA_TYPE_SUBTITLE,
.id = AV_CODEC_ID_STL,
.decode = text_decode_frame,
.init = linebreak_init,
.priv_class = &stl_decoder_class,
};
#endif
#if CONFIG_PJS_DECODER
#define pjs_options options
DECLARE_CLASS(pjs);

View File

@ -29,8 +29,8 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 56
#define LIBAVCODEC_VERSION_MINOR 8
#define LIBAVCODEC_VERSION_MICRO 102
#define LIBAVCODEC_VERSION_MINOR 9
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \

View File

@ -404,6 +404,7 @@ OBJS-$(CONFIG_SPEEX_MUXER) += oggenc.o \
vorbiscomment.o
OBJS-$(CONFIG_SRT_DEMUXER) += srtdec.o subtitles.o
OBJS-$(CONFIG_SRT_MUXER) += srtenc.o
OBJS-$(CONFIG_STL_DEMUXER) += stldec.o subtitles.o
OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o
OBJS-$(CONFIG_SUBVIEWER1_DEMUXER) += subviewer1dec.o subtitles.o
OBJS-$(CONFIG_SUBVIEWER_DEMUXER) += subviewerdec.o subtitles.o

View File

@ -278,6 +278,7 @@ void av_register_all(void)
REGISTER_MUXDEMUX(SPDIF, spdif);
REGISTER_MUXDEMUX(SRT, srt);
REGISTER_DEMUXER (STR, str);
REGISTER_DEMUXER (STL, stl);
REGISTER_DEMUXER (SUBVIEWER1, subviewer1);
REGISTER_DEMUXER (SUBVIEWER, subviewer);
REGISTER_DEMUXER (SUP, sup);

141
libavformat/stldec.c Normal file
View File

@ -0,0 +1,141 @@
/*
* Copyright (c) 2014 Eejya Singh
*
* 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
* STL subtitles format demuxer
* @see https://documentation.apple.com/en/dvdstudiopro/usermanual/index.html#chapter=19%26section=13%26tasks=true
*/
#include "avformat.h"
#include "internal.h"
#include "subtitles.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/avstring.h"
typedef struct {
FFDemuxSubtitlesQueue q;
} STLContext;
static int stl_probe(AVProbeData *p)
{
char c;
const unsigned char *ptr = p->buf;
if (AV_RB24(ptr) == 0xEFBBBF)
ptr += 3; /* skip UTF-8 BOM */
while (*ptr == '\r' || *ptr == '\n' || *ptr == '$' || !strncmp(ptr, "//" , 2))
ptr += ff_subtitles_next_line(ptr);
if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d , %c", &c) == 1)
return AVPROBE_SCORE_MAX;
return 0;
}
static int64_t get_pts(char **buf, int *duration)
{
int hh1, mm1, ss1, ms1;
int hh2, mm2, ss2, ms2;
int len = 0;
if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , %n",
&hh1, &mm1, &ss1, &ms1,
&hh2, &mm2, &ss2, &ms2, &len) >= 8 && len > 0) {
int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
*duration = end - start;
*buf += len;
return start;
}
return AV_NOPTS_VALUE;
}
static int stl_read_header(AVFormatContext *s)
{
STLContext *stl = s->priv_data;
AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
avpriv_set_pts_info(st, 64, 1, 100);
st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codec->codec_id = AV_CODEC_ID_STL;
while (!avio_feof(s->pb)) {
char line[4096];
char *p = line;
const int64_t pos = avio_tell(s->pb);
int len = ff_get_line(s->pb, line, sizeof(line));
int64_t pts_start;
int duration;
if (!len)
break;
line[strcspn(line, "\r\n")] = 0;
pts_start = get_pts(&p , &duration);
if (pts_start != AV_NOPTS_VALUE) {
AVPacket *sub;
sub = ff_subtitles_queue_insert(&stl->q, p, strlen(p), 0);
if (!sub)
return AVERROR(ENOMEM);
sub->pos = pos;
sub->pts = pts_start;
sub->duration = duration;
}
}
ff_subtitles_queue_finalize(&stl->q);
return 0;
}
static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
{
STLContext *stl = s->priv_data;
return ff_subtitles_queue_read_packet(&stl->q, pkt);
}
static int stl_read_seek(AVFormatContext *s, int stream_index,
int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
{
STLContext *stl = s->priv_data;
return ff_subtitles_queue_seek(&stl->q, s, stream_index,
min_ts, ts, max_ts, flags);
}
static int stl_read_close(AVFormatContext *s)
{
STLContext *stl = s->priv_data;
ff_subtitles_queue_clean(&stl->q);
return 0;
}
AVInputFormat ff_stl_demuxer = {
.name = "stl",
.long_name = NULL_IF_CONFIG_SMALL("Spruce subtitle format"),
.priv_data_size = sizeof(STLContext),
.read_probe = stl_probe,
.read_header = stl_read_header,
.read_packet = stl_read_packet,
.read_seek2 = stl_read_seek,
.read_close = stl_read_close,
.extensions = "stl",
};

View File

@ -30,8 +30,8 @@
#include "libavutil/version.h"
#define LIBAVFORMAT_VERSION_MAJOR 56
#define LIBAVFORMAT_VERSION_MINOR 9
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_MINOR 10
#define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \

View File

@ -37,6 +37,9 @@ fate-sub-sami: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/SAMI_capability_test
FATE_SUBTITLES_ASS-$(call DEMDEC, SRT, SUBRIP) += fate-sub-srt
fate-sub-srt: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/SubRip_capability_tester.srt
FATE_SUBTITLES_ASS-$(call DEMDEC, STL, STL) += fate-sub-stl
fate-sub-stl: CMD = fmtstdout ass -i $(TARGET_SAMPLES)/sub/STL_capability_tester.stl
FATE_SUBTITLES-$(call ALLYES, MOV_DEMUXER MOVTEXT_DECODER SUBRIP_ENCODER SRT_MUXER) += fate-sub-subripenc
fate-sub-subripenc: CMD = fmtstdout srt -i $(TARGET_SAMPLES)/sub/MovText_capability_tester.mp4 -scodec subrip

29
tests/ref/fate/sub-stl Normal file
View File

@ -0,0 +1,29 @@
[Script Info]
; Script generated by FFmpeg/Lavc
ScriptType: v4.00+
PlayResX: 384
PlayResY: 288
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,0,100,100,0,0,1,1,0,2,10,10,10,0
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:31.02,0:00:33.00,Default,,0,0,0,,Hello, my name is Axel Kornmesser.
Dialogue: 0,0:00:45.02,0:00:49.13,Default,,0,0,0,,It is always a pleasure to work with ESA astronomers.
Dialogue: 0,0:00:49.13,0:00:52.03,Default,,0,0,0,,The "Eyes on The Skies" documentary
Dialogue: 0,0:00:52.03,0:00:55.09,Default,,0,0,0,,was our second collaboration
Dialogue: 0,0:00:55.09,0:00:58.07,Default,,0,0,0,,after a great \Nexperience in 2005,
Dialogue: 0,0:00:58.07,0:00:59.20,Default,,0,0,0,,when \Nwe did the story about the
Dialogue: 0,0:00:59.20,0:01:04.01,Default,,0,0,0,,Hubble Telescope "15 Years of Discovery".
Dialogue: 0,0:01:04.16,0:01:07.04,Default,,0,0,0,,It was a lot of fun again.
Dialogue: 0,0:01:15.04,0:01:18.16,Default,,0,0,0,,We usually \N don't get the final film \Nbefore we start composing
Dialogue: 0,0:01:18.21,0:01:22.02,Default,,0,0,0,,We had a script and many details about the story,
Dialogue: 0,0:01:22.10,0:01:26.08,Default,,0,0,0,,and so we worked\N in parallel \Nin the movie production
Dialogue: 0,0:01:27.04,0:01:30.17,Default,,0,0,0,,The largest part of \N the soundtrack \Nwas done without seeing a movie
Dialogue: 0,0:01:30.17,0:01:36.06,Default,,0,0,0,,It was no problem, but very inspiring \Nand a free working process.
Dialogue: 0,0:02:08.13,0:02:10.23,Default,,0,0,0,,Galileo's theme is one of my favourites.
Dialogue: 0,0:02:10.23,0:02:14.10,Default,,0,0,0,,We did a lot of different versions \Nabout the central theme.
Dialogue: 0,0:02:14.10,0:02:18.02,Default,,0,0,0,,For the 17th century \N we used a nice harpsichord
Dialogue: 0,0:02:19.05,0:02:22.09,Default,,0,0,0,,and so we landed directly into Galileo's time.