ios - ffmpeg如何从iOS执行命令?

标签 ios video ios8 ffmpeg

我能够成功地将 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/

相关文章:

ios - 我的计算属性和结构

c - 如何对音频流使用混合和连接过滤器?

android - 如何查找和播放通过 Lynda.com Android 或 Windows 应用程序下载的视频

audio - 从视频制作音频播客的服务?

exception - libc++abi.dylib : terminate_handler unexpectedly threw an exception - 0 stack trace iOS7/iOS 8

ios - unity IOS firebase 处理前台推送通知

ios - 上传的 IPA 不会出现在 iOS 8 Test Flight 应用程序中。他们改变程序了吗?

swift - 在用户关闭应用程序后请求 HealthKit 权限

ios7 - #ifdef __IPHONE_8_0代码也可在iOS 7上运行

android - 验证点击某些东西是否会让你退出 appium 中的应用程序