annotate ffmpeg/libavcodec/realtextdec.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Copyright (c) 2012 Clément Bœsch
yading@10 3 *
yading@10 4 * This file is part of FFmpeg.
yading@10 5 *
yading@10 6 * FFmpeg is free software; you can redistribute it and/or
yading@10 7 * modify it under the terms of the GNU Lesser General Public
yading@10 8 * License as published by the Free Software Foundation; either
yading@10 9 * version 2.1 of the License, or (at your option) any later version.
yading@10 10 *
yading@10 11 * FFmpeg is distributed in the hope that it will be useful,
yading@10 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 14 * Lesser General Public License for more details.
yading@10 15 *
yading@10 16 * You should have received a copy of the GNU Lesser General Public
yading@10 17 * License along with FFmpeg; if not, write to the Free Software
yading@10 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 19 */
yading@10 20
yading@10 21 /**
yading@10 22 * @file
yading@10 23 * RealText subtitle decoder
yading@10 24 * @see http://service.real.com/help/library/guides/ProductionGuide/prodguide/htmfiles/realtext.htm
yading@10 25 */
yading@10 26
yading@10 27 #include "avcodec.h"
yading@10 28 #include "ass.h"
yading@10 29 #include "libavutil/avstring.h"
yading@10 30 #include "libavutil/bprint.h"
yading@10 31
yading@10 32 static int rt_event_to_ass(AVBPrint *buf, const char *p)
yading@10 33 {
yading@10 34 int prev_chr_is_space = 1;
yading@10 35
yading@10 36 while (*p) {
yading@10 37 if (*p != '<') {
yading@10 38 if (!av_isspace(*p))
yading@10 39 av_bprint_chars(buf, *p, 1);
yading@10 40 else if (!prev_chr_is_space)
yading@10 41 av_bprint_chars(buf, ' ', 1);
yading@10 42 prev_chr_is_space = av_isspace(*p);
yading@10 43 } else {
yading@10 44 const char *end = strchr(p, '>');
yading@10 45 if (!end)
yading@10 46 break;
yading@10 47 if (!av_strncasecmp(p, "<br/>", 5) ||
yading@10 48 !av_strncasecmp(p, "<br>", 4)) {
yading@10 49 av_bprintf(buf, "\\N");
yading@10 50 }
yading@10 51 p = end;
yading@10 52 }
yading@10 53 p++;
yading@10 54 }
yading@10 55 av_bprintf(buf, "\r\n");
yading@10 56 return 0;
yading@10 57 }
yading@10 58
yading@10 59 static int realtext_decode_frame(AVCodecContext *avctx,
yading@10 60 void *data, int *got_sub_ptr, AVPacket *avpkt)
yading@10 61 {
yading@10 62 AVSubtitle *sub = data;
yading@10 63 const char *ptr = avpkt->data;
yading@10 64 AVBPrint buf;
yading@10 65
yading@10 66 av_bprint_init(&buf, 0, 4096);
yading@10 67 // note: no need to rescale pts & duration since they are in the same
yading@10 68 // timebase as ASS (1/100)
yading@10 69 if (ptr && avpkt->size > 0 && !rt_event_to_ass(&buf, ptr))
yading@10 70 ff_ass_add_rect(sub, buf.str, avpkt->pts, avpkt->duration, 0);
yading@10 71 *got_sub_ptr = sub->num_rects > 0;
yading@10 72 av_bprint_finalize(&buf, NULL);
yading@10 73 return avpkt->size;
yading@10 74 }
yading@10 75
yading@10 76 AVCodec ff_realtext_decoder = {
yading@10 77 .name = "realtext",
yading@10 78 .long_name = NULL_IF_CONFIG_SMALL("RealText subtitle"),
yading@10 79 .type = AVMEDIA_TYPE_SUBTITLE,
yading@10 80 .id = AV_CODEC_ID_REALTEXT,
yading@10 81 .decode = realtext_decode_frame,
yading@10 82 .init = ff_ass_subtitle_header_default,
yading@10 83 };