简体   繁体   English

在哪里保存AVAssetWriter的输出-iOS

[英]where to save output of AVAssetWriter - iOS

I'm following some examples of how to compress a video to reduce file size prior to uploading it to a server. 我正在跟踪一些有关如何在将视频上传到服务器之前压缩视频以减小文件大小的示例。 Specifically, I've looked at this question here: How can I reduce the file size of a video created with UIImagePickerController? 具体来说,我在这里查看了这个问题: 如何减少使用UIImagePickerController创建的视频的文件大小?

However, I'm wondering where the best place to save the output is. 但是,我想知道保存输出的最佳位置在哪里。

Even the AV foundation programming guide only provides this as an example: 甚至AV Foundation编程指南也仅提供以下示例:

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);

Again, looking for some guidance on exactly where it is I want to save the video! 再次,寻找有关我要保存视频的确切位置的指导!

Cheers, Brendan 干杯,布伦丹

This is documents directory URL, just append your filename: 这是文档目录URL,只需附加您的文件名:

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

Almost the same for all others: library ( NSLibraryDirectory ) 所有其他几乎相同:库( NSLibraryDirectory

You can write file in document directory using below code 您可以使用以下代码将文件写入文档目录

defile document directory path 删除文件目录路径

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

and then 接着

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

here mp4 is your file extention. mp4是您的文件扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM