Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0a1,21
- > /*
- > * SubRip subtitle demuxer
- > * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org>
- > *
- > * 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
- > */
- >
- 9c30
- < } STLContext;
- ---
- > } SRTContext;
- 11c32
- < static int stl_probe(AVProbeData *p)
- ---
- > static int srt_probe(AVProbeData *p)
- 13,15c34,53
- < char c;
- < const unsigned char *ptr = p->buf;
- < if (sscanf(ptr, "%*d:%*d:%*d:%*d , %*d:%*d:%*d:%*d ,", &c) == 1)
- ---
- > int v;
- > char buf[64], *pbuf;
- > FFTextReader tr;
- >
- > ff_text_init_buf(&tr, p->buf, p->buf_size);
- >
- > while (ff_text_peek_r8(&tr) == '\r' || ff_text_peek_r8(&tr) == '\n')
- > ff_text_r8(&tr);
- >
- > /* Check if the first non-empty line is a number. We do not check what the
- > * number is because in practice it can be anything. */
- > if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0 ||
- > strtol(buf, &pbuf, 10) < 0 || *pbuf)
- > return 0;
- >
- > /* Check if the next line matches a SRT timestamp */
- > if (ff_subtitles_read_line(&tr, buf, sizeof(buf)) < 0)
- > return 0;
- > if (buf[0] >= '0' && buf[1] <= '9' && strstr(buf, " --> ")
- > && sscanf(buf, "%*d:%*2d:%*2d%*1[,.]%*3d --> %*d:%*2d:%*2d%*1[,.]%3d", &v) == 1)
- 16a55
- >
- 18a58
- >
- 21a62,64
- > int i;
- >
- > for (i=0; i<2; i++) {
- 24c67,68
- < if (sscanf(*buf, "%2d:%2d:%2d:%2d , %2d:%2d:%2d:%2d , ",
- ---
- > if (sscanf(*buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d"
- > "%*[ ]X1:%u X2:%u Y1:%u Y2:%u",
- 26,28c70,73
- < &hh2, &mm2, &ss2, &ms2) >= 6) {
- < int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1;
- < int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2;
- ---
- > &hh2, &mm2, &ss2, &ms2,
- > x1, x2, y1, y2) >= 8) {
- > int64_t start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1;
- > int64_t end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2;
- 34c79
- <
- ---
- > }
- 38c83
- < static int stl_read_header(AVFormatContext *s)
- ---
- > static int srt_read_header(AVFormatContext *s)
- 40c85
- < STLContext *stl = s->priv_data;
- ---
- > SRTContext *srt = s->priv_data;
- 49c94
- < avpriv_set_pts_info(st, 64, 1, 100);
- ---
- > avpriv_set_pts_info(st, 64, 1, 1000);
- 51c96
- < st->codec->codec_id = AV_CODEC_ID_TEXT;
- ---
- > st->codec->codec_id = AV_CODEC_ID_SUBRIP;
- 71c116
- < sub = ff_subtitles_queue_insert(&stl->q, ptr, len, 0);
- ---
- > sub = ff_subtitles_queue_insert(&srt->q, ptr, len, 0);
- 92c137
- < ff_subtitles_queue_finalize(&stl->q);
- ---
- > ff_subtitles_queue_finalize(&srt->q);
- 99,140c144
- < /*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_TEXT;
- <
- < 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;
- <
- < if (!len)
- < break;
- <
- < line[strcspn(line, "\r\n")] = 0;
- <
- < pts_start = read_ts(&p);
- < 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 = -1;
- < }
- < }
- <
- < ff_subtitles_queue_finalize(&stl->q);
- < return 0;
- < }
- < */
- < static int stl_read_packet(AVFormatContext *s, AVPacket *pkt)
- ---
- > static int srt_read_packet(AVFormatContext *s, AVPacket *pkt)
- 142,143c146,147
- < STLContext *stl = s->priv_data;
- < return ff_subtitles_queue_read_packet(&stl->q, pkt);
- ---
- > SRTContext *srt = s->priv_data;
- > return ff_subtitles_queue_read_packet(&srt->q, pkt);
- 146,147c150,151
- < static int stl_read_seek(AVFormatContext *s, int stream_index,
- < int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
- ---
- > static int srt_read_seek(AVFormatContext *s, int stream_index,
- > int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
- 149,150c153,154
- < STLContext *stl = s->priv_data;
- < return ff_subtitles_queue_seek(&stl->q, s, stream_index,
- ---
- > SRTContext *srt = s->priv_data;
- > return ff_subtitles_queue_seek(&srt->q, s, stream_index,
- 154c158
- < static int stl_read_close(AVFormatContext *s)
- ---
- > static int srt_read_close(AVFormatContext *s)
- 156,157c160,161
- < STLContext *stl = s->priv_data;
- < ff_subtitles_queue_clean(&stl->q);
- ---
- > SRTContext *srt = s->priv_data;
- > ff_subtitles_queue_clean(&srt->q);
- 161,170c165,173
- < AVInputFormat ff_stl_demuxer = {
- < .name = "stl",
- < .long_name = NULL_IF_CONFIG_SMALL("STL subtitles"),
- < .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",
- ---
- > AVInputFormat ff_srt_demuxer = {
- > .name = "srt",
- > .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"),
- > .priv_data_size = sizeof(SRTContext),
- > .read_probe = srt_probe,
- > .read_header = srt_read_header,
- > .read_packet = srt_read_packet,
- > .read_seek2 = srt_read_seek,
- > .read_close = srt_read_close,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement