mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
timecode: better input checks in init function.
This commit is contained in:
parent
66160bdb01
commit
98aca4bbef
@ -55,9 +55,33 @@ uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop)
|
||||
( (frame / (fps * 3600) % 24)) % 10; // units of hours
|
||||
}
|
||||
|
||||
static int check_timecode_rate(void *avcl, AVRational rate, int drop)
|
||||
{
|
||||
int fps;
|
||||
|
||||
if (!rate.num || !rate.den) {
|
||||
av_log(avcl, AV_LOG_ERROR, "Timecode frame rate must be specified\n");
|
||||
return -1;
|
||||
}
|
||||
fps = (rate.num + rate.den/2) / rate.den;
|
||||
if (drop && (rate.den != 1001 || fps != 30)) {
|
||||
av_log(avcl, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n");
|
||||
return -2;
|
||||
}
|
||||
switch (fps) {
|
||||
case 24:
|
||||
case 25:
|
||||
case 30: return 0;
|
||||
|
||||
default:
|
||||
av_log(avcl, AV_LOG_ERROR, "Timecode frame rate not supported\n");
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
|
||||
{
|
||||
int hh, mm, ss, ff, fps;
|
||||
int hh, mm, ss, ff, fps, ret;
|
||||
char c;
|
||||
|
||||
if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) {
|
||||
@ -66,17 +90,17 @@ int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tc->drop = c != ':'; // drop if ';', '.', ...
|
||||
|
||||
ret = check_timecode_rate(avcl, tc->rate, tc->drop);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den;
|
||||
tc->start = (hh*3600 + mm*60 + ss) * fps + ff;
|
||||
tc->drop = c != ':'; // drop if ';', '.', ...
|
||||
|
||||
if (tc->drop) { /* adjust frame number */
|
||||
int tmins = 60*hh + mm;
|
||||
if (tc->rate.den != 1001 || fps != 30) {
|
||||
av_log(avcl, AV_LOG_ERROR, "error: drop frame is only allowed with"
|
||||
"30000/1001 FPS");
|
||||
return -2;
|
||||
}
|
||||
tc->start -= 2 * (tmins - tmins/10);
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user