-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAVAsset+Convenience.h
83 lines (55 loc) · 3.58 KB
/
AVAsset+Convenience.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// AVAsset+Export.h
// Ringo
//
// Created by Alexander Ivanov on 15.02.15.
// Copyright (c) 2015 Alexander Ivanov. All rights reserved.
//
#import <AVFoundation/AVFoundation.h>
#if TARGET_OS_IPHONE
@import UIKit;
#else
@import AppKit;
#define UIImage NSImage
#endif
#define AVAudioSettingsLinearPCMMono @{ AVFormatIDKey : @(kAudioFormatLinearPCM), AVLinearPCMBitDepthKey : @(32), AVLinearPCMIsFloatKey : @YES, AVNumberOfChannelsKey : @(1) }
#define AVAudioSettingsLinearPCMStereo @{ AVFormatIDKey : @(kAudioFormatLinearPCM), AVLinearPCMBitDepthKey : @(32), AVLinearPCMIsFloatKey : @YES, AVNumberOfChannelsKey : @(2) }
#define AVAudioSettingsMPEG4AACMono @{ AVFormatIDKey : @(kAudioFormatMPEG4AAC), AVSampleRateKey : @(44100), AVNumberOfChannelsKey : @(1) }
#define AVAudioSettingsMPEG4AACStereo @{ AVFormatIDKey : @(kAudioFormatMPEG4AAC), AVSampleRateKey : @(44100), AVNumberOfChannelsKey : @(2) }
#define AVAudioSettingsMPEG4Layer3Mono @{ AVFormatIDKey : @(kAudioFormatMPEGLayer3), AVSampleRateKey : @(44100), AVNumberOfChannelsKey : @(1) }
#define AVAudioSettingsMPEG4Layer3Stereo @{ AVFormatIDKey : @(kAudioFormatMPEGLayer3), AVSampleRateKey : @(44100), AVNumberOfChannelsKey : @(2) }
#import "Dispatch+Convenience.h"
#import "NSObject+Convenience.h"
@interface AVAsset (Convenience)
@property (assign, nonatomic, readonly) NSTimeInterval seconds;
@property (strong, nonatomic, readonly) NSString *title;
@property (strong, nonatomic, readonly) NSString *album;
@property (strong, nonatomic, readonly) NSString *artist;
@property (strong, nonatomic, readonly) NSString *comment;
@property (strong, nonatomic, readonly) UIImage *artwork;
- (NSString *)metadataDescription;
- (AVAssetExportSession *)exportAudio:(CMTimeRange)timeRange metadata:(NSArray *)metadata to:(NSURL *)outputURL completion:(void (^)(void))handler;
- (AVAssetExportSession *)exportAudio:(CMTimeRange)timeRange to:(NSURL *)outputURL completion:(void (^)(void))handler;
- (AVAssetReader *)readWithSettings:(NSDictionary<NSString *, id> *)settings queue:(dispatch_queue_t)queue handler:(void (^)(NSData *data))handler;
- (AVAssetReader *)readWithSettings:(NSDictionary<NSString *, id> *)settings handler:(void (^)(NSData *data))handler;
- (AVAssetReader *)read:(void (^)(NSData *data))handler;
- (AVAssetWriter *)exportAudioWithSettings:(NSDictionary<NSString *, id> *)settings timeRange:(CMTimeRange)timeRange metadata:(NSArray *)metadata to:(NSURL *)outputURL handler:(void (^)(double progress))handler;
@property (assign, nonatomic, readonly) BOOL canRead;
@end
@interface AVAssetTrack (Convenience)
@property (assign, nonatomic, readonly) NSUInteger channelsPerFrame;
@end
@interface AVMetadataItem (Convenience)
+ (AVMutableMetadataItem *)metadataItemWithKey:(id <NSObject, NSCopying>)key value:(id <NSObject, NSCopying>)value;
@end
@interface AVAssetReader (Convenience)
+ (AVAssetReader *)assetReaderWithAsset:(AVAsset *)asset timeRange:(CMTimeRange)timeRange mediaType:(NSString *)mediaType settings:(NSDictionary<NSString *,id> *)settings;
@property (assign, nonatomic, readonly) BOOL canRead;
- (BOOL)startReadingOnQueue:(dispatch_queue_t)queue handler:(void (^)(void *, size_t))handler;
- (BOOL)startReading:(void (^)(void *, size_t))handler;
- (BOOL)startWriting:(AVAssetWriter *)writer queue:(dispatch_queue_t)queue handler:(void (^)(CMTime time))handler;
- (BOOL)startWriting:(AVAssetWriter *)writer handler:(void (^)(CMTime time))handler;
@end
@interface AVAssetWriter (Convenience)
+ (instancetype)assetWriterWithURL:(NSURL *)url fileType:(NSString *)fileType mediaType:(NSString *)mediaType settings:(NSDictionary<NSString *,id> *)settings;
@end