gpt4 book ai didi

ios - AVAsset 持续时间不正确

转载 作者:可可西里 更新时间:2023-11-01 05:54:16 26 4
gpt4 key购买 nike

我在 Mac 播放器中有视频,视频时长为 31 秒。当我在我的应用程序中使用它并加载该文件时,AVAsset 的持续时间为“28.03”。

AVAsset *videoAsset = [AVAsset assetWithURL:videoUrl];
Float64 time = CMTimeGetSeconds(videoAsset.duration);

最佳答案

对于某些类型的 Assets ,持续时间是一个近似值。如果您需要确切的持续时间(应该是极端情况),请使用:

NSDictionary *options = @{AVURLAssetPreferPreciseDurationAndTimingKey: @YES};
AVURLAsset *videoAsset = [URLAssetWithURL:videoUrl options:options];

您可以在 documentation 中找到更多信息.计算持续时间可能需要一些时间,所以记得使用异步加载:

[videoAsset loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
switch ([videoAsset statusOfValueForKey:@"duration" error:nil]) {
case AVKeyValueStatusLoaded:
Float64 time = CMTimeGetSeconds(videoAsset.duration);
// ...
break;
default:
// other cases like cancellation or fail
break;
}
}];

您可以在视频 Discovering AV Foundation - WWDC 2010 Session 405 中找到有关使用 AVFoundation API 的更多提示

关于ios - AVAsset 持续时间不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22838562/

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