我已经查看了我可以找到的用于设置元数据的每个示例AVAssetExportSession,但即使音频导出工作正常(结果音频文件播放正常),仍然没有随文件导出的元数据.我正在使用Xcode 4.5,目标构建iOS 5,测试设备iOS 6.请看下面我正在使用的代码,请让我知道我做错了什么.
头
// for metadata export
NSArray *MyMetadata;
AVMutableMetadataItem *common1;
AVMutableMetadataItem *common2;
AVMutableMetadataItem *common3;
AVMutableMetadataItem *common4;
Run Code Online (Sandbox Code Playgroud)
履行
AVAsset *asset = [AVAsset assetWithURL:audioFileInput];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetPassthrough];
if (!exportSession) {
return;
}
CMTime startTime = CMTimeMake((int)(floor(fileStartMarker * 100)), 100);
CMTime stopTime = CMTimeMake((int)(ceil(fileEndMarker * 100)), 100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime);
exportSession.outputURL = audioFileOutput;
exportSession.outputFileType = @"com.apple.coreaudio-format";
exportSession.timeRange = exportTimeRange;
// define meta data for file
// Common metadata
common1 = [[AVMutableMetadataItem alloc] init]; …Run Code Online (Sandbox Code Playgroud) 我有一个将应用程序导出AVMutableComposition到.mov文件中的应用程序,我希望用户使用进度条查看导出状态的方式与发送文本消息或上传文件时的方式相同.
我知道如何在知道任务的持续时间(例如播放音频文件)时创建进度条,但由于导出没有设定的持续时间,我不确定如何继续.
我目前有一个活动指示器,但它没有提供最佳的用户体验.
有没有人有任何指针?
我们为用户录制的视频添加了字幕,但AVAssetExportSession对象的导出失败是非确定性的:有时它会起作用,有时它不起作用.目前还不清楚如何重现错误.
我们注意到出口期间资产跟踪似乎丢失了.
在导出之前,有两个轨道(一个用于音频,一个用于视频),如预期的那样.但是在exportDidFinish显示0个曲目中检查相同文件URL的曲目数.所以出口过程似乎有些问题.
更新:注释会exporter.videoComposition = mutableComposition修复错误,但当然不会对视频应用任何转换.所以问题似乎在于创造AVMutableVideoComposition,这会在出口期间导致下游问题.文档和教程AVMutableVideoComposition很少,所以即使您没有解决方案但可以推荐Apple以外的参考资料,这将有所帮助.
错误:
Error Domain = AVFoundationErrorDomain Code = -11841"Operation Stopped"UserInfo = 0x170676e80 {NSLocalizedDescription = Operation Stopped,NSLocalizedFailureReason =视频无法合成.}
码:
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] as! AVAssetTrack
videoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), ofTrack: sourceVideoTrack, atTime: kCMTimeZero, error: nil)
audioTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), ofTrack: sourceAudioTrack, atTime: kCMTimeZero, …Run Code Online (Sandbox Code Playgroud) 下面的代码生成此错误(附加到exporters):
致命错误:UnsafeMutablePointer.deinitialize with negative count
var exporters = [AVAssetExportSession]()
let exporter = AVAssetExportSession(asset: mainComposition, presetName: AVAssetExportPresetHighestQuality)!
exporter.videoComposition = videoComposition
exporter.outputFileType = AVFileTypeMPEG4
exporter.outputURL = exportURL
exporter.shouldOptimizeForNetworkUse = true
exporters.append(exporter)
Run Code Online (Sandbox Code Playgroud)
StackOverflow上的其他帖子对UnsafeMutablePointer.deinitialize这个问题没有太多了解,这不会一直发生.
有任何想法吗?
我遇到AVAssetExportSession的问题,其中进度停止增加但状态仍然表示它正在导出.这实际上是一种非常罕见的情况,它在99.99%的时间内完美无瑕地运行,但无论如何我想解决这个问题.
所以我开始出口:
exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetMediumQuality];
exportSession.videoComposition = videoComposition;
exportSession.outputFileType = @"com.apple.quicktime-movie";
exportSession.outputURL = outputURL;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
...
}];
Run Code Online (Sandbox Code Playgroud)
然后有一个计时器检查进度:
AVAssetExportSessionStatus status = [exportSession status];
float progress = 0;
if (status == AVAssetExportSessionStatusExporting) {
progress = [exportSession progress];
} else if (status == AVAssetExportSessionStatusCompleted) {
progress = 1;
}
NSLog(@"%d %f", status, progress);
[delegate processor:self didProgress:progress];
Run Code Online (Sandbox Code Playgroud)
输出最终看起来像:
2012-05-23 14:28:59.494 **********[1899:707] 2 0.125991
2012-05-23 14:28:59.994 **********[1899:707] 2 0.185280
2012-05-23 14:29:00.494 **********[1899:707] 2 0.259393
2012-05-23 14:29:00.994 **********[1899:707] 2 0.326093
2012-05-23 …Run Code Online (Sandbox Code Playgroud) 我试图从iPod-Library导出音频文件.我的目标是使用此iPod-Library文件在应用程序文档文件夹中创建新文件.它无法仅为某些项目创建文件.以下是我的代码段.
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL: url options:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
AVAssetExportSession *exporter = [[AVAssetExportSession alloc]
initWithAsset: songAsset
presetName: AVAssetExportPresetAppleM4A];
exporter.outputFileType = @"com.apple.m4a-audio";
NSString *songName = [filename stringByAppendingString:@".m4a"];
NSString *musicfilepath = [documentsDirectory stringByAppendingPathComponent:@"musics/"];
[[NSFileManager defaultManager] createDirectoryAtPath:musicfilepath withIntermediateDirectories:YES attributes:nil error:nil];
NSString *exportFile = [musicfilepath stringByAppendingPathComponent:songName];
NSError *error1;
if([[NSFileManager defaultManager] fileExistsAtPath:exportFile])
{
[[NSFileManager defaultManager] removeItemAtPath:exportFile error:&error1];
}
NSURL* exportURL = [[NSURL fileURLWithPath:exportFile] retain];
exporter.outputURL = exportURL;
Run Code Online (Sandbox Code Playgroud)
尝试使用错误处理程序块时,如下所示出现错误:
[exporter exportAsynchronouslyWithCompletionHandler:^{
int exportStatus = exporter.status;
switch …Run Code Online (Sandbox Code Playgroud) 我正在尝试将CIFilter应用于AVAsset,然后在应用过滤器的情况下保存它.我这样做的方法是使用AVAssetExportSessionwith videoCompositionset设置为AVMutableVideoComposition具有自定义AVVideoCompositing类的对象.
我还将instructions我的AVMutableVideoComposition对象设置为自定义组合指令类(符合AVMutableVideoCompositionInstruction).这个类传递了一个跟踪ID,以及一些其他不重要的变量.
不幸的是,我遇到了一个问题 - startVideoCompositionRequest:我的自定义视频合成器类(符合AVVideoCompositing)中的函数没有被正确调用.
当我将passthroughTrackID自定义指令类的变量设置为轨道ID时,startVideoCompositionRequest(request)我的函数AVVideoCompositing不会被调用.
然而,当我没有设置passthroughTrackID我的自定义指令类的变量,将startVideoCompositionRequest(request) 被调用,但没有正确-打印request.sourceTrackIDs结果空数组,并request.sourceFrameByTrackID(trackID)导致零值.
我发现有趣的是,cancelAllPendingVideoCompositionRequests:在尝试使用过滤器导出视频时,该函数总是被调用两次.startVideoCompositionRequest:在startVideoCompositionRequest:未调用的情况下,它要么被调用一次,要么被调用一次,或者连续两次被调用.
我创建了三个用于导出带过滤器的视频的类.这是实用程序类,它基本上只包含一个export函数并调用所有必需的代码
class VideoFilterExport{
let asset: AVAsset
init(asset: AVAsset){
self.asset = asset
}
func export(toURL url: NSURL, callback: (url: NSURL?) -> Void){
guard let track: AVAssetTrack = self.asset.tracksWithMediaType(AVMediaTypeVideo).first else{callback(url: nil); return}
let composition …Run Code Online (Sandbox Code Playgroud) ios avcomposition avvideocomposition avassetexportsession swift
我正在尝试使用iOS 4.3上的AVMutableComposition,AVMutableVideoComposition和AVVideoCompositionCoreAnimationTool将CALayer烘焙成纵向模式视频(导出时).这一切都在景观中起作用.但是,如果我以纵向捕捉视频,AVVideoCompositionCoreAnimationTool将忽略视频轨道上的变换.也就是说,对于纵向模式视频,我将AVMutableCompositionTrack.preferredTransform设置为原始资产视频轨道中的preferredTransform值.只要我不使用AVVideoCompositionCoreAnimationTool,这就可以了,视频以纵向模式显示.但是,只要我添加AVVideoCompositionCoreAnimationTool和CALayer,该文件就会出现.(CALayer显示正确,但背后的视频位于其侧面,并且文件的宽高比关闭).我尝试将变换应用于CALayer,并在ACVideoComposition中设置变换.这些都不会改变生成的文件的方向(它仍然是480x369,而不是360x480).有没有办法用AVVideoCompositionCoreAnimationTool渲染肖像模式视频?
首先,我设置了一个AVMutableComposition和AVMutableVideoComposition
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, [videoAsset duration]);
AVAssetTrack *clipVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGSize videoSize = CGSizeApplyAffineTransform(clipVideoTrack.naturalSize, clipVideoTrack.preferredTransform);
videoSize.width = fabs(videoSize.width);
videoSize.height = fabs(videoSize.height);
CMTime titleDuration = CMTimeMakeWithSeconds(5, 600);
CMTimeRange titleRange = CMTimeRangeMake(kCMTimeZero, titleDuration);
[compositionVideoTrack insertTimeRange:titleRange ofTrack:nil atTime:kCMTimeZero error:nil];
[compositionVideoTrack insertTimeRange:timeRange ofTrack:clipVideoTrack atTime:titleDuration error:nil];
compositionVideoTrack.preferredTransform = clipVideoTrack.preferredTransform;
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
AVMutableVideoCompositionInstruction *passThroughInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
passThroughInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, [composition …Run Code Online (Sandbox Code Playgroud) 我在追踪资产导出会话失败背后的根本问题时遇到了问题.问题仅针对一个视频,我认为问题出在其音频轨道上,因为我成功导出了没有音轨的资产(只有视频轨道).
使用AVAssetReader对视频轨道进行解码,并在重写为新视频轨道之前处理采样缓冲区; 音频轨道没有解码也没有任何中间处理.但是,即使不处理视频样本缓冲区,也会发生相同的故障.
我也试过反过来做 - 只有音频而没有视频轨道 - 还有其他视频工作正常,这个特定的视频失败了.我认为视频的音轨有一个固有的问题,但我无法推断出问题是什么,因此我无法解决它.这是我的代码:
AVAssetExportSession* assetExport = [[AVAssetExportSession alloc] initWithAsset:composition
presetName:AVAssetExportPresetHighestQuality];
assetExport.outputFileType = @"com.apple.quicktime-movie";
assetExport.outputURL = [NSURL fileURLWithPath:path];
__weak typeof(self) weakSelf = self;
[assetExport exportAsynchronouslyWithCompletionHandler:^{
switch (assetExport.status) {
case AVAssetExportSessionStatusCompleted: NSLog(@"Asset combined");
break;
case AVAssetExportSessionStatusFailed: NSLog(@"Asset combination failed");
break;
default: NSLog(@"Asset combination completed with unknown status: %@", @(assetExport.status));
break;
}
}];
Run Code Online (Sandbox Code Playgroud)
这个问题应该出现在资产出口会议上; 跟踪AVMutableComposition的插入工作得很好.这是AVAssetExportSession的错误消息:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSUnderlyingError=0x6040001338d0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"},
NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not …Run Code Online (Sandbox Code Playgroud) ios ×9
avfoundation ×5
objective-c ×3
swift ×3
audio ×1
avasset ×1
cocoa-touch ×1
iphone ×1
metadata ×1
video ×1