문제

I'm using an AVMutableVideoComposition to add video and audio.

I have multiple video and audio files that I stitch together, which basically works fine.

I'm using this code to add the audio:

AVURLAsset *audioAsset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:path] options:nil];

            [compositionAudioTrack insertTimeRange:titleRange
                               ofTrack:[audioAsset tracksWithMediaType:AVMediaTypeAudio][0]
                                atTime:partZeroTime
                                 error:&err];

The path is correct (used NSLog to check) and partZeroTime is the insertion point for every audio track (the audio is played at the beginning of the video only). The audio file is always the same (some m4a file).

This only works for the first audio, though. Every subsequent audio isn't played. I do not receive an error from adding the audio asset.

I also tried to create a separate track for the music, with the same result.

Any ideas?

[Edit]

I might not be entirely clear about what I want to do, so here's more information: I have a video composition of several clips that I stitch together with an AVMutableComposition. It contains an intro (where I try to add the music), followed by 1 or 2 clips, another intro (with music) followed by more video. I added a separate track for the music so it would look like --music--silence--music--silence.

I tried adding the silence with insertEmptyTimerange but this messes up basically everything. I then used insertTimeRange:tr ofTrack:nil... which gives me the same result as before: the first music clip is played, but every following clip won't...

I'm pulling my hair out on this...

도움이 되었습니까?

해결책

ok, this was REALLY dumb... :)

The problem was, that I defined the timerange wrong. Instead of using CMTimeRangeMake(kCMTimeZero, introDuration) I defined it like CMTimeRangeMake(introStart, introDuration) where introStart was the starting time of the music...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top