我正在使用下一个代码片段同步loadValues,所以loading = NO永远不会触发.我对AVAssetExportSession exportAsynchronously有同样的问题. 这一切都不适用于设备.
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:URL options:options];
NSArray *keys = [NSArray arrayWithObjects:@"duration", @"tracks", nil];
__block bool loading = YES;
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^(void) {
loading = NO;
}];
while (loading)[[NSRunLoop currentRunLoop] runUntilDate:[[NSDate date] dateByAddingTimeInterval:0.5]];
Run Code Online (Sandbox Code Playgroud)
请帮忙!我的大脑在融化.
我目前正在尝试使用 AVMutableComposition 将 5 个视频背靠背放置,如下所示:
[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];
Run Code Online (Sandbox Code Playgroud)
然后,我使用 AVAssetExportSession 导出视频,但在每个视频之间,我会得到一个需要删除的空白/黑色帧。以前有人遇到过这个问题吗?如果有的话,你解决了吗?
此外,空白帧不在源视频文件中。
提前致谢。
我想修剪一段视频:
-(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 = CMTimeMakeWithSeconds(3.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
//[exportSession release];
}];
}
Run Code Online (Sandbox Code Playgroud)
但我得到错误: …
我试图将淡入效果添加到wav文件中,然后使用导出具有添加的淡入效果的新文件AVAssetExportSession。我所看到的所有示例都将导出为m4u甚至可以使用wav或aif进行此操作吗?
我得到的错误是:
AVAssetExportSessionStatusFailed Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo=0x1f01c9f0 {NSLocalizedDescription=Cannot Open, NSLocalizedFailureReason=This media format is not supported.}
Run Code Online (Sandbox Code Playgroud)
我的代码如下所示
NSString *inpath = [path stringByAppendingFormat:@"/%@",file];
NSString *ename = [file stringByDeletingPathExtension];
NSString *incname = [ename stringByAppendingString:@"1t"];
NSString *outname = [incname stringByAppendingPathExtension:@"wav"];
NSString *outpath = [path stringByAppendingFormat:@"/%@",outname];
NSURL *urlpath = [NSURL fileURLWithPath:inpath];
NSURL *urlout = [NSURL fileURLWithPath:outpath];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:urlpath options:options];
//check the soundfile is greater than 50seconds
CMTime assetTime = [anAsset …Run Code Online (Sandbox Code Playgroud) 我正在使用 AVFoundation 裁剪和旋转视频,但在设置 AVAssetExporter 的 videoComposition 属性时收到 SIGABRT 错误。
assetExport.videoComposition = videoComposition;
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢,丹尼尔。
我将两个录音(使用录音AVAudioRecorder)合并为一个文件.使用AVAssetExportSession导出的合并文件(只要我即在当前视图控制器)完美的作品第一次但当重新载入该视图(新的会话)的AVAssetExportSession exportAsynchronouslyWithCompletionHandler:方法没有得到根本称为(没有回电话! )没有错误没有什么...我试图记录AVAssetExportSession对象,我第一次得到这个
Run Code Online (Sandbox Code Playgroud)<AVAssetExportSession: 0x155b3250, asset = <AVMutableComposition: 0x156474c0 tracks = ("<AVMutableCompositionTrack: 0x156a0bb0 trackID = 1, mediaType = soun, editCount = 0>")>, presetName = AVAssetExportPresetAppleM4A, outputFileType = (null)
这是第二次
<AVAssetExportSession: 0x1559e840, asset = <AVMutableComposition: 0x155f7f30 tracks = ("<AVMutableCompositionTrack: 0x155f0120 trackID = 1, mediaType = soun, editCount = 1>")>, presetName = AVAssetExportPresetAppleM4A, outputFileType = (null)
Run Code Online (Sandbox Code Playgroud)
我注意到的唯一区别是editCount = 1.
我知道这听起来令人困惑,这对我来说.这里发生了什么?
我的代码:
AVAssetExportSession* exportSession = [AVAssetExportSession
exportSessionWithAsset:composition
presetName:AVAssetExportPresetAppleM4A];
NSLog(@"exportSession: %@", exportSession);
exportSession.outputURL = [NSURL fileURLWithPath:combined];
exportSession.outputFileType = …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我允许用户以纵向模式录制视频.我在应用程序中使用它,这很好.但是,我正在实施一项功能,在Instagram上分享视频,视频必须是方形的.
将视频裁剪为正方形,比如说中心部分,是一个选项,但是由于用户在拍摄视频时没有考虑到这一点,因此通常会发现它很糟糕.
因此,我想导出视频方块,但具有宽高比和左右两个条.最好的是,有没有办法定义背景的颜色(通过代码或通过UIImage).
我能找到的最接近的是这个,但我无法充分利用它,因为我不知道如何设置转换.
示例(红色框仅用于标记图像边界):

我正在尝试导出AVMutableComposition使用AVAssetExportSession.
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mutableComposition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL=url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.videoComposition = mainCompositionInst;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^
{
switch (exporter.status)
{
case AVAssetExportSessionStatusCompleted:
{
NSLog(@"Video Merge SuccessFullt");
}
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Failed:%@", exporter.error.description);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Canceled:%@", exporter.error);
break;
case AVAssetExportSessionStatusExporting:
NSLog(@"Exporting!");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"Waiting");
break;
default:
break;
}
}];
Run Code Online (Sandbox Code Playgroud)
但是出口即使是1分钟的视频也需要30秒左右,考虑到iPad内置摄像头应用程序需要不到2秒的时间.
此外,如果我videoComposition从导出器中删除,时间减少到7秒,这仍然是不好的,考虑到视频长度只有1分钟.那么,我想知道如何将出口时间减少到最低限度?
另外,我想知道,AVAssetExportSession一般需要这么多时间,还是只是我的情况?
更新:合并代码:
AVMutableComposition*mutableComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *videoCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *audioCompositionTrack = …Run Code Online (Sandbox Code Playgroud) 我有一个导出视频文件的代码。该代码在 iOS8 上运行良好,但在 iOS9 设备上视频文件没有声音。我认为问题出在 AVAssetExportSession 上,但我无法找到问题并修复它。同样奇怪的是,当我导出它进行播放时,该资源工作正常。
(void)export {
self.videoComposition.renderScale = 1.0;
self.videoComposition.animationTool = [self coreAnimationTool];
FakeAsset * assetFaker = [FakeAsset new];
[assetFaker fakeAssetWithDuration:self.currentTime completitionBlock:^(AVAsset *asset) {
[self addEmptyBackgroundTrackFromAsset:asset];
AVAssetExportSession * exportSession =
[AVAssetExportSession exportSessionWithAsset:[self.composition copy]
presetName:AVAssetExportPresetHighestQuality];
[MovieExport setCurrentExporter:exportSession];
NSUInteger i = 0;
NSString * path;
do {
path =
[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"movieExport%i.mov",i]]; i++;
} while ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]);
NSURL * url = [NSURL fileURLWithPath:path];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtURL:url error:nil];
}
exportSession.outputURL = url;
exportSession.outputFileType …Run Code Online (Sandbox Code Playgroud) 我的视频持续时间为4:00.现在我想根据视频帧在视频文件中添加文本.比如从00:30到1:50持续时间,我想添加文字"欢迎".现在从3:00到4:00视频的持续时间我想添加文字"Awesome".如何实现这一功能.我在下面的教程中提到过.它在整个视频中添加文本而不是视频的一段时间. https://www.raywenderlich.com/30200/avfoundation-tutorial-adding-overlays-and-animations-to-videos
任何帮助都会得到满足.
我在整个视频中添加了添加文字的代码行:
- (void)applyVideoEffectsToComposition:(AVMutableVideoComposition *)composition size:(CGSize)size
{
// 1 - Set up the text layer
CATextLayer *subtitle1Text = [[CATextLayer alloc] init];
[subtitle1Text setFont:@"Helvetica-Bold"];
[subtitle1Text setFontSize:36];
[subtitle1Text setFrame:CGRectMake(0, 0, size.width, 100)];
[subtitle1Text setString:_subTitle1.text];
[subtitle1Text setAlignmentMode:kCAAlignmentCenter];
[subtitle1Text setForegroundColor:[[UIColor whiteColor] CGColor]];
// 2 - The usual overlay
CALayer *overlayLayer = [CALayer layer];
[overlayLayer addSublayer:subtitle1Text];
overlayLayer.frame = CGRectMake(0, 0, size.width, size.height);
[overlayLayer setMasksToBounds:YES];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, size.width, size.height);
videoLayer.frame = CGRectMake(0, …Run Code Online (Sandbox Code Playgroud) ios ×8
avfoundation ×7
objective-c ×4
iphone ×3
avurlasset ×2
video ×2
audio ×1
ios8 ×1
ios9 ×1