gpt4 book ai didi

objective-c - 在 objective-c 中将 CMTime 转换为人类可读时间

转载 作者:IT王子 更新时间:2023-10-29 07:54:58 25 4
gpt4 key购买 nike

所以我有一个来自视频的 CMTime。我如何将它转换成一个漂亮的字符串,就像照片应用程序中的视频持续时间标签一样。有一些方便的方法可以处理这个吗?谢谢。

AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
CMTime videoDuration = videoAsset.duration;
float videoDurationSeconds = CMTimeGetSeconds(videoDuration);

最佳答案

如果您不需要日期格式,您也可以使用它来获取文本格式的视频时长

AVURLAsset *videoAVURLAsset = [AVURLAsset assetWithURL:url];
CMTime durationV = videoAVURLAsset.duration;

NSUInteger dTotalSeconds = CMTimeGetSeconds(durationV);

NSUInteger dHours = floor(dTotalSeconds / 3600);
NSUInteger dMinutes = floor(dTotalSeconds % 3600 / 60);
NSUInteger dSeconds = floor(dTotalSeconds % 3600 % 60);

NSString *videoDurationText = [NSString stringWithFormat:@"%i:%02i:%02i",dHours, dMinutes, dSeconds];

关于objective-c - 在 objective-c 中将 CMTime 转换为人类可读时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10654750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com