使用以毫秒为单位的QTTime



我得到我的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)

下面应该可以工作:

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;

相关内容

  • 没有找到相关文章