【问题标题】:where to save output of AVAssetWriter - iOS在哪里保存 AVAssetWriter 的输出 - iOS
【发布时间】:2014-12-25 10:27:26
【问题描述】:

我正在关注一些示例,说明如何在将视频上传到服务器之前压缩视频以减小文件大小。具体来说,我在这里看过这个问题:How can I reduce the file size of a video created with UIImagePickerController?

但是,我想知道保存输出的最佳位置在哪里。

即使是 AV 基础编程指南也仅提供此示例:

NSError *outError;
NSURL *outputURL = <#NSURL object representing the URL where you want to save the   video#>;
AVAssetWriter *assetWriter = [AVAssetWriter assetWriterWithURL:outputURL
                                                  fileType:AVFileTypeQuickTimeMovie
                                                     error:&outError];
BOOL success = (assetWriter != nil);

再次,寻找有关我要保存视频的确切位置的指导!

干杯, 布伦丹

【问题讨论】:

    标签: ios compression avfoundation video-capture avassetwriter


    【解决方案1】:

    这是文档目录 URL,只需附加您的文件名:

    [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    

    对所有其他人几乎相同:库 (NSLibraryDirectory)

    【讨论】:

      【解决方案2】:

      您可以使用以下代码在文档目录中写入文件

      文件目录路径

      NSString *DocumentsDirectoryPath() {NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentsDirectoryPath = [paths objectAtIndex:0];return documentsDirectoryPath;}
      

      然后

      NSURL * outputURL = [NSURL fileURLWithPath:[DocumentsDirectoryPath() stringByAppendingPathComponent:@"yourfilename.mp4"]];
      

      这里mp4 是您的文件扩展名。

      【讨论】:

        猜你喜欢
        • 2018-10-02
        • 2019-01-19
        • 1970-01-01
        • 2012-03-18
        • 1970-01-01
        • 1970-01-01
        • 2011-08-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多