History

avformat/lrcdec: support arbitrary precision timestamp

Apparently files with milliseconds exist in the wild. And since it cost nothing to support arbitrary number of digits, extend format to support that. Depending on number of digits, the time base of fractional part is changing. Most LRCs use 2 digits and centiseconds base, but subs with 3 digits and miliseconds exist too. Set internal time base to AV_TIME_BASE, which in parcitice allows to hold microseconds with 6 digits. Totally artificial, but who knows maybe someone wants that. Fixes: #11677

Kacper Michajłow committed 1 year ago

Commit bc3cc0a1 parent e916f551 file · +10 −8Browse files

Showing the changes to libavformat (1 of 1 file). Show all

Unified · Split

libavformat/lrcdec.c+10−8
@@ -78,7 +78,9 @@ static int64_t count_ts(const char *p) · 77 unmodified lines
78static int64_t read_ts(const char *p, int64_t *start)78static int64_t read_ts(const char *p, int64_t *start)
79{79{
80 int64_t offset = 0;80 int64_t offset = 0;
81 uint64_t mm, ss, cs;81 uint64_t mm;
82 double ss;
83 char prefix[3];
82 84
83 while(p[offset] == ' ' || p[offset] == '\t') {85 while(p[offset] == ' ' || p[offset] == '\t') {
84 offset++;86 offset++;
@@ -86,14 +88,14 @@ static int64_t read_ts(const char *p, int64_t *start) · 1 unmodified line
86 if(p[offset] != '[') {88 if(p[offset] != '[') {
87 return 0;89 return 0;
88 }90 }
89 if(sscanf(p, "[-%"SCNu64":%"SCNu64".%"SCNu64"]", &mm, &ss, &cs) == 3) {91 int ret = sscanf(p, "%2[[-]%"SCNu64":%lf]", prefix, &mm, &ss);
90 /* Just in case negative pts, players may drop it but we won't. */92 if (ret != 3 || prefix[0] != '[') {
91 *start = -(int64_t) (mm*60000 + ss*1000 + cs*10);
92 } else if(sscanf(p, "[%"SCNu64":%"SCNu64".%"SCNu64"]", &mm, &ss, &cs) == 3) {
93 *start = mm*60000 + ss*1000 + cs*10;
94 } else {
95 return 0;93 return 0;
96 }94 }
95 *start = (mm * 60 + ss) * AV_TIME_BASE;
96 if (prefix[1] == '-') {
97 *start = - *start;
98 }
97 do {99 do {
98 offset++;100 offset++;
99 } while(p[offset] && p[offset-1] != ']');101 } while(p[offset] && p[offset-1] != ']');
@@ -164,7 +166,7 @@ static int lrc_read_header(AVFormatContext *s) · 64 unmodified lines
164 if(!st) {166 if(!st) {
165 return AVERROR(ENOMEM);167 return AVERROR(ENOMEM);
166 }168 }
167 avpriv_set_pts_info(st, 64, 1, 1000);169 avpriv_set_pts_info(st, 64, 1, AV_TIME_BASE);
168 lrc->ts_offset = 0;170 lrc->ts_offset = 0;
169 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;171 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
170 st->codecpar->codec_id = AV_CODEC_ID_TEXT;172 st->codecpar->codec_id = AV_CODEC_ID_TEXT;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t