[FFmpeg-devel] [PATCH 1/2] lavc/srtdec: make read_ts preserve the millisecond.
Clément Bœsch
ubitux at gmail.com
Tue Sep 11 19:42:25 CEST 2012
On Sun, Sep 02, 2012 at 10:03:17AM +0200, Nicolas George wrote:
> The times are also changed to int64_t.
>
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
> libavcodec/srtdec.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c
> index f32521f..12b7e0c 100644
> --- a/libavcodec/srtdec.c
> +++ b/libavcodec/srtdec.c
> @@ -184,21 +184,21 @@ 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,
> +static const char *read_ts(const char *buf, int64_t *ts_start, int64_t *ts_end,
> int *x1, int *y1, int *x2, int *y2)
> {
> - int i, hs, ms, ss, he, me, se;
> + int i, hs, ms, ss, mss, he, me, se, mse;
>
> 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,
> + &hs, &ms, &ss, &mss, &he, &me, &se, &mse,
> x1, x2, y1, y2);
> buf += strcspn(buf, "\n") + 1;
> 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;
> + *ts_start = (int64_t)1000*(ss + 60*(ms + 60*hs)) + mss;
> + *ts_end = (int64_t)1000*(se + 60*(me + 60*he)) + mse;
> return buf;
> }
> }
> @@ -209,7 +209,8 @@ static int srt_decode_frame(AVCodecContext *avctx,
> void *data, int *got_sub_ptr, AVPacket *avpkt)
> {
> AVSubtitle *sub = data;
> - int ts_start, ts_end, x1 = -1, y1 = -1, x2 = -1, y2 = -1;
> + int64_t ts_start, ts_end;
> + int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
> char buffer[2048];
> const char *ptr = avpkt->data;
> const char *end = avpkt->data + avpkt->size;
> @@ -223,17 +224,16 @@ static int srt_decode_frame(AVCodecContext *avctx,
> 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});
> + (AVRational){1,1000});
> ts_end = av_rescale_q(avpkt->pts + avpkt->duration,
> avctx->time_base,
> - (AVRational){1,100});
> + (AVRational){1,1000});
> }
> 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);
> + ff_ass_add_rect(sub, buffer, ts_start / 10, ts_end / 10 - ts_start / 10, 0);
> }
>
IMO the correct this is to make read_ts() just skip the TS (shift the
pointer to the payload) and always rely on the avpkt->pts (SRT demuxer and
MKV demuxer should always set the correct timing).
Then the rescale to 1/100 is correct for the ASS step.
[...]
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120911/56b33542/attachment.asc>
More information about the ffmpeg-devel
mailing list