【问题标题】:ffmpeg how to to execute command from iOS?ffmpeg如何从iOS执行命令?
【发布时间】:2015-08-23 23:01:27
【问题描述】:

我能够成功地将 ffmpeg 编译并导入到我现有的 iOS 应用程序中。但是现在我想使用以下命令来剪辑和裁剪视频。如何与 iOS 中的 ffmpeg 库进行交互?

这个命令通过命令行告诉我:

./ffmpeg -i input.mp4 -ss 157 -t 10 -vf crop=250:250:200:100 -strict -2 clipped.mp4

【问题讨论】:

  • 你找到与此相关的东西了吗?

标签: ios video ios8 ffmpeg


【解决方案1】:

您可以使用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

【讨论】:

  • 我想专门使用 ffmpeg,因为除了修剪之外,我还在用视频做很多事情。我需要裁剪、修剪并稍后转换视频格式。
【解决方案2】:

您可能已经知道这一点,但您可以直接在 iOS 中使用 ffmpeg 库,而不是命令行格式 - 下面的答案似乎是一种被广泛接受的方法:

假设这不是您想要的,而您实际上希望它使用 ffmpeg '包装器',那么 GitHub 上有一些可用的。我个人没有使用过这些,尽管我在 Android 上使用过相同的技术并且效果很好,只要您记得您使用的程序最初设计为独立的命令行调用并进行彻底测试:

【讨论】:

  • 找不到错误“libavformat/avformat.h”文件。是否需要添加任何其他库?
  • @VineeshTP 您需要在构建设置中指定健康路径并替换 ffmpeg-ios。
猜你喜欢
  • 2013-01-14
  • 1970-01-01
  • 2020-10-11
  • 1970-01-01
  • 1970-01-01
  • 2014-11-15
  • 2013-08-14
  • 2019-06-21
  • 2019-11-03
相关资源
最近更新 更多