diff options
Diffstat (limited to 'libavcodec/srtdec.c')
-rw-r--r-- | libavcodec/srtdec.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index bbc8061..f32521f 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -2,20 +2,20 @@ * SubRip subtitle decoder * Copyright (c) 2010 Aurelien Jacobs <aurel@gnuage.org> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -217,26 +217,47 @@ static int srt_decode_frame(AVCodecContext *avctx, if (avpkt->size <= 0) return avpkt->size; - ff_ass_init(sub); - while (ptr < end && *ptr) { - ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2); - if (!ptr) - break; + if (avctx->codec->id == CODEC_ID_SRT) { + ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2); + if (!ptr) + break; + } else { + // Do final divide-by-10 outside rescale to force rounding down. + ts_start = av_rescale_q(avpkt->pts, + avctx->time_base, + (AVRational){1,100}); + ts_end = av_rescale_q(avpkt->pts + avpkt->duration, + avctx->time_base, + (AVRational){1,100}); + } ptr = srt_to_ass(avctx, buffer, buffer+sizeof(buffer), ptr, x1, y1, x2, y2); - ff_ass_add_rect(sub, buffer, ts_start, ts_end, 0); + ff_ass_add_rect(sub, buffer, ts_start, ts_end-ts_start, 0); } *got_sub_ptr = sub->num_rects > 0; return avpkt->size; } +#if CONFIG_SRT_DECODER AVCodec ff_srt_decoder = { .name = "srt", - .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"), + .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle with embedded timing"), .type = AVMEDIA_TYPE_SUBTITLE, .id = AV_CODEC_ID_SRT, .init = ff_ass_subtitle_header_default, .decode = srt_decode_frame, }; +#endif + +#if CONFIG_SUBRIP_DECODER +AVCodec ff_subrip_decoder = { + .name = "subrip", + .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"), + .type = AVMEDIA_TYPE_SUBTITLE, + .id = AV_CODEC_ID_SUBRIP, + .init = ff_ass_subtitle_header_default, + .decode = srt_decode_frame, +}; +#endif |