Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avcodec/srtdec: Keep exact end times
When using FFmpeg as an SRT normalizer, the end timestamps were modified
compared to the original.
  • Loading branch information
eelco committed Dec 1, 2015
1 parent 71e1da8 commit f0e98dd
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions libavcodec/srtdec.c
Expand Up @@ -202,7 +202,7 @@ static int srt_decode_frame(AVCodecContext *avctx,
{
AVSubtitle *sub = data;
AVBPrint buffer;
int ts_start, ts_end, x1 = -1, y1 = -1, x2 = -1, y2 = -1;
int ts_start, ts_duration, x1 = -1, y1 = -1, x2 = -1, y2 = -1;
int size, ret;
const uint8_t *p = av_packet_get_side_data(avpkt, AV_PKT_DATA_SUBTITLE_POSITION, &size);

Expand All @@ -218,17 +218,21 @@ static int srt_decode_frame(AVCodecContext *avctx,

av_bprint_init(&buffer, 0, AV_BPRINT_SIZE_UNLIMITED);

// TODO: reindent
// 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});
// Do final divide-by-10 outside rescale to force rounding down.
ts_start = av_rescale_q(avpkt->pts,
avctx->time_base,
(AVRational){1,100});

// Floor the duration (for ASS output)
ts_duration = avpkt->duration / 10;

// Set an exact end display time to prevent the rounding for ASS messing it up
sub->end_display_time = av_rescale_q(avpkt->duration,
avctx->pkt_timebase,
(AVRational){1,1000});

srt_to_ass(avctx, &buffer, avpkt->data, x1, y1, x2, y2);
ret = ff_ass_add_rect_bprint(sub, &buffer, ts_start, ts_end-ts_start);
ret = ff_ass_add_rect_bprint(sub, &buffer, ts_start, ts_duration);
av_bprint_finalize(&buffer, NULL);
if (ret < 0)
return ret;
Expand Down

0 comments on commit f0e98dd

Please sign in to comment.