Tag: avassetexportsession

模拟AVLayerVideoGravityResizeAspectFill:裁剪和中心video模仿预览,而不会失去清晰度

基于这个SOpost ,下面的代码可以旋转,聚焦和剪切用户捕捉的video。 捕获会话使用AVCaptureSessionPresetHigh作为预设值,而预览层使用AVLayerVideoGravityResizeAspectFill作为video重力。 这个预览是非常尖锐的。 然而,导出的video并不那么清晰,表面上是因为从5S的后置摄像头的1920×1080分辨率到320×568(导出video的目标尺寸)的缩放会引起像素丢失的模糊现象? 假设没有办法从1920×1080缩放到320×568而没有模糊,问题就变成了:如何模仿预览图层的清晰度? 不知何故,苹果正在使用algorithm将1920x1080video转换成320×568的清晰预览帧。 有没有一种方法来模仿AVAssetWriter或AVAssetExportSession? func cropVideo() { // Set start time let startTime = NSDate().timeIntervalSince1970 // Create main composition & its tracks let mainComposition = AVMutableComposition() let compositionVideoTrack = mainComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID(kCMPersistentTrackID_Invalid)) let compositionAudioTrack = mainComposition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: CMPersistentTrackID(kCMPersistentTrackID_Invalid)) // Get source video & audio tracks let videoPath = getFilePath(curSlice!.getCaptureURL()) let videoURL […]

在iOS上导出video:了解和设置帧持续时间属性?

在本教程中,关于合并video,作者将导出video的帧持续时间设置为30 FPS。 1)不是将帧持续时间固定为30 FPS,帧持续时间不应该与video合并的帧持续时间相关联吗? 2)在导出video时,导出的video与源video不同,使用不同的FPS有什么优缺点? 这是以牺牲video质量为代价来加快出口时间的一种方式吗? 例如,如果教程中的源video是以24 FPS拍摄的呢? 我们需要在iOS上导出video,有时会合并多个video,有时会导出从相机设备捕获的单个video。

无法使用AVAssetExportSession修剪video

我想修剪video: -(void)trimVideo:(NSURL*)outputURL { //[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:outputURL options:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality]; NSString * outputFilePath = NSHomeDirectory(); outputFilePath = [outputFilePath stringByAppendingPathComponent:@"Library"]; outputFilePath = [outputFilePath stringByAppendingPathComponent:@"temp.mov"]; NSURL * outputFileUrl = [NSURL fileURLWithPath:outputFilePath]; exportSession.outputURL = outputFileUrl; exportSession.shouldOptimizeForNetworkUse = YES; exportSession.outputFileType = AVFileTypeMPEG4; CMTime start = CMTimeMakeWithSeconds(1.0, 600); CMTime duration […]

Swift – 压缩video文件

所以,目前我正在使用这个压缩video: func compressVideo(inputURL: NSURL, outputURL: NSURL, handler:(session: AVAssetExportSession)-> Void) { let urlAsset = AVURLAsset(URL: inputURL, options: nil) let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality) exportSession!.outputURL = outputURL exportSession!.outputFileType = AVFileTypeQuickTimeMovie exportSession!.shouldOptimizeForNetworkUse = true exportSession!.exportAsynchronouslyWithCompletionHandler { () -> Void in handler(session: exportSession!) } } 当我在2秒内录制video时,尺寸为4.3 MB ,当我在6秒内录制video时,文件大小为9.3 MB 。 任何提示,以减less大小?

AVAssetExportSession导出失败,带有错误:“操作已停止,NSLocalizedFailureReason =video无法合成。

我们将字幕添加到用户录制的video中,但是AVAssetExportSession对象的导出未能确定性地失败:有时会起作用,有时却不起作用。 目前还不清楚如何重现错误。 我们注意到资产追踪似乎在出口时丢失了。 在导出之前,如预期的那样有两个轨道(一个用于audio,一个用于video)。 但是检查exportDidFinish中相同文件URL的轨道数量显示0个轨道。 所以出口过程似乎有些问题。 更新:注释exporter.videoComposition = mutableComposition修复错误,但当然没有变换应用于video。 所以问题似乎在于创buildAVMutableVideoComposition ,导致在导出期间出现问题。 有关AVMutableVideoComposition文档和教程很less,所以即使您没有解决scheme,但可以推荐超出Apple的参考资源,这将是有帮助的。 错误: 错误域= AVFoundationErrorDomain代码= -11841“操作停止”UserInfo = 0x170676e80 {NSLocalizedDescription =操作停止,NSLocalizedFailureReason =video不能组成。 码: let videoAsset = AVURLAsset(URL: fileUrl, options: nil) let mixComposition = AVMutableComposition() let videoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, preferredTrackID: CMPersistentTrackID(kCMPersistentTrackID_Invalid)) let audioTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeAudio, preferredTrackID: CMPersistentTrackID(kCMPersistentTrackID_Invalid)) let sourceVideoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0] as! AVAssetTrack let sourceAudioTrack = videoAsset.tracksWithMediaType(AVMediaTypeAudio)[0] […]

AVMutableComposition – video资产之间的空白/黑框

我目前正在尝试使用AVMutableComposition将5个video背对背放置,如下所示: [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset1.duration) ofAsset:asset1 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration) ofAsset:asset2 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset3.duration) ofAsset:asset3 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset4.duration) ofAsset:asset4 atTime:[mixComposition duration] error:nil]; [mixComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset5.duration) ofAsset:asset5 atTime:[mixComposition duration] error:nil]; 然后,我使用AVAssetExportSession导出video,然而,每个video之间的工作,我得到一个空白/黑框,我需要删除。 有没有人有过这个问题,如果是你设法解决它? 另外,空白帧不在源video文件中。 提前致谢。

如何使用AVAssetWriter制作缩小尺寸的video?

我会制作缩小尺寸的video,可能是50像素和75像素的长度。 这些是物理层面。 你如何设定? 在video设置? 我认为AVVideoWidthKey和AVVideoHeightKey是更多的决议不是物理尺寸,我所需要的。 NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt: 320], AVVideoWidthKey, [NSNumber numberWithInt:480], AVVideoHeightKey, nil]; AVAssetWriterInput* writerInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain

ios 10中的AVAssetExportSession不适用于iPhone 7

当我在AVSsetExportSession中将两个video混合在ios 9中时,它的工作完美无缺。 但是当我在iOS 10的AVAssetExportSession混合,它不工作。 如果有任何知道的原因,请帮助我,谢谢。 真实的代码适用于iphone 6s和更早版本,但不适用于iPhone 7 例如 -(void) blendVideoOverVideo:(NSURL*)mainVideoUrl andBlendVideoUrl:(NSURL*)liveEffectUrl { AVURLAsset *mainVideoUrlAsset =[AVURLAsset URLAssetWithURL:mainVideoUrl options:nil]; // AVPlayerItem* mainVideoPlayerItem =[[AVPlayerItem alloc]initWithAsset:mainVideoUrlAsset]; AVAssetTrack* mainVideoTrack =[[mainVideoUrlAsset tracksWithMediaType:AVMediaTypeVideo]firstObject]; CGSize mainVideoSize = [mainVideoTrack naturalSize]; AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init]; AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:mainVideoUrl options:nil]; if(mainVideoUrl!=nil) { if([[audioAsset tracksWithMediaType:AVMediaTypeAudio] count]) { AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio […]

在后台启动AVAssetExportSession

我的应用程序做了一些处理,在某些时候需要调用一个AVAssetExportSession。 如果会话已经开始,然后我背景的应用程序,一切正常完成。 但是,如果我在调用exportAsynchronouslyWithCompletionHandler之前后台应用程序。 我得到这个错误: AVAssetExportSessionStatusFailed Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1e550db0 {NSLocalizedFailureReason=An unknown error occurred (-12985), NSUnderlyingError=0x1e574910 "The operation couldn‚Äôt be completed. (OSStatus error -12985.)", NSLocalizedDescription=The operation could not be completed} 是否有可能在后台启动AVAssetExportSession?