gpt4 book ai didi

ios - AVAssetExportSession - 导出的视频与相机胶卷不兼容

转载 作者:行者123 更新时间:2023-11-28 08:39:19 26 4
gpt4 key购买 nike

我有一个错误和一个问题。我想将修改后的视频导出到相机胶卷,但导出的视频与相机胶卷不兼容。

我也想删除最初录制的视频,以便我可以录制不止一次,但它会产生错误并且没有意义。如果我取消注释代码,则会出现错误,告诉我最终路径不存在。我假设这会在导出修改版本之前删除初始电影。但我不明白为什么会发生这种情况,因为删除代码低于导出代码。

代码如下:

    // Create Date Formatter
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd-hh-mm-ss"

// Create Export Session
let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality)
exportSession?.videoComposition = videoComposition
do {
try exportSession?.outputURL = NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true).URLByAppendingPathComponent(dateFormatter.stringFromDate(NSDate())).URLByAppendingPathExtension("mov")
}
catch {
print(error)
}
exportSession?.outputFileType = AVFileTypeQuickTimeMovie
exportSession?.exportAsynchronouslyWithCompletionHandler({
print("Output File Type: \(exportSession?.outputFileType)")
print("Output URL: \(exportSession?.outputURL?.absoluteString)")
print("Video Compatible W/ Camera Roll: \(exportSession?.asset.compatibleWithSavedPhotosAlbum)")
//-----SAVE-----
if exportSession?.status == AVAssetExportSessionStatus.Completed
{
print("Export Finished")
if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum((exportSession?.outputURL?.absoluteString)!) //Returns false...
{
UISaveVideoAtPathToSavedPhotosAlbum((exportSession?.outputURL?.absoluteString)!, self, nil, nil)
print("Video Saved")
// Show Message
self.showMessage()
}
else
{
print("Video Not Saved")
}
}
else if exportSession?.status == AVAssetExportSessionStatus.Failed
{
print("Export Error: \(exportSession?.error)")
print("Export Failed")
}
else
{
print("Export Cancelled")
}
})

// The code below generates an error
// Remove Temporary Video
// do
// {
// try NSFileManager.defaultManager().removeItemAtURL(initialOutputURL)
// }
// catch
// {
// print(error)
// }

那么不兼容是从哪里来的呢?我要注意日志显示的是 QuickTime 格式和 720x720 分辨率。

最佳答案

好吧,所以我最终找到了答案......这也没有多大意义。也许它会帮助遇到这个问题的其他人。

因此,删除初始视频的代码必须放在 exportAsynchronouslyWithCompletionHandler内部,而不是之后。

为了保存视频,我刚刚使用了 ALAssetLibrary.videoAtPathIsCompatibleWithSavedPhotosAlbum.writeVideoAtPathToSavedPhotosAlbum。我知道它已被弃用,但我也希望与 iOS 7 兼容。如果您需要 iOS 8 及更高版本,请使用 PHPhotoLibrary。这很奇怪,因为我的初始代码和 ALAssetLibrary 版本都做完全相同的事情。另外,有趣的是,日志仍然显示视频与相机胶卷不兼容。

最后的修复是在旋转视频时使用 CGFloat(M_PI_2) 而不是 90

关于ios - AVAssetExportSession - 导出的视频与相机胶卷不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36809115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com