【问题标题】:How to compress video using AVFoundation in iOS [closed]如何在 iOS 中使用 AVFoundation 压缩视频 [关闭]
【发布时间】:2012-01-13 13:29:44
【问题描述】:

iPhone 中是否有任何压缩技术可以使用 AVfoundation 压缩视频。或任何开源。

问候, 吉瓦

【问题讨论】:

标签: ios cocoa-touch avfoundation


【解决方案1】:

试试这个:)

+ (void)convertVideoToLowQualityWithInputURL:(NSURL*)inputURL outputURL:(NSURL*)outputURL successHandler:(void (^)())successHandler failureHandler:(void (^)(NSError *))failureHandler
{
    if([[NSFileManager defaultManager] fileExistsAtURL:outputURL]) [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
    exportSession.outputURL = outputURL;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    [exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
        if (exportSession.status == AVAssetExportSessionStatusCompleted)
        {
            successHandler();
        }
        else
        {
            NSError *error = [NSError errorWithDomain:domain code:code userInfo:userInfo]; 
            failureHandler(error); 
        }
     }];
}

【讨论】:

  • 我有点困惑,为什么整个事情都是一个大故障处理程序。
  • 特里斯坦先生,你是什么意思?
  • 我猜绝对没有。对不起,复杂的方法签名让我有点困惑。我以为我正在查看最后一个块,这里的所有代码都是那个“故障处理程序块”的一部分。对我的误解。 :-)
  • 您好,使用上述代码后,视频文件压缩前后的文件大小保持不变。
  • SK 是正确的。 NSData 中的字节数在此方法前后保持不变。
【解决方案2】:

这是 Apple 提供的使用 AVFoundation 录制的最佳示例

您可以自定义设置(尺寸/FPS/比特率)。

https://developer.apple.com/library/ios/#samplecode/RosyWriter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011110

希望对你有帮助

【讨论】:

    【解决方案3】:

    是的,它被称为AVAssetWriter。到处找例子,在这里给出一个连贯的工作代码作为答案太复杂了。

    【讨论】:

    • “这里”是人们寻求答案的地方。
    • @mpemburn 是的,回答“真正的问题”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多