- (IBAction)showTrimmedVideo:(UIButton *)sender
{
[self deleteTmpFile];
NSURL *videoFileUrl = [NSURL fileURLWithPath:self.originalVideoPath];
AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {
self.exportSession = [[AVAssetExportSession alloc]
initWithAsset:anAsset presetName:AVAssetExportPresetHighestQuality];
// Implementation continues.
NSURL *furl = [NSURL fileURLWithPath:self.tmpVideoPath];
self.exportSession.outputURL = furl;
self.exportSession.outputFileType = AVFileTypeMPEG4;
CMTime start = CMTimeMakeWithSeconds(self.startTime, anAsset.duration.timescale);
CMTime duration = CMTimeMakeWithSeconds(self.stopTime-self.startTime, anAsset.duration.timescale);
CMTimeRange range = CMTimeRangeMake(start, duration);
self.exportSession.timeRange = range;
self.trimBtn.hidden = YES;
self.myActivityIndicator.hidden = NO;
[self.myActivityIndicator startAnimating];
[self.exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([self.exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[self.exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
NSLog(@"NONE");
dispatch_async(dispatch_get_main_queue(), ^{
[self.myActivityIndicator stopAnimating];
self.myActivityIndicator.hidden = YES;
self.trimBtn.hidden = NO;
[self playMovie:self.tmpVideoPath];
});
break;
}
}];
}
}
2.我发送视频修剪到服务器,然后android设备从服务器获取视频,但他们发现音频/视频不同步,起初我考虑服务器做错了,所以我只是发送视频到Android设备与USB,错误仍然存在。
3.所以我通过ffmpeg工具分析剪裁的视频:
ffmpeg -i trimVideo.mp4
然后我发现trimVideo.mp4 start是一个负数。
这是什么ffmpeg print:
元数据:
major_brand:qt
minor_version:0
compatible_brands:qt
creation_time:2015-08-29 12:22:13
编码器:Lavf56.15.102
持续时间:00:02:21.77,开始时间:-4.692568,比特率:359 kb / s
流#0:0(und):音频:aac(LC)(mp4a / 0x6134706D),24000 Hz,立体声,fltp,69 kb / s(默认)
元数据:
creation_time:2015-08-29 12:22:13
handler_name:核心媒体数据处理程序
流#0:1(und):视频:h264(高)(avc1 / 0x31637661),yuv420p,512x288 [SAR 1:1 DAR 16:9],277 kb / s,15.16 fps,15.17 tbr,12136 tbn,30.34 tbc(默认)
元数据:
creation_time:2015-08-29 12:22:13
handler_name:核心媒体数据处理程序
编码器:'avc1'
我已经被这个bug困惑了好几天了,我很抱歉我的英语不好而且我真的需要你的帮助,谢谢。
答案 0 :(得分:0)