FFmpegKit iOS / macOS / tvOS API 4.5
MediaInformation.m
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018-2021 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#import "MediaInformation.h"
21
22NSString* const MediaKeyMediaProperties = @"format";
23NSString* const MediaKeyFilename = @"filename";
24NSString* const MediaKeyFormat = @"format_name";
25NSString* const MediaKeyFormatLong = @"format_long_name";
26NSString* const MediaKeyStartTime = @"start_time";
27NSString* const MediaKeyDuration = @"duration";
28NSString* const MediaKeySize = @"size";
29NSString* const MediaKeyBitRate = @"bit_rate";
30NSString* const MediaKeyTags = @"tags";
31
32@implementation MediaInformation {
33
37 NSDictionary *dictionary;
38
42 NSArray *streamArray;
43
44}
45
46- (instancetype)init:(NSDictionary*)mediaDictionary withStreams:(NSArray*)streams{
47 self = [super init];
48 if (self) {
49 dictionary = mediaDictionary;
50 streamArray = streams;
51 }
52
53 return self;
54}
55
56- (NSString*)getFilename {
57 return [self getStringProperty:MediaKeyFilename];
58}
59
60- (NSString*)getFormat {
61 return [self getStringProperty:MediaKeyFormat];
62}
63
64- (NSString*)getLongFormat {
65 return [self getStringProperty:MediaKeyFormatLong];
66}
67
68- (NSString*)getStartTime {
69 return [self getStringProperty:MediaKeyStartTime];
70}
71
72- (NSString*)getDuration {
73 return [self getStringProperty:MediaKeyDuration];
74}
75
76- (NSString*)getSize {
77 return [self getStringProperty:MediaKeySize];
78}
79
80- (NSString*)getBitrate {
81 return [self getStringProperty:MediaKeyBitRate];
82}
83
84- (NSDictionary*)getTags {
85 return [self getProperties:MediaKeyTags];
86}
87
88- (NSArray*)getStreams {
89 return streamArray;
90}
91
92- (NSString*)getStringProperty:(NSString*)key {
93 NSDictionary* mediaProperties = [self getMediaProperties];
94 if (mediaProperties == nil) {
95 return nil;
96 }
97
98 return mediaProperties[key];
99}
100
101- (NSNumber*)getNumberProperty:(NSString*)key {
102 NSDictionary* mediaProperties = [self getMediaProperties];
103 if (mediaProperties == nil) {
104 return nil;
105 }
106
107 return mediaProperties[key];
108}
109
110- (NSDictionary*)getProperties:(NSString*)key {
111 NSDictionary* mediaProperties = [self getMediaProperties];
112 if (mediaProperties == nil) {
113 return nil;
114 }
115
116 return mediaProperties[key];
117}
118
119- (NSDictionary*)getMediaProperties {
120 return dictionary[MediaKeyMediaProperties];
121}
122
123- (NSDictionary*)getAllProperties {
124 return dictionary;
125}
126
127@end
NSString *const MediaKeyBitRate
NSString *const MediaKeyDuration
NSArray * streamArray
NSString *const MediaKeyTags
NSString *const MediaKeyFormat
NSString *const MediaKeyFormatLong
NSString *const MediaKeyStartTime
NSString *const MediaKeySize
NSString *const MediaKeyFilename
NSString *const MediaKeyMediaProperties