ios – AVAssetExportSession修剪和下载

ios – AVAssetExportSession修剪和下载,第1张

概述我正在尝试使用AVExportSession修剪下载在线视频. 码: FileMove *fileMove = (FileMove*)data; NSString *url = @"http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4" 我正在尝试使用AVExportSession修剪和下载在线视频.

码:

fileMove *fileMove = (fileMove*)data;  Nsstring *url = @"http://download.wavetlan.com/SVV/Media/http/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4";    NSURL *vIDeoURL = [NSURL URLWithString:[url stringByAddingPercentEscapesUsingEnCoding:NSUTF8StringEnCoding]];    NSLog(@"VIDeoURL: %@",vIDeoURL);    AVAsset *anAsset = [AVURLAsset URLAssetWithURL:vIDeoURL options:nil];        NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];    if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality]) {        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]                                               initWithAsset:anAsset presetname:AVAssetExportPresetLowQuality];        NSURL *outputURL = [NSURL fileURLWithPath:fileMove.dst];        NSLog(@"outputURL: %@",outputURL);        exportSession.outputURL = outputURL;        exportSession.outputfileType = AVfileTypeQuickTimeMovIE;        CMTime start = CMTimeMakeWithSeconds(1.0,600);        CMTime duration = CMTimeMakeWithSeconds(3.0,600);        CMTimeRange range = CMTimeRangeMake(start,duration);        exportSession.timeRange = range;        if ([[NSfileManager defaultManager] fileExistsAtPath:fileMove.dst])            [[NSfileManager defaultManager] removeItemAtPath:fileMove.dst error:nil];        [exportSession exportAsynchronouslyWithCompletionHandler:^{            switch ([exportSession status]) {                case AVAssetExportSessionStatusFailed:                    NSLog(@"Export Failed: %@",[[exportSession error]description ]);                    break;                case AVAssetExportSessionStatusCancelled:                    NSLog(@"Export canceled");                    break;                default:                    break;            }        }];    }

错误:

Export Failed: Error Domain=AVFoundationErrorDomain Code=-11800 “The
operation Could not be completed” UserInfo=0x635a820
{NSLocalizedDescription=The operation Could not be completed,
NSUnderlyingError=0x1ff4240 “The operation Couldn’t be completed.
(Osstatus error -12780.)”,NSLocalizedFailureReason=An unkNown error
occurred (-12780)}

你们看到代码中有任何问题吗? AVExportSession访问在线视频有任何限制吗?

解决方法 我已经设法使用AVFoundation修剪远程视频.这是用Swift编写的示例代码:

let range: CMTimeRangelet sourceURL: NSURLlet targetfileURL: NSURLlet requiredKeys = [ "exportable","tracks" ]let asset = AVAsset(URL: sourceURL)asset.loadValuesAsynchronouslyForKeys(requiredKeys) {    // Error handling code here    precondition(asset.statusOfValueForKey("exportable",error: nil) == .Loaded)    precondition(asset.statusOfValueForKey("tracks",error: nil) == .Loaded)    precondition(asset.exportable)    let composition = AVMutableComposition()    do {        try composition.insertTimeRange(range,ofAsset: asset,atTime: kCMTimeZero)    } catch {        // Error handling code here        return    }    let finalComposition = composition.copy() as! AVComposition    guard let export = AVAssetExportSession(asset: finalComposition,presetname: AVAssetExportPresetPassthrough) else {        // Error handling code here        return    }    export.outputURL = targetfileURL    export.outputfileType = AVfileTypeMPEG4    export.exportAsynchronouslyWithCompletionHandler {        switch export.status {        case .Completed:            // Alright!            break        case .Cancelled,.Failed:            // Error handling code here            break        default:            fatalError("Shouldn't be called")        }    }}
总结

以上是内存溢出为你收集整理的ios – AVAssetExportSession修剪和下载全部内容,希望文章能够帮你解决ios – AVAssetExportSession修剪和下载所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1046553.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存