我试图在嵌套层次结构中使用AVMutableComposition.因此,我必须将一种成分放入其他成分中.这样做会导致以下错误消息:
AVCompositionTest [45347:10703] comp2 >>>操作无法完成
我使用了以下代码剪切.
AVAsset *audioAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"02 Undefined" ofType:@"mp3"]]];
AVMutableComposition *comp1 = [AVMutableComposition composition];
BOOL success = YES;
NSError *error = nil;
success = [comp1 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration)
ofAsset:audioAsset
atTime:kCMTimeZero
error:&error];
if (!success) {
NSLog(@"comp1 >>> %@", [error localizedDescription]);
}
AVMutableComposition *comp2 = [AVMutableComposition composition];
success = [comp2 insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration)
ofAsset:comp1
atTime:kCMTimeZero
error:&error];
if (!success) {
NSLog(@"comp2 >>> %@", [error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)
是否有可能筑巢成分?
我的目标是组合从相机记录的一组剪辑并以特定的首选尺寸导出它们.当然,视频方向需要在导出之前旋转.
我是通过从存储在下面的avAssets中的视频剪辑数组合成AVMutableComposition来做到这一点的.我可以把它们组合好,并将其导出.但是,我在AVMutableVideoComposition上设置的旋转变换不受尊重.如果我使用相同的转换并将其设置在视频轨道的preferredTransform属性上,那么它可以工作.在这两种情况下,视频renderSize都没有被尊重.这就好像导出器完全忽略了videoComposition.有什么想法会发生什么?
我确实有一个AVCaptureSession正在运行,但我在导出之前将其关闭,这没有任何区别.我对iOS编程很新,所以我可能会遗漏一些基本的东西.:)
我的代码:
-(void) finalRecord{
NSError *error = nil;
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
NSLog(@"Video track id is %d", [compositionVideoTrack trackID]);
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
// avAssets hold the video clips to be composited
int pieces = [avAssets count];
CGAffineTransform transform = CGAffineTransformMakeRotation( M_PI_2);
// [compositionVideoTrack setPreferredTransform:transform];
for (int i = 0; i<pieces; i++) {
AVURLAsset *sourceAsset = [avAssets objectAtIndex:i];
AVAssetTrack *sourceVideoTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetTrack *sourceAudioTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeAudio] …Run Code Online (Sandbox Code Playgroud) 我知道之前曾问过这个问题(例如这里和这里),但我无法弄清楚我做错了什么.
我有一个AVMutableComposition用于将一些视频剪辑与一些CALayer动画组合在一起的视频剪辑.
当我AVMutableComposition把它和它结合在一起AVSynchronizedLayer进行播放时,一切正常AVPlayerLayer.视频输出正确,一切都放在应有的位置.
我的问题是,当我尝试导出这个东西时,我尝试使用AVVideoCompositionCoreAnimationTool而不是AVSynchronizedLayer(这是文档中我们应该用于导出的东西)和AVAssetExportSession,但是出了点问题,因为在我导出的电影中,每个CALayer都有它的坐标系反转.
所以,如果在播放过程中0,0点是在左上角的屏幕一角时,我出口的电影的0,0点是在左下方的角落,因此我的动画发疯.
我阅读了有关此内容的任何可能的文章,我还从Apple下载了AVVideoEdit示例,但我无法看到发生了什么......
iphone core-animation avfoundation avmutablecomposition avassetexportsession
我用前置摄像头录制了一段视频,输出被镜像了......
我尝试使用AVMutablecomposition和layerinstructions翻转视频,但没有运气.
谷歌搜索和搜索Stack Overflow一直没有结果,所以我打赌一个简单,直接的例子,说明如何做到这一点会使许多人受益.
假设我们有两个视频资源(AVAsset对象),让我们把它们称为空白和主要,其中main是一个随机有限长度的视频,比方说2-5分钟,而空白总是4秒视频,我们要合并视频按以下顺序排列:
空白 - 主要 - 空白
// Create AVMutableComposition Object.This object will hold our multiple AVMutableCompositionTrack.
let mixComposition = AVMutableComposition()
let assets = [blank, main, blank]
var totalTime : CMTime = CMTimeMake(0, 0)
var atTimeM: CMTime = CMTimeMake(0, 0)
Utils.log([blank.duration, main.duration])
// VIDEO TRACK
let videoTrack = mixComposition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
for (index,asset) in assets.enumerated() {
do {
if index == 0 {
atTimeM = kCMTimeZero
} else {
atTimeM = totalTime …Run Code Online (Sandbox Code Playgroud) 我有一个使用AVPlayer的简单视频编辑视图.我使用一个或多个AVURLAsset创建一个AVMutableComposition.一切正常,但视频总是旋转90度.即如果源视频是以纵向模式拍摄的.AVPlayer以横向模式显示它,反之亦然.我已经阅读了文档,并将其"go""至死,无法找到解决方案.我在寻找错误的地方.
有人可以帮忙吗?
提前致谢;
让 - 皮埃尔·
我有一个奇怪的问题.在我的应用程序中,我使用下面的代码组合多个音频和视频文件.一旦我将它从设备下载到计算机并使用Quick Time播放,结果视频似乎工作正常,但每当我尝试使用UIWebView或AVPLayer播放新编写的视频时,我只能看到合并视频文件的第一部分.
此外,当我尝试使用MPMoviePlayerController播放时,它会挂起"正在加载".
我可以听到所有作曲的音频.为了说清楚,我有两个阵列:1- audioPieces,带有音频文件的路径[song1,song2,song3]; 2- moviePieces,包含视频文件的路径[movie1,movie2,movie3]; 合并这些文件后,我只能看到movie1,但我可以听到song1 + song2 + song3.PS歌曲和电影有不同的长度(差异小于0.2秒).任何帮助将不胜感激.先谢谢你,Janusz
-(void)putFilesTogether{
AVMutableComposition *mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *videoCompositionTrack =[[AVMutableCompositionTrack alloc]init];
AVMutableCompositionTrack *audioCompositionTrack =[[AVMutableCompositionTrack alloc]init];
NSLog(@" movie %@ audio %@ ", moviePieces, audioPieces);
NSError * error;
for(int i=0;i<moviePieces.count;i++)
{
NSFileManager * fm = [NSFileManager defaultManager];
NSString * movieFilePath;
NSString * audioFilePath;
movieFilePath = [moviePieces objectAtIndex:i];
audioFilePath = [audioPieces objectAtIndex:i];
if(![fm fileExistsAtPath:movieFilePath]){
NSLog(@"Movie doesn't exist %@ ",movieFilePath);
}
else{
NSLog(@"Movie exist %@ ",movieFilePath);
}
if(![fm fileExistsAtPath:audioFilePath]){
NSLog(@"Audio doesn't exist %@ …Run Code Online (Sandbox Code Playgroud) 我有一个带声音录制的视频.将其添加到AVMutableComposition然后将其导出时,视频将在播放声音时冻结.我错过了什么?
我有两条曲目:
_compositionVideoTrack = [self.composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
_compositionAudioTrack = [self.composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
Run Code Online (Sandbox Code Playgroud)
然后创建轨道:
AVAssetTrack *clipVideoTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetTrack *clipAudioTrack = [[sourceAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
然后我插入曲目:
[_compositionVideoTrack insertTimeRange:editRange ofTrack:clipVideoTrack atTime:self.composition.duration error:&editError];
[_compositionAudioTrack insertTimeRange:editRange ofTrack:clipAudioTrack atTime:self.composition.duration error:&editError];
Run Code Online (Sandbox Code Playgroud)
最后我导出它:
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:urlAsset presetName:AVAssetExportPresetPassthrough];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
Run Code Online (Sandbox Code Playgroud)
该文件是.mp4.它可能是文件格式吗?
我想实现慢动作视频像Slo-Mo相机的Defalut功能,我使用下面的代码,它适用于视频.但在音频轨道中该视频无法正常工作.
double videoScaleFactor =8.0;
compositionAudioTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
toDuration:CMTimeMake(videoDuration.value* videoScaleFactor,videoDuration.timescale)];
[compositionVideoTrack scaleTimeRange:CMTimeRangeMake(kCMTimeZero, videoDuration)
toDuration:CMTimeMake(videoDuration.value* videoScaleFactor, videoDuration.timescale)];
this scenario is woking properly for video slowmotion.But in audio slow-motion it is not working...
Run Code Online (Sandbox Code Playgroud)
请帮我..
这个问题之前已被多次询问,但没有任何帮助.我正在使用合并多个视频AVMutableComposition.合并视频后,我会在30%到40%的视频中出现空白帧.其他合并很好.我刚玩的组成直接使用AVPlayer作为AVPlayerItem.代码如下:
AVMutableComposition *mutableComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *videoCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *audioCompositionTrack = [mutableComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
NSMutableArray *instructions = [NSMutableArray new];
CGSize size = CGSizeZero;
CMTime time = kCMTimeZero;
for (AVURLAsset *asset in assets)
{
AVAssetTrack *assetTrack;
assetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
AVAssetTrack *audioAssetTrack = [asset tracksWithMediaType:AVMediaTypeAudio].firstObject;
NSError *error;
[videoCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration )
ofTrack:assetTrack
atTime:time
error:&error];
if (error) {
NSLog(@"asset url :: %@",assetTrack.asset);
NSLog(@"Error - %@", error.debugDescription);
}
[audioCompositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration)
ofTrack:audioAssetTrack …Run Code Online (Sandbox Code Playgroud) avfoundation ×7
ios ×7
video ×5
iphone ×3
objective-c ×2
audio ×1
avplayer ×1
avurlasset ×1
cocoa ×1
mirror ×1
swift ×1
swift3 ×1