AVFoundation编程指南10-AVAsset解读(下)

作者: 张芳涛 | 来源:发表于2019-05-17 14:34 被阅读9次

    写在前面

    喜欢AVFoundation资料的同学可以关注我的专题:《AVFoundation》专辑
    也可以关注我的简书账号

    正文

    AVURLAsset

    用于选项字典的键 - [AVURLAsset initWithURL:options:]

    AVF_EXPORT NSString *const AVURLAssetPreferPreciseDurationAndTimingKey NS_AVAILABLE(10_7, 4_0);
    
    Key名称 AVURLAssetPreferPreciseDurationAndTimingKey
    函数解释 指示asset是否应准备好指示精确的持续时间并按时间提供精确的随机访问。

    此键的值是布尔类型的NSNumber
    备注 如果将nil作为options参数的值传递给- [AVURLAsset initWithURL:options:],或者如果传递缺少键AVURLAssetPreferPreciseDurationAndTimingKey的值的字典,则假定默认值为NO。如果仅打算播放asset,因为当全精度不可用时,AVPlayer将支持按时间进行近似随机访问,默认值为NO就足够了。

    如果在需要精确计时的情况下可以接受更长的加载时间,则通过YES。如果要将asset插入AVMutableComposition,通常需要精确的随机访问,建议使用YES值。

    请注意,根据其容器格式的具体情况,此类精度可能需要在使用其任何部分的操作之前额外解析资源。许多容器格式提供了足够的摘要信息以便精确计时,并且不需要额外的解析来准备它; QuickTime电影文件和MPEG-4文件是此类格式的示例。其他格式不提供足够的摘要信息,只有在对文件内容进行初步检查后才能对它们进行精确的随机访问。

    如果asset``URL引用的定时媒体资源无法获得精确的持续时间和时间,则即使通过使用此key请求精确计时,AVAsset.providesPreciseDurationAndTiming也将为NO
    AVF_EXPORT NSString *const AVURLAssetReferenceRestrictionsKey NS_AVAILABLE(10_7, 5_0);
    
    Key名称 AVURLAssetReferenceRestrictionsKey
    解释 指示asset在解析对外部媒体数据的引用时使用的限制。此键的值是包含AVAssetReferenceRestrictions枚举值的NSNumber或多个此类值的逻辑组合。
    备注 某些asset可以包含对存储在asset容器文件外部的媒体数据的引用,例如在另一个文件中。这个key可用于指定遇到这些引用时要使用的策略。如果asset包含一个或多个参考限制禁止的类型的引用,则asset属性的加载将失败。此外,此类asset不能与其他AVFoundation模块一起使用,例如AVPlayerItemAVAssetExportSession
    AVF_EXPORT NSString *const AVURLAssetHTTPCookiesKey API_AVAILABLE(ios(8.0), tvos(9.0)) API_UNAVAILABLE(macos) __WATCHOS_PROHIBITED;
    
    Key名称 AVURLAssetHTTPCookiesKey
    解释 AVURLAsset可以通过HTTP请求发送的HTTP cookie

    标准跨站点策略仍然适用:cookie仅发送到它们适用的域。
    备注 默认情况下,AVURLAsset只能访问客户端默认cookie存储中的cookie

    适用于AVURLAssetURL。你可以补充asset可用的cookie

    通过使用此初始化选项

    HTTP cookie不适用于非HTTPSURL

    HLS中,许多HTTP请求(例如,媒体,密钥,变体索引)可以被发布到不同的路径或主机。

    在这两种情况下,HTTP请求都将丢失任何不适用于AVURLAsset URLcookie

    init选项允许AVURLAsset为这些HTTPS)请求使用其他HTTP``cookie
    AVF_EXPORT NSString *const AVURLAssetAllowsCellularAccessKey API_AVAILABLE(ios(10.0), tvos(10.0)) API_UNAVAILABLE(macos) __WATCHOS_PROHIBITED;
    
    Key名称 AVURLAssetAllowsCellularAccessKey
    解释 指示是否允许代表此asset的网络请求使用蜂窝接口。
    备注 默认是 YES

    AVURLAsset

    + (NSArray<AVFileType> *)audiovisualTypes NS_AVAILABLE(10_7, 5_0);
    
    函数名 audiovisualTypes
    函数解释 提供AVURLAsset类可以理解的文件类型。
    返回值 UTINSArray标识AVURLAsset类可以理解的文件类型。
    + (NSArray<NSString *> *)audiovisualMIMETypes NS_AVAILABLE(10_7, 5_0);
    
    函数名 audiovisualMIMETypes
    解释 提供AVURLAsset类可以理解的MIME类型。
    返回值 返回一个包含NSString类型的NSArray数组,其包含了MIME类型的AVURLAsset
    + (BOOL)isPlayableExtendedMIMEType: (NSString *)extendedMIMEType NS_AVAILABLE(10_7, 5_0);
    
    函数名 isPlayableExtendedMIMEType:
    函数解释 如果asset可以使用extendedMIMEType中指定的编解码器和容器类型播放,则返回YES。否则返回NO
    参数 extendedMIMEType
    返回值 YES 或者是 NO
    + (instancetype)URLAssetWithURL:(NSURL *)URL options:(nullable NSDictionary<NSString *, id> *)options;
    
    函数名 URLAssetWithURL:options:
    解释 返回AVURLAsset的实例以检查媒体资源。
    参数 URL
    一个NSURL的实例,它引用媒体资源。

    options:
    一个NSDictionary的实例,包含用于指定AVURLAsset初始化选项的键。请参阅上面的AVURLAssetPreferPreciseDurationAndTimingKeyAVURLAssetReferenceRestrictionsKey
    返回值 返回一个AVURLAsset的实例。
    - (instancetype)initWithURL:(NSURL *)URL options:(nullable NSDictionary<NSString *, id> *)options NS_DESIGNATED_INITIALIZER;
    
    函数名 initWithURL:options:
    解释 初始化AVURLAsset的实例以检查媒体资源。
    参数 URL:
    一个NSURL的实例,它引用媒体资源。

    options:
    一个NSDictionary的实例,包含用于指定AVURLAsset初始化选项的键。请参阅上面的AVURLAssetPreferPreciseDurationAndTimingKeyAVURLAssetReferenceRestrictionsKey
    返回值 一个AVURLAsset的实例。
    @property (nonatomic, readonly, copy) NSURL *URL;
    

    表示初始化AVURLAsset实例的URL

    AVURLAssetURLHandling

    @property (nonatomic, readonly) AVAssetResourceLoader *resourceLoader NS_AVAILABLE(10_9, 6_0);
    

    提供对AVAssetResourceLoader实例的访问,该实例提供对在asset上执行操作(例如playback)过程中可能加载的URL处理的有限控制。

    无法通过使用AVAssetResourceLoader来调解文件URL的加载。

    请注意,AVAsset的副本将提供相同的AVAssetResourceLoader实例。

    AVURLAssetCache

    @property (nonatomic, readonly, nullable) AVAssetCache *assetCache NS_AVAILABLE(10_12, 10_0);
    

    提供对AVAssetCache实例的访问,以用于检查本地缓存的媒体数据。如果asset尚未配置为存储或访问磁盘中的媒体数据,则为nil

    AVAssetCompositionUtility

     - (nullable AVAssetTrack *)compatibleTrackForCompositionTrack:(AVCompositionTrack *)compositionTrack;
    
    函数名 compatibleTrackForCompositionTrack:
    解释 提供对任何timeRange的目标的AVAssetTrack的引用。

    可以插入到可变组合track中(通过 - [AVMutableCompositionTrack insertTimeRange:ofTrack:atTime:error:])。
    参数 compositionTrack:
    要求兼容的AVAssetTrack的合成track
    返回值 返回一个AVAssetTrack的实例
    备注 查找具有指定合成轨迹可容纳的内容的目标track

    - [AVMutableComposition mutableTrackCompatibleWithTrack:]的逻辑补充。

    AVAsset change notifications

    AVF_EXPORT NSString *const AVAssetDurationDidChangeNotification NS_AVAILABLE(10_11, 9_0);
    
    通知名称 AVAssetDurationDidChangeNotification
    解释 AVFragmentedAsset的持续时间在被AVFragmentedAssetMinder调整时发生变化时发布,但仅适用于@“duration”的状态达到AVKeyValueStatusLoaded后发生的更改。
    AVF_EXPORT NSString *const AVAssetContainsFragmentsDidChangeNotification API_AVAILABLE(macos(10.11), ios(12.0), tvos(12.0)) API_UNAVAILABLE(watchos);
    
    通知名称 AVAssetContainsFragmentsDidChangeNotification
    解释 @“containsFragments”的值已经被加载并且AVFragmentedAsset被添加到AVFragmentedAssetMinder之后发布,或者当值为1的时候)在磁盘上的asset中检测到片段之后它没有被检测到或者当值为2的时候)没有检测到片段时之前包含一个或多个asset的磁盘上的asset
    AVF_EXPORT NSString *const AVAssetWasDefragmentedNotification API_AVAILABLE(macos(10.11), ios(12.0), tvos(12.0)) API_UNAVAILABLE(watchos);
    
    通知名称 AVAssetWasDefragmentedNotification
    解释 AVFragmentedAssetMinder正在调整AVFragmentedAsset时对磁盘上的asset进行碎片整理时发布,但仅在@“canContainFragments”的值状态达到AVKeyValueStatusLoaded之后进行碎片整理时才会发布。
    备注 发布此通知后,asset属性canContainFragmentscontainsFragments的值都将为NO
    AVF_EXPORT NSString *const AVAssetChapterMetadataGroupsDidChangeNotification NS_AVAILABLE(10_11, 9_0);
    
    通知名称 AVAssetChapterMetadataGroupsDidChangeNotification
    解释 当表示AVAsset``capture的定时元数据组数组的集合发生更改以及定时元数据组的任何内容发生更改时发布,但仅适用于@“availableChapterLocales”值的状态达到AVKeyValueStatusLoaded后发生的更改。
    AVF_EXPORT NSString *const AVAssetMediaSelectionGroupsDidChangeNotification NS_AVAILABLE(10_11, 9_0);
    
    通知名称 AVAssetMediaSelectionGroupsDidChangeNotification
    解释 AVAsset提供的媒体选择组集合发生更改以及其媒体选择组的任何内容发生更改时发布,但仅适用于@“availableMediaCharacteristicsWithMediaSelectionOptions”值的状态达到AVKeyValueStatusLoaded后发生的更改。

    AVFragmentMinding代理方法

    @property (nonatomic, readonly, getter=isAssociatedWithFragmentMinder) BOOL associatedWithFragmentMinder API_AVAILABLE(macos(10.11), ios(12.0), tvos(12.0)) API_UNAVAILABLE(watchos);
    
    代理名称 associatedWithFragmentMinder
    解释 指示支持片段管理的AVAsset当前是否与片段管理器相关联,例如, AVFragmentedAssetMinder的一个实例。
    备注 支持片段管理的AVAssets仅在与片段管理器关联时发布更改通知。

    AVFragmentedAsset

    + (instancetype)fragmentedAssetWithURL:(NSURL *)URL options:(nullable NSDictionary<NSString *, id> *)options;
    
    函数名称 fragmentedAssetWithURL:options:
    解释 返回AVFragmentedAsset的实例,以检查碎片化的媒体资源。
    参数 URL:
    一个NSURL的实例,它用来引用媒体资源。

    options:
    一个NSDictionary的实例,包含用于指定AVFragmentedAsset初始化选项的键。请参阅上面的AVURLAssetPreferPreciseDurationAndTimingKeyAVURLAssetReferenceRestrictionsKey
    返回值 一个AVFragmentedAsset的实例。
    @property (nonatomic, readonly) NSArray<AVFragmentedAssetTrack *> *tracks;
    
    属性名称 tracks
    解释 asset中的track
    备注 此属性的值是asset包含的track数组;track的类型为AVFragmentedAssetTrack

    AVFragmentedAssetTrackInspection

    - (nullable AVFragmentedAssetTrack *)trackWithTrackID:(CMPersistentTrackID)trackID;
    
    函数名称 trackWithTrackID:
    解释 提供AVFragmentedAssetTrack的实例,该实例表示指定trackIDtrack
    参数 trackID:
    请求的AVFragmentedAssetTracktrackID
    返回值 AVFragmentedAssetTrack的一个实例;如果没有指定trackID的跟踪可用,则可以为nil
    备注 当加载了key``@“tracks”时,变为可调用而不会阻塞状态
    - (NSArray<AVFragmentedAssetTrack *> *)tracksWithMediaType:(AVMediaType)mediaType;
    
    函数名 tracksWithMediaType:
    解释 提供assetAVFragmentedAssetTracks数组,以呈现指定媒体类型的媒体。
    参数 mediaType:
    接收器过滤其AVFragmentedAssetTracks的媒体类型。 (媒体类型在AVMediaFormat.h中定义)
    返回值 AVFragmentedAssetTracksNSArray;如果没有指定媒体类型的曲目可用,则可能为nil
    备注 当加载了key``@“tracks”时,变为可调用而不会阻塞状态
    - (NSArray<AVFragmentedAssetTrack *> *)tracksWithMediaCharacteristic:(AVMediaCharacteristic)mediaCharacteristic;
    
    函数名 tracksWithMediaCharacteristic:
    解释 提供assetAVFragmentedAssetTracks数组,以呈现具有指定特征的媒体。
    参数 mediaCharacteristic:
    接收器过滤其AVFragmentedAssetTracks的媒体特性。 (媒体特征在AVMediaFormat.h中定义)
    返回值 AVFragmentedAssetTracksNSArray;如果没有具有指定特征的曲目可用,则可能为空。
    备注 当加载了key``@“tracks”时,变为可调用而不会阻塞状态

    AVFragmentedAssetMinder

    + (instancetype)fragmentedAssetMinderWithAsset:(AVAsset<AVFragmentMinding> *)asset mindingInterval:(NSTimeInterval)mindingInterval;
    
    函数名称 fragmentedAssetMinderWithAsset:mindingInterval:
    解释 创建AVFragmentedAssetMinder,将指定的asset添加到其中,并将mindingInterval设置为指定的值。
    参数 asset:
    要添加到AVFragmentedAssetMinderAVFragmentedAsset实例

    mindingInterval:
    AVFragmentedAssetMinder的初始调度间隔。
    返回值 返回一个AVFragmentedAssetMinder的新实例。
    - (instancetype)initWithAsset:(AVAsset<AVFragmentMinding> *)asset mindingInterval:(NSTimeInterval)mindingInterval;
    
    函数名称 initWithAsset:mindingInterval:
    解释 创建AVFragmentedAssetMinder,将指定的asset添加到其中,并将mindingInterval设置为指定的值。
    参数 asset:
    要添加到AVFragmentedAssetMinderAVFragmentedAsset实例

    mindingInterval:AVFragmentedAssetMinder的初始调度间隔。
    返回值 返回一个AVFragmentedAssetMinder的新实例。
    @property (nonatomic) NSTimeInterval mindingInterval;
    

    NSTimeInterval,指示应检查其他片段的频率。默认时间间隔为10.0

    @property (nonatomic, readonly) NSArray<AVAsset<AVFragmentMinding> *> *assets;
    

    成为minded AVFragmentedAsset对象的NSArray

    - (void)addFragmentedAsset:(AVAsset<AVFragmentMinding> *)asset;
    
    函数名称 addFragmentedAsset:
    解释 将碎片asset添加到正在构建的asset数组中。
    参数 asset:
    要添加到minder的碎片asset
    - (void)removeFragmentedAsset:(AVAsset<AVFragmentMinding> *)asset;
    
    函数名称 removeFragmentedAsset:
    解释 从成为mindedasset数组中删除碎片asset
    参数 asset:
    minder中删除的零碎asset

    AVURLAssetContentKeyEligibility

    @property (nonatomic, readonly) BOOL mayRequireContentKeysForMediaDataProcessing API_AVAILABLE(macos(10.12.4), ios(10.3), tvos(10.2), watchos(3.3));
    

    允许将AVURLAsset作为内容key recipient添加到AVContentKeySession

    上一章 目录 下一章

    相关文章

      网友评论

        本文标题:AVFoundation编程指南10-AVAsset解读(下)

        本文链接:https://www.haomeiwen.com/subject/fjvnaqtx.html