我能够成功地将 ffmpeg 编译并导入到我现有的 iOS 应用程序中。但是现在我想使用以下命令来剪辑和裁剪视频。如何与 iOS 中的 ffmpeg 库进行交互?
这个命令通过命令行对我说:
./ffmpeg -i input.mp4 -ss 157 -t 10 -vf crop=250:250:200:100 -strict -2 clipped.mp4
最佳答案
您可以使用 AVFoundation
修剪视频
AVAsset *anAsset = <#Get an asset#>;
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:anAsset presetName:AVAssetExportPresetLowQuality];
}
exportSession.outputURL = <#A file URL#>;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = CMTimeMakeWithSeconds(1.0, 600);
CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
break;
}
}];
引用:https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/01_UsingAssets.html
关于ios - ffmpeg如何从iOS执行命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32172374/