Skip to content

Instantly share code, notes, and snippets.

@yohhoy
Created August 19, 2019 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yohhoy/5f2e593ef574f077af03b6511650eec8 to your computer and use it in GitHub Desktop.
Save yohhoy/5f2e593ef574f077af03b6511650eec8 to your computer and use it in GitHub Desktop.
FFmpeg/av_timecode_init_from_string() with "59.94DF" support
/*
* https://github.com/intel/ffmpeg_libyami/blob/master/libavutil/timecode.c
*/
inline int av_timecode_init_from_string2(AVTimecode* tc, AVRational rate, const char* str)
{
#if 0
return av_timecode_init_from_string(&tc, rate, str, NULL);
#else
char c;
int hh, mm, ss, ff;
if (sscanf(str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5)
return AVERROR_INVALIDDATA;
tc->flags = c != ':' ? AV_TIMECODE_FLAG_DROPFRAME : 0;
tc->rate = rate;
tc->fps = (rate.num + rate.den/2) / rate.den;
tc->start = (hh*3600 + mm*60 + ss) * tc->fps + ff;
if (tc->flags & AV_TIMECODE_FLAG_DROPFRAME) {
int tmins = 60*hh + mm;
int factor = (tc->fps == 30) ? 2 : 4; // 30 or 60
tc->start -= factor * (tmins - tmins/10);
}
return 0;
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment