VapxMp4Editor.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Tencent is pleased to support the open source community by making vap available.
  2. //
  3. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the MIT License (the "License"); you may not use this file except in
  6. // compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://opensource.org/licenses/MIT
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License is
  11. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12. // either express or implied. See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "VapxMp4Editor.h"
  15. @implementation VapxMp4Editor
  16. - (NSString *)mp4ByInsertAtom:(NSString *)atomPath atIndex:(NSInteger)index {
  17. NSFileManager *fileManager = [NSFileManager defaultManager];
  18. if (self.inputPath.length == 0 || ![fileManager fileExistsAtPath:self.inputPath]) {
  19. return nil;
  20. }
  21. NSString *ffmpegPath = [[NSBundle mainBundle] pathForResource:@"mp4edit" ofType:@""];
  22. NSString *output = self.outputPath;
  23. NSArray *arguments = @[@"--insert", [NSString stringWithFormat:@":%@:%@", atomPath, @(index)], self.inputPath, output];
  24. NSPipe *pipe = [NSPipe pipe];
  25. NSFileHandle * read = [pipe fileHandleForReading];
  26. NSTask *task = [[NSTask alloc] init];
  27. [task setLaunchPath: ffmpegPath];
  28. [task setArguments: arguments];
  29. [task setStandardOutput: pipe];
  30. [task launch];
  31. [task waitUntilExit];
  32. NSData* data = [read readDataToEndOfFile];
  33. NSString* stringOutput = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  34. NSLog(@"stringOutput:%@, terminationStatus:%i",stringOutput, [task terminationStatus]);
  35. return output;
  36. }
  37. @end