gpt4 book ai didi

iphone - 从 iPhone 应用程序上传到 YouTube 的视频没有声音

转载 作者:行者123 更新时间:2023-12-03 21:03:50 24 4
gpt4 key购买 nike

我正在开发一个 iPhone 应用程序,它记录其事件(屏幕录制)并上传到 YouTube。首先,视频在上传之前没有声音,应用程序将一些声音与视频混合。输出视频在我的 iPhone 和 iPad 上播放没有任何问题,但上传的视频播放时没有声音(仅在启动时有声音)。我的视频格式是.mov。我混合声音和视频的代码是

as in purplelilgirl's tutorial

-(NSString*) processVideo: (NSURL*) videoUrl{    NSLog(@"started processing %@",videoUrl);
AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL: videoUrl options:nil];

AVMutableComposition* mixComposition = [AVMutableComposition composition];


NSError * error = nil;

for (NSMutableDictionary * audioInfo in audioInfoArray){
// NSString *pathString = [[NSHomeDirectory() stringByAppendingString:@"/Documents/"] stringByAppendingString: [audioInfo objectForKey: @"fileName"]];
// NSString *pathString = [audioInfo objectForKey: @"filePath"];
NSURL *audioUrl=[audioInfo objectForKey: @"filePath"];
// NSLog(@"audioUrl %@",audioUrl);
AVURLAsset * urlAsset = [AVURLAsset URLAssetWithURL:audioUrl options:nil];

AVAssetTrack * audioAssetTrack = [[urlAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID: kCMPersistentTrackID_Invalid];

// NSLog(@"%lf", [[audioInfo objectForKey: @"startTime"] doubleValue]);

CMTime audioStartTime = CMTimeMake(([[audioInfo objectForKey: @"startTime"] doubleValue]*TIME_SCALE), TIME_SCALE);

[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,urlAsset.duration) ofTrack:audioAssetTrack atTime:audioStartTime error:&error];
}


AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]
atTime:kCMTimeZero error:&error];

AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition
presetName:AVAssetExportPresetPassthrough];

NSString* videoName = @"export.mov";

NSString *exportPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:videoName];
NSURL *exportUrl = [NSURL fileURLWithPath:exportPath];

if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath])
{
[[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
}

_assetExport.outputFileType = @"com.apple.quicktime-movie";
// _assetExport.outputFileType=AVFileTypeMPEG4;
NSLog(@"file type %@",_assetExport.outputFileType);
_assetExport.outputURL = exportUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;

[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
switch (_assetExport.status)
{
case AVAssetExportSessionStatusCompleted:
//export complete
NSLog(@"Export Complete");
//[self uploadToYouTube];

break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Export Failed");
NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
//export error (see exportSession.error)
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export cancelled");
NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
//export cancelled
break;
}
}];
NSLog(@"completed processing exportPath %@ ",exportPath);
return exportPath;
}

我的代码有什么问题,你能帮我吗

最佳答案

音频使用什么编解码器进行编码?据我了解,如果您使用某种形式的苹果专有编解码器,可能会导致您的问题。

关于iphone - 从 iPhone 应用程序上传到 YouTube 的视频没有声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9921239/

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