diff options
author | Clément Bœsch <u@pkh.me> | 2014-09-14 20:30:27 +0200 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2014-09-30 20:21:14 +0200 |
commit | 55180b3299c61e5e3d16f1e9ea58dba8b787cc8e (patch) | |
tree | 9984561f4546525c823dfad5051c749533aa46a9 /libavcodec | |
parent | d5ddcb5f8e7b14974fabd5e95e6420c6e9b12991 (diff) | |
download | ffmpeg-55180b3299c61e5e3d16f1e9ea58dba8b787cc8e.tar.gz |
Kill timed SRT
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/srtdec.c | 33 | ||||
-rw-r--r-- | libavcodec/srtenc.c | 45 | ||||
-rw-r--r-- | libavcodec/version.h | 2 |
3 files changed, 8 insertions, 72 deletions
diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index 794a25a547..cc1748635a 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -193,28 +193,6 @@ static const char *srt_to_ass(AVCodecContext *avctx, char *out, char *out_end, return in; } -static const char *read_ts(const char *buf, int *ts_start, int *ts_end, - int *x1, int *y1, int *x2, int *y2) -{ - int i, hs, ms, ss, he, me, se; - - for (i=0; i<2; i++) { - /* try to read timestamps in either the first or second line */ - int c = sscanf(buf, "%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d" - "%*[ ]X1:%u X2:%u Y1:%u Y2:%u", - &hs, &ms, &ss, ts_start, &he, &me, &se, ts_end, - x1, x2, y1, y2); - buf += strcspn(buf, "\n"); - buf += !!*buf; - if (c >= 8) { - *ts_start = 100*(ss + 60*(ms + 60*hs)) + *ts_start/10; - *ts_end = 100*(se + 60*(me + 60*he)) + *ts_end /10; - return buf; - } - } - return NULL; -} - static int srt_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt) { @@ -237,11 +215,7 @@ static int srt_decode_frame(AVCodecContext *avctx, return avpkt->size; while (ptr < end && *ptr) { - if (avctx->codec->id == AV_CODEC_ID_SRT) { - ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2); - if (!ptr) - break; - } else { + // TODO: reindent // Do final divide-by-10 outside rescale to force rounding down. ts_start = av_rescale_q(avpkt->pts, avctx->time_base, @@ -249,7 +223,6 @@ static int srt_decode_frame(AVCodecContext *avctx, 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); ret = ff_ass_add_rect(sub, buffer, ts_start, ts_end-ts_start, 0); @@ -265,9 +238,9 @@ static int srt_decode_frame(AVCodecContext *avctx, /* deprecated decoder */ AVCodec ff_srt_decoder = { .name = "srt", - .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle with embedded timing"), + .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"), .type = AVMEDIA_TYPE_SUBTITLE, - .id = AV_CODEC_ID_SRT, + .id = AV_CODEC_ID_SUBRIP, .init = ff_ass_subtitle_header_default, .decode = srt_decode_frame, }; diff --git a/libavcodec/srtenc.c b/libavcodec/srtenc.c index 89c26dcbf0..328797089c 100644 --- a/libavcodec/srtenc.c +++ b/libavcodec/srtenc.c @@ -33,8 +33,6 @@ typedef struct { AVCodecContext *avctx; ASSSplitContext *ass_ctx; AVBPrint buffer; - unsigned timestamp_end; - int count; char stack[SRT_STACK_SIZE]; int stack_ptr; int alignment_applied; @@ -201,35 +199,13 @@ static void srt_cancel_overrides_cb(void *priv, const char *style) static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2, int t1, int t2) { - SRTContext *s = priv; - - if (s->avctx->codec->id == AV_CODEC_ID_SRT) { - char buffer[32]; - int len = snprintf(buffer, sizeof(buffer), - " X1:%03u X2:%03u Y1:%03u Y2:%03u", x1, x2, y1, y2); - unsigned char *dummy; - unsigned room; - - av_bprint_get_buffer(&s->buffer, len, &dummy, &room); - if (room >= len) { - memmove(s->buffer.str + s->timestamp_end + len, - s->buffer.str + s->timestamp_end, - s->buffer.len - s->timestamp_end + 1); - memcpy(s->buffer.str + s->timestamp_end, buffer, len); - } - /* Increment even if av_bprint_get_buffer() did not return enough room: - the bprint structure will be treated as truncated. */ - s->buffer.len += len; - } + // TODO: add a AV_PKT_DATA_SUBTITLE_POSITION side data when a new subtitles + // encoding API passing the AVPacket is available. } static void srt_end_cb(void *priv) { - SRTContext *s = priv; - srt_stack_push_pop(priv, 0, 1); - if (s->avctx->codec->id == AV_CODEC_ID_SRT) - srt_print(priv, "\r\n\r\n"); } static const ASSCodesCallbacks srt_callbacks = { @@ -263,19 +239,6 @@ static int srt_encode_frame(AVCodecContext *avctx, dialog = ff_ass_split_dialog(s->ass_ctx, sub->rects[i]->ass, 0, &num); for (; dialog && num--; dialog++) { - if (avctx->codec->id == AV_CODEC_ID_SRT) { - int sh, sm, ss, sc = 10 * dialog->start; - int eh, em, es, ec = 10 * dialog->end; - sh = sc/3600000; sc -= 3600000*sh; - sm = sc/ 60000; sc -= 60000*sm; - ss = sc/ 1000; sc -= 1000*ss; - eh = ec/3600000; ec -= 3600000*eh; - em = ec/ 60000; ec -= 60000*em; - es = ec/ 1000; ec -= 1000*es; - srt_print(s,"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n", - ++s->count, sh, sm, ss, sc, eh, em, es, ec); - s->timestamp_end = s->buffer.len - 2; - } s->alignment_applied = 0; srt_style_apply(s, dialog->style); ff_ass_split_override_codes(&srt_callbacks, s, dialog->text); @@ -308,9 +271,9 @@ static int srt_encode_close(AVCodecContext *avctx) /* deprecated encoder */ AVCodec ff_srt_encoder = { .name = "srt", - .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle with embedded timing"), + .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"), .type = AVMEDIA_TYPE_SUBTITLE, - .id = AV_CODEC_ID_SRT, + .id = AV_CODEC_ID_SUBRIP, .priv_data_size = sizeof(SRTContext), .init = srt_encode_init, .encode_sub = srt_encode_frame, diff --git a/libavcodec/version.h b/libavcodec/version.h index a77e8b7401..022e27b3ce 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -30,7 +30,7 @@ #define LIBAVCODEC_VERSION_MAJOR 56 #define LIBAVCODEC_VERSION_MINOR 1 -#define LIBAVCODEC_VERSION_MICRO 101 +#define LIBAVCODEC_VERSION_MICRO 102 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ |