Bri*_*sto 3 objective-c ios ios7
我需要合并两个视频文件及其相应的音频.我尝试使用:http: //www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios
视频合并,但他们的音频丢失了.这就像一个静音的视频.我还需要合并音频.我也用Google搜索,找不到任何有用的东西.请有人帮我这个...
实时编辑音频与实时编辑视频完全相同.回到每部电影并获取音轨并将其粘贴到您的可变组合中.
在这个例子中,我抓住了视频的前五秒和电影的最后五秒视频,并将它们一个接一个地放在一个新视频中:
NSString* type = AVMediaTypeVideo;
NSArray* arr = [oldAsset tracksWithMediaType:type];
AVAssetTrack* track = [arr lastObject];
CMTime duration = track.timeRange.duration;
AVMutableComposition* comp = [AVMutableComposition composition];
AVMutableCompositionTrack* comptrack = [comp addMutableTrackWithMediaType:type preferredTrackID:kCMPersistentTrackID_Invalid];
[comptrack insertTimeRange:CMTimeRangeMake(CMTimeMakeWithSeconds(0,600), CMTimeMakeWithSeconds(5,600)) ofTrack:track atTime:CMTimeMakeWithSeconds(0,600) error:nil];
[comptrack insertTimeRange:CMTimeRangeMake(CMTimeSubtract(duration, CMTimeMakeWithSeconds(5,600)), CMTimeMakeWithSeconds(5,600)) ofTrack:track atTime:CMTimeMakeWithSeconds(5,600) error:nil];
Run Code Online (Sandbox Code Playgroud)
但由此产生的视频将是沉默的.所以我也回去取相应的音频:
type = AVMediaTypeAudio;
arr = [oldAsset tracksWithMediaType:type];
track = [arr lastObject];
comptrack = [comp addMutableTrackWithMediaType:type preferredTrackID:kCMPersistentTrackID_Invalid];
[comptrack insertTimeRange:CMTimeRangeMake(CMTimeMakeWithSeconds(0,600), CMTimeMakeWithSeconds(5,600)) ofTrack:track atTime:CMTimeMakeWithSeconds(0,600) error:nil];
[comptrack insertTimeRange:CMTimeRangeMake(CMTimeSubtract(duration, CMTimeMakeWithSeconds(5,600)), CMTimeMakeWithSeconds(5,600)) ofTrack:track atTime:CMTimeMakeWithSeconds(5,600) error:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1477 次 |
| 最近记录: |