修剪后的ios视频,然后在非ios设备上播放音频/视频不同步 [英] ios video after trimming then play on non ios device audio/video out of sync
问题描述
修整视频,然后将修整后的视频发送到android设备并播放,我发现音频/视频不同步,音频比视频落后几秒钟.但视频可以在iOS设备上正常播放.1.我使用以下代码修剪视频:
trimming video,then I send the video trimmed to android device and play,I find audio/video out of sync, the audio is several seconds behind the video. but the video can play normal on iOS device. 1.I trim video with codes like this:
- (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,错误仍然存在.
2.I send the video trimmed to server,then android device get video from server,but they find audio/video out of sync,at first I consider of server do something wrong,so I just send video to android device with USB,the error still exist.
3.so我通过ffmpeg工具分析了修整后的视频:ffmpeg -i trimVideo.mp4
然后我发现trimVideo.mp4开始是一个负数.这是ffmpeg打印的内容:
3.so I analyze the trimmed video by ffmpeg tools:
ffmpeg -i trimVideo.mp4
then I find trimVideo.mp4 start is a negative number.
here is what 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.34tbc(默认)
元数据:
creation_time:2015-08-29 12:22:13
handler_name:核心媒体数据处理程序
编码器:'avc1'
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2015-08-29 12:22:13
encoder : Lavf56.15.102
Duration: 00:02:21.77, start: -4.692568, bitrate: 359 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 24000 Hz, stereo, fltp, 69 kb/s (default)
Metadata:
creation_time : 2015-08-29 12:22:13
handler_name : Core Media Data Handler
Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 512x288 [SAR 1:1 DAR 16:9], 277 kb/s, 15.16 fps, 15.17 tbr, 12136 tbn, 30.34 tbc (default)
Metadata:
creation_time : 2015-08-29 12:22:13
handler_name : Core Media Data Handler
encoder : 'avc1'
好几天以来,我一直对该错误感到困惑,对我的英语不好对不起,谢谢.我真的需要您的帮助.
I have been puzzled by this bug for several days, I am sorry of my bad english and I really need your help,thanks.
推荐答案
好的,最后我找到了解决问题的方法.我使用SDAvassetExportSession修剪视频,尽管结果视频长度稍长一些,但是A/V可以在非QuickTime播放器中同步.
ok,finally I find a way to solve the problem. I use SDAvassetExportSession to trim video,although the result video lengths are longer a little,but A/V can be sync in non quicktime player.
这篇关于修剪后的ios视频,然后在非ios设备上播放音频/视频不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!