【发布时间】:2023-04-08 09:29:02
【问题描述】:
工作区:iOS 13.0、Xcode 11.0
TL;DR:iOS 13 中的 AVAssetReferenceRestrictions 有问题吗?
第 1 部分:
在AVAsset.h 中,AVAssetReferenceRestrictions 定义为:
@enum AVAssetReferenceRestrictions
@abstract These constants can be passed in to AVURLAssetReferenceRestrictionsKey to control the resolution of references to external media data.
@constant AVAssetReferenceRestrictionForbidNone
Indicates that all types of references should be followed.
@constant AVAssetReferenceRestrictionForbidRemoteReferenceToLocal
Indicates that references from a remote asset (e.g. referenced via http URL) to local media data (e.g. stored in a local file) should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToRemote
Indicates that references from a local asset to remote media data should not be followed.
@constant AVAssetReferenceRestrictionForbidCrossSiteReference
Indicates that references from a remote asset to remote media data stored at a different site should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToLocal
Indicates that references from a local asset to local media data stored outside the asset's container file should not be followed.
@constant AVAssetReferenceRestrictionForbidAll
Indicates that only references to media data stored within the asset's container file should be allowed.
*/
typedef NS_OPTIONS(NSUInteger, AVAssetReferenceRestrictions) {
AVAssetReferenceRestrictionForbidNone = 0UL,
AVAssetReferenceRestrictionForbidRemoteReferenceToLocal = (1UL << 0),
AVAssetReferenceRestrictionForbidLocalReferenceToRemote = (1UL << 1),
AVAssetReferenceRestrictionForbidCrossSiteReference = (1UL << 2),
AVAssetReferenceRestrictionForbidLocalReferenceToLocal = (1UL << 3),
AVAssetReferenceRestrictionForbidAll = 0xFFFFUL,
AVAssetReferenceRestrictionDefaultPolicy = AVAssetReferenceRestrictionForbidLocalReferenceToRemote
};
而AVAsset的属性定义为:
@property referenceRestrictions
@abstract Indicates the reference restrictions being used by the receiver.
@discussion
For AVURLAsset, this property reflects the value passed in for AVURLAssetReferenceRestrictionsKey, if any. See AVURLAssetReferenceRestrictionsKey below for a full discussion of reference restrictions. The default value for this property is AVAssetReferenceRestrictionForbidNone.
@property (nonatomic, readonly) AVAssetReferenceRestrictions referenceRestrictions API_AVAILABLE(macos(10.7), ios(5.0), tvos(9.0)) API_UNAVAILABLE(watchos);
因此,尽管该属性的文档明确指出默认值为AVAssetReferenceRestrictionForbidNone,但AVAssetReferenceRestrictionDefaultPolicy 当前为AVAssetReferenceRestrictionForbidLocalReferenceToRemote。是文档没有正确更新,还是 AVAssetReferenceRestrictionDefaultPolicy 与我预期的不同?
第 2 部分:
在对应的 Swift 中,它是这样定义(转换的?):
@enum AVAssetReferenceRestrictions
@abstract These constants can be passed in to AVURLAssetReferenceRestrictionsKey to control the resolution of references to external media data.
@constant AVAssetReferenceRestrictionForbidNone
Indicates that all types of references should be followed.
@constant AVAssetReferenceRestrictionForbidRemoteReferenceToLocal
Indicates that references from a remote asset (e.g. referenced via http URL) to local media data (e.g. stored in a local file) should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToRemote
Indicates that references from a local asset to remote media data should not be followed.
@constant AVAssetReferenceRestrictionForbidCrossSiteReference
Indicates that references from a remote asset to remote media data stored at a different site should not be followed.
@constant AVAssetReferenceRestrictionForbidLocalReferenceToLocal
Indicates that references from a local asset to local media data stored outside the asset's container file should not be followed.
@constant AVAssetReferenceRestrictionForbidAll
Indicates that only references to media data stored within the asset's container file should be allowed.
public struct AVAssetReferenceRestrictions : OptionSet {
public init(rawValue: UInt)
public static var forbidRemoteReferenceToLocal: AVAssetReferenceRestrictions { get }
public static var forbidLocalReferenceToRemote: AVAssetReferenceRestrictions { get }
public static var forbidCrossSiteReference: AVAssetReferenceRestrictions { get }
public static var forbidLocalReferenceToLocal: AVAssetReferenceRestrictions { get }
public static var forbidAll: AVAssetReferenceRestrictions { get }
public static var defaultPolicy: AVAssetReferenceRestrictions { get }
}
这里没有AVAssetReferenceRestrictionForbidNone 的选项。但是文档明确表示确实如此。那么,到底是谁的错,还是我的误解?
第 3 部分:我是如何在这里结束的?
我不得不检查这些 因为我们能够从
UIImagePickerController中选择一个视频, 然后以AVURLAsset形式导出它以使用AVAssetExportSession。 一切都很好,直到 iOS 13.0 都可以无缝运行。该功能适用于 iOS 12.4.1 及更低版本的设备。AVAssetReferenceRestrictions 的用法是在初始化器中
AVURLAsset,我相信默认值已经改变了 不允许我们再导出。
【问题讨论】:
标签: ios swift ios13 avassetexportsession