| FFmpegKit iOS / macOS / tvOS API 4.5

MediaInformationJsonParser.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 "MediaInformationJsonParser.h"
21
22@implementation MediaInformationJsonParser
23
24+ (MediaInformation*)from:(NSString*)ffprobeJsonOutput {
25 NSError *error;
26
27 MediaInformation* mediaInformation = [self from: ffprobeJsonOutput with: error];
28
29 if (error != nil) {
30 NSLog(@"MediaInformation parsing failed: %@.\n", error);
31 }
32
33 return mediaInformation;
34}
35
36+ (MediaInformation*)from:(NSString*)ffprobeJsonOutput with:(NSError*)error {
37 NSData *jsonData = [ffprobeJsonOutput dataUsingEncoding:NSUTF8StringEncoding];
38 NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
39 if (error != nil || jsonDictionary == nil) {
40 return nil;
41 }
42
43 NSArray* array = [jsonDictionary objectForKey:@"streams"];
44 NSMutableArray *streamArray = [[NSMutableArray alloc] init];
45 for(int i = 0; i<array.count; i++) {
46 NSDictionary *streamDictionary = [array objectAtIndex:i];
47 [streamArray addObject:[[StreamInformation alloc] init: streamDictionary]];
48 }
49
50 return [[MediaInformation alloc] init:jsonDictionary withStreams:streamArray];
51}
52
53@end
streamArray
NSArray * streamArray
Definition: MediaInformation.m:32
MediaInformationJsonParser.h
MediaInformation
Definition: MediaInformation.h:40
MediaInformationJsonParser
Definition: MediaInformationJsonParser.h:30
+[MediaInformationJsonParser from:with:]
MediaInformation * from:with:(NSString *ffprobeJsonOutput,[with] NSError *error)
Definition: MediaInformationJsonParser.m:36
StreamInformation
Definition: StreamInformation.h:48