iphone - 如何在 iphone sdk 中合并实时流媒体视频和音频
<p><p>我正在 IOS 中开发基于视频的应用程序。在我的应用程序中,我需要合并视频和音频。我已经合并了本地视频和音频文件,但是如果我尝试合并它们,我无法合并实时流视频和音频,这意味着应用程序由于持续时间而崩溃。对于合并,我使用以下代码</p>
<pre><code> -(void) playerFunction
{
NSURL *url = ;
// NSURL *url = ;// these is totally not working
NSString* audio_inputFileName = @"audio.mp3";
NSString* audio_inputFilePath = resourcePath],audio_inputFileName];
NSURL* audiopath = ;
NSString* videoName = @"output.mov";//outputdata
NSString *savepath = ;
NSFileManager *filemgr = ;
if ( == YES){
[ removeItemAtPath:savepath error:nil];
}
else
{
NSLog (@"File not found");
}
CMTime nextClipStartTime = kCMTimeZero;
AVMutableComposition* mixComposition = ;
NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @YES };
AVURLAsset* videoAsset = [initWithURL:url options:options];
AVURLAsset* audioAsset = [initWithURL: audiopath options:options];
CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration);
AVMutableCompositionTrack *a_compositionVideoTrack = ;
NSLog(@"%@",);
NSLog(@"%@",);
NSLog(@"%f", CMTimeGetSeconds(videoAsset.duration));
objectAtIndex:0] atTime:kCMTimeZero error:nil];
;
CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, audioAsset.duration);
AVMutableCompositionTrack *b_compositionAudioTrack = ;
objectAtIndex:0] atTime:nextClipStartTime error:nil];
AVAssetExportSession* _assetExport = [ initWithAsset:mixComposition presetName:AVAssetExportPresetLowQuality];
_assetExport.shouldOptimizeForNetworkUse = YES;
_assetExport.outputFileType = @"com.apple.quicktime-movie";
NSURL *savetUrl = ;
_assetExport.outputURL = savetUrl;
_assetExport.timeRange = CMTimeRangeMake(kCMTimeZero, audioAsset.duration);
[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
switch (_assetExport.status)
{
case AVAssetExportSessionStatusCompleted:
// export complete
NSLog(@"Export Complete");
//------>>> // From Here I want play movie using MPMoviePlayerController.<<<---------
;
// ;
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Export Failed");
NSLog(@"ExportSessionError: %@", );
// export error (see exportSession.error)
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export Failed");
NSLog(@"ExportSessionError: %@", );
// export cancelled
break;
}
}
];
NSLog(@"savepath :%@",savepath);
}
</code></pre>
<p>请一些人帮助我</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您没有提供正确的实时视频 URL 来播放。</p>
<p>在您的代码中,您在文档目录中传递了本地视频 URL。
<code>NSString *fileNamePath1 = @"Egg_break.mov";</code> 而不是这个,你应该从服务器传递一些 URLString。</p>
<p>例如</p>
<pre><code>AVURLAsset *asset = options:nil];
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 如何在 iphone sdk 中合并实时流媒体视频和音频,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15244041/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15244041/
</a>
</p>
页:
[1]