我得到QTMovieView
的当前时间,如此:
QTTime time = self.movieView.movie.currentTime;
然后将其放入SMPTE表格
NSString *SMPTE_string;
int days, hour, minute, second, frame;
long long result;
result = time.timeValue / time.timeScale; // second
frame = (time.timeValue % time.timeScale) / 100;
second = result % 60;
result = result / 60; // minute
minute = result % 60;
result = result / 60; // hour
hour = result % 24;
days = result;
SMPTE_string = [NSString stringWithFormat:@"%02d:%02d:%02d:%02d", hour, minute, second, frame]; // hh:mm:ss:ff
但我不想让它以帧号结束。我希望它以毫秒结束(hh:mm:ss.mil)
答案 0 :(得分:2)
以下内容应该有效:
double second = (double)time.timeValue / (double)time.timeScale;
int result = second / 60;
second -= 60 * result;
int minute = result % 60;
result = result / 60;
int hour = result % 24;
int days = result / 24;
NSString *SMPTE_string = [NSString stringWithFormat:@"%02d:%02d:%06.3f", hour, minute, second];
秒数计算为double
而不是int
,然后打印
使用%06.3f
格式以毫秒精度。
(请注意,代码中的days = result
不正确。)
如果您更喜欢整数运算,那么您也可以计算毫秒数
QTTime time
与
long long milli = (1000 * (time.timeValue % time.timeScale)) / time.timeScale;