gpt4 book ai didi

ios - 为什么我的 AVURLAsset 没有持续时间?

转载 作者:可可西里 更新时间:2023-11-01 17:02:21 25 4
gpt4 key购买 nike

在我的 iOS 应用程序 (SDK 5.6) 中,我从一个短视频创建了一个 AVURLAsset,如下所示:

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:assetURL options:nil];

这似乎工作正常。如果我检查 gdb 中的 Assets ,它看起来像这样:

(gdb) po asset
<AVURLAsset: 0x1a1c40, URL = file://localhost/var/mobile/Applications/A2142D8E-BC19-4E0B-A4C8-ABED4F7D4970/Documents/sample_iTunes.mov>

我使用来自 Apple 网站的示例 .mov 文件,该文件存储在应用程序的文档目录中。

我想知道这个视频的持续时间,以便进一步处理,但是当我检查持续时间属性时,我得到了这个:

(gdb) po asset.duration
There is no member named duration.

我做错了什么?有没有其他方法可以确定 AVAsset 或 AVAssetTrack 的持续时间?

TIA:约翰

最佳答案

但是,创建 Assets 并不一定意味着它已准备好使用。要使用, Assets 必须加载其轨道。使用

加载 Assets

[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler: ^{ // The completion block goes here. }];

数组中应该有一个“持续时间”键。

加载完成后,获取时长

Float64 durationSeconds = CMTimeGetSeconds([<#An asset#> duration]);

关于ios - 为什么我的 AVURLAsset 没有持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7447175/

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