gpt4 book ai didi

ios - AVAssetExportSession-在IOS中加入2个mp4文件

转载 作者:行者123 更新时间:2023-12-01 18:17:24 25 4
gpt4 key购买 nike

我正在尝试使用以下代码将2个预先存在的mpeg4视频加入到ipad2上。

-(void)mergeTestVideos
{

//setup asset
NSString *firstassetpath = [NSString stringWithFormat:@"%@mpeg4-1.mp4", NSTemporaryDirectory()];
NSString *secondassetpath = [NSString stringWithFormat:@"%@mpeg4-2.mp4", NSTemporaryDirectory()];

NSFileManager *fileManager = [NSFileManager defaultManager];

AVAsset *firstAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:firstassetpath]];
AVAsset *secondAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:secondassetpath]];

NSLog(@"FirstAsset Is Readable = %d", firstAsset.isReadable);
NSLog(@"FirstAsset Is playable = %d", firstAsset.isPlayable);
NSLog(@"FirstAsset Is exportable = %d", firstAsset.exportable);
NSLog(@"SecondAsset Is Readable = %d", secondAsset.isReadable);
NSLog(@"SecondAsset Is playable = %d", secondAsset.isPlayable);
NSLog(@"SecondAsset Is exportable = %d", secondAsset.exportable);

//setup composition and track
AVMutableComposition *composition = [[AVMutableComposition alloc]init];
AVMutableCompositionTrack *track = [composition addMutableTrackWithMediaType:AVAssetExportPresetPassthrough preferredTrackID:kCMPersistentTrackID_Invalid];

//add assets to track
[track insertTimeRange:CMTimeRangeMake(kCMTimeZero, firstAsset.duration) ofTrack:[[firstAsset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0] atTime:kCMTimeZero error:nil];

[track insertTimeRange:CMTimeRangeMake(kCMTimeZero, secondAsset.duration) ofTrack:[[secondAsset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0] atTime:firstAsset.duration error:nil];

// 5 - Create exporter
AVAssetExportSession *exporter = [[AVAssetExportSession alloc]initWithAsset:composition presetName:AVAssetExportPresetPassthrough];

NSString *outputURL = [NSString stringWithFormat:@"%@mergedvid.mp4", NSTemporaryDirectory()];

NSLog(@"%@", exporter.supportedFileTypes);
exporter.outputURL=[NSURL fileURLWithPath:outputURL];

exporter.outputFileType = AVFileTypeMPEG4;
[exporter exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:exporter];
});
}];

}

-(void)exportDidFinish:(AVAssetExportSession*)session {

NSLog(@"export method");
NSLog(@"%i", session.status);
NSLog(@"%@", session.error);
}

输出如下:
- FirstAsset Is Readable = 1
- FirstAsset Is playable = 1
- FirstAsset Is exportable = 1
- SecondAsset Is Readable = 1
- SecondAsset Is playable = 1
- SecondAsset Is exportable = 1
- (
"com.apple.quicktime-movie",
"com.apple.m4a-audio",
"public.mpeg-4",
"com.apple.m4v-video",
"public.3gpp",
"org.3gpp.adaptive-multi-rate-audio",
"com.microsoft.waveform-audio",
"public.aiff-audio",
"public.aifc-audio",
"com.apple.coreaudio-format"
)
-export method
- 4
- Error Domain=AVFoundationErrorDomain Code=-11838 "Operation Stopped" UserInfo=0x155f76f0 {NSLocalizedDescription=Operation Stopped, NSLocalizedFailureReason=The operation is not supported for this media.}

好的,根据输出,我的文件是可以导出的,并且mp4是受支持的输出类型。

有人知道为什么它会给我错误信息“此媒体不支持该操作”吗?

最佳答案

我认为这是你的罪魁祸首

AVMutableCompositionTrack *track = [composition addMutableTrackWithMediaType:AVAssetExportPresetPassthrough preferredTrackID:kCMPersistentTrackID_Invalid];

在这里,您传递了 AVAssetExportPresetPassthrough,您应该在其中使用 AVMediaTypeVideoAVMediaTypeAudio

关于ios - AVAssetExportSession-在IOS中加入2个mp4文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20558461/

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