summaryrefslogtreecommitdiff
path: root/libavcodec/srtdec.c
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2012-08-11 20:27:51 -0700
committerPhilip Langdale <philipl@overt.org>2012-08-15 20:44:23 -0700
commit6af680fa070ebc5081045e4b24ceaa4fccfa89b4 (patch)
tree89bae7c77e4b1a0070e2521009bd5c4bfe017920 /libavcodec/srtdec.c
parentb1b84b068d20d29aa9e1c0cc3a989e293138997c (diff)
srtdec: Add timing-less "subrip" decoder.
After various discussions, we concluded that, amongst other things, it made sense to have a separate subrip decoder that did not use in-band timing information, and rather relied on the ffmpeg level timing. As this is 90% the same as the existing srt decoder, it's implemented in the same file. Signed-off-by: Philip Langdale <philipl@overt.org>
Diffstat (limited to 'libavcodec/srtdec.c')
-rw-r--r--libavcodec/srtdec.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
index 13e4f9c7e3..3d3ace0a87 100644
--- a/libavcodec/srtdec.c
+++ b/libavcodec/srtdec.c
@@ -217,9 +217,19 @@ static int srt_decode_frame(AVCodecContext *avctx,
return avpkt->size;
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-ts_start, 0);
@@ -229,11 +239,24 @@ static int srt_decode_frame(AVCodecContext *avctx,
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