带有和没有断点的AVAssetExportSession [英] AVAssetExportSession with and without break points

查看:105
本文介绍了带有和没有断点的AVAssetExportSession的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有低质量转换的简单视频压缩代码。我正在使用IOS-4.2.1在iphone 4中测试我的代码。问题是当我在没有断点的设备上测试我的代码时代码无法创建视频(它只创建一个零kb文件或空文件)但是当我逐行使用断点检查这段代码时,它会生成一个完美的压缩视频,也可以在mac中的quicktime播放器上运行。压缩后我制作了这个视频文件的zip。

I have simple video compression code in low quality conversion.I am testing my code in iphone 4 with IOS-4.2.1.The problem is when I test my code on device without break points the code failed to create video(it just a zero kb file or empty file created) but when I use breakpoint checking line by line this code slowly it will make a perfect compressed video which also runs on quicktime player in mac.After compression I make zip of this video file.

NSURL *videoURL=[[self.videourlarray objectAtIndex:i] valueForKey:UIImagePickerControllerReferenceURL];
        NSURL *outputURL = [NSURL fileURLWithPath:videoFile];

        [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
        AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
        exportSession.outputURL = outputURL;
        exportSession.shouldOptimizeForNetworkUse = YES;
        exportSession.outputFileType = AVFileTypeQuickTimeMovie;
        [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
         {
             NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
             [exportSession release];
         }];

thanx任何帮助......

thanx for any help...

推荐答案

我认为你需要确保你没有弄乱线程..(AVFoundation指南说导出器不能保证在任何特定线程上运行)。

I think you need to make sure you're not messing with the threads.. (AVFoundation guide says that the exporter is not guaranteed to run on any particular thread).

使用这样的块。

    [exportSession exportAsynchronouslyWithCompletionHandler:^(void) 
    {
    dispatch_async(dispatch_get_main_queue(), ^{
         NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
            });

     }];

我个人会从块中调用一个委托,但我认为你的简单日志声明就是为了这个例如,您已经知道:)

I would personally call a delegate from the block, but I presume your simple log statement is just for this example and you already know that :)

这篇关于带有和没有断点的AVAssetExportSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆