【发布时间】:2012-11-28 02:02:08
【问题描述】:
我为 ios 制作了一个基于 FFMPEG 的播放器。它在模拟器上运行良好,但在真实设备(iPhone 4)上,帧速率很低,使我的音频和视频不同步。该播放器在 iPhone 4s 上运行良好,所以我想这只是设备的计算能力问题。
那么,有没有为 iOS 设备(armv7、arvm7s arch)构建优化的 FFMPEG?还是有办法利用ios设备硬件解码视频流?
我的视频流采用 H264/AAC 编码。
【问题讨论】:
我为 ios 制作了一个基于 FFMPEG 的播放器。它在模拟器上运行良好,但在真实设备(iPhone 4)上,帧速率很低,使我的音频和视频不同步。该播放器在 iPhone 4s 上运行良好,所以我想这只是设备的计算能力问题。
那么,有没有为 iOS 设备(armv7、arvm7s arch)构建优化的 FFMPEG?还是有办法利用ios设备硬件解码视频流?
我的视频流采用 H264/AAC 编码。
【问题讨论】:
这些流应该可以正常播放,我认为由于您使用的是 ffmpeg,因此您没有使用 iOS 直接支持的视频协议。
我们使用 ffmpeg 做 rtsp/rtmp,我们使用 h264/aac 获得了良好的性能
导致 av/sync 问题的因素有很多,通常需要对视频进行某种类型的预缓冲,网络在其中也起着重要作用。
关于你的第二个问题,硬件编码只能通过 avfoundation 获得,你可以使用 avassetwriter 来编码你的视频,但同样取决于你是否需要实时。
查看此链接https://github.com/mooncatventures-group/FFPlayer-beta1/blob/master/FFAVFrames-test/ViewController.m
-(void) startRecording {
// // create the AVComposition
// [mutableComposition release];
// mutableComposition = [[AVMutableComposition alloc] init];
movieURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%llu.mov", NSTemporaryDirectory(), mach_absolute_time()]];
NSError *movieError = nil;
assetWriter = [[AVAssetWriter alloc] initWithURL:movieURL
fileType: AVFileTypeQuickTimeMovie
error: &movieError];
NSDictionary *assetWriterInputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:FRAME_WIDTH], AVVideoWidthKey,
[NSNumber numberWithInt:FRAME_HEIGHT], AVVideoHeightKey,
nil];
assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo
outputSettings:assetWriterInputSettings];
assetWriterInput.expectsMediaDataInRealTime = YES;
[assetWriter addInput:assetWriterInput];
assetWriterPixelBufferAdaptor = [[AVAssetWriterInputPixelBufferAdaptor alloc]
initWithAssetWriterInput:assetWriterInput
sourcePixelBufferAttributes:nil];
[assetWriter startWriting];
firstFrameWallClockTime = CFAbsoluteTimeGetCurrent();
[assetWriter startSessionAtSourceTime:kCMTimeZero];
startSampleing=YES;
}
目前的一个缺点是需要确定一种方法来读取正在写入的编码数据,相信我,当我说我们中的一些开发人员在我编写时试图弄清楚如何做到这一点时这个。
【讨论】: