X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fsubviewerdec.c;h=5c2fe676f197268158af4e0ab68f3b4396287230;hb=131f2c2712479a44332866b442526abe97e0c316;hp=61eb80af8787b571aab1095586a111b47bdef3a1;hpb=fda424b300c1a0b991296aa585691609d01196bd;p=ffmpeg diff --git a/libavformat/subviewerdec.c b/libavformat/subviewerdec.c index 61eb80af878..5c2fe676f19 100644 --- a/libavformat/subviewerdec.c +++ b/libavformat/subviewerdec.c @@ -37,7 +37,7 @@ typedef struct { FFDemuxSubtitlesQueue q; } SubViewerContext; -static int subviewer_probe(AVProbeData *p) +static int subviewer_probe(const AVProbeData *p) { char c; const unsigned char *ptr = p->buf; @@ -56,11 +56,21 @@ static int read_ts(const char *s, int64_t *start, int *duration) int64_t end; int hh1, mm1, ss1, ms1; int hh2, mm2, ss2, ms2; + int multiplier = 1; + if (sscanf(s, "%u:%u:%u.%2u,%u:%u:%u.%2u", + &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) { + multiplier = 10; + } else if (sscanf(s, "%u:%u:%u.%1u,%u:%u:%u.%1u", + &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) { + multiplier = 100; + } if (sscanf(s, "%u:%u:%u.%u,%u:%u:%u.%u", &hh1, &mm1, &ss1, &ms1, &hh2, &mm2, &ss2, &ms2) == 8) { - end = (hh2*3600LL + mm2*60LL + ss2) * 100LL + ms2; - *start = (hh1*3600LL + mm1*60LL + ss1) * 100LL + ms1; + ms1 = FFMIN(ms1, 999); + ms2 = FFMIN(ms2, 999); + end = (hh2*3600LL + mm2*60LL + ss2) * 1000LL + ms2 * multiplier; + *start = (hh1*3600LL + mm1*60LL + ss1) * 1000LL + ms1 * multiplier; *duration = end - *start; return 0; } @@ -84,7 +94,7 @@ static int subviewer_read_header(AVFormatContext *s) return res; if (avio_rb24(s->pb) != 0xefbbbf) avio_seek(s->pb, -3, SEEK_CUR); - avpriv_set_pts_info(st, 64, 1, 100); + avpriv_set_pts_info(st, 64, 1, 1000); st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_id = AV_CODEC_ID_SUBVIEWER; @@ -138,6 +148,10 @@ static int subviewer_read_header(AVFormatContext *s) new_event = 1; pos = avio_tell(s->pb); } else if (*line) { + if (pts_start == AV_NOPTS_VALUE) { + res = AVERROR_INVALIDDATA; + goto end; + } if (!new_event) { sub = ff_subtitles_queue_insert(&subviewer->q, "\n", 1, 1); if (!sub) { @@ -162,6 +176,8 @@ static int subviewer_read_header(AVFormatContext *s) ff_subtitles_queue_finalize(s, &subviewer->q); end: + if (res < 0) + ff_subtitles_queue_clean(&subviewer->q); av_bprint_finalize(&header, NULL); return res; }