【问题标题】:How build ffmpeg optimized for iOS, using hardware decoding probably?如何构建针对 iOS 优化的 ffmpeg,可能使用硬件解码?
【发布时间】:2012-11-28 02:02:08
【问题描述】:

我为 ios 制作了一个基于 FFMPEG 的播放器。它在模拟器上运行良好,但在真实设备(iPhone 4)上,帧速率很低,使我的音频和视频不同步。该播放器在 iPhone 4s 上运行良好,所以我想这只是设备的计算能力问题。

那么,有没有为 iOS 设备(armv7、arvm7s arch)构建优化的 FFMPEG?还是有办法利用ios设备硬件解码视频流?

我的视频流采用 H264/AAC 编码。

【问题讨论】:

    标签: ios ffmpeg


    【解决方案1】:

    这些流应该可以正常播放,我认为由于您使用的是 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;
    }
    

    目前的一个缺点是需要确定一种方法来读取正在写入的编码数据,相信我,当我说我们中的一些开发人员在我编写时试图弄清楚如何做到这一点时这个。

    【讨论】:

    • 你的视频解码是 AVFoundation 吗?如果你的视频是h264/aac,那么使用ffmpeg进行解码的原因是什么?
    • 你说你使用的是基于 ffmpeg 的播放器
    • 是的,我确实实现了预缓冲和 GPU 加速色彩空间转换,但帧速率仍然很低(15~23 fps,在 ip4 上测试),所以我想到了其他替代方案。由于我们的视频仅包含 H264/AAC 流,因此使用 AVFoundation 提供的硬件解码可能是一个不错的选择。 AVFoundation 在解码 h264/aac 流时显然比 ffmpeg 提供了更好的性能,所以我认为你使用 ffmpeg 而不是 AVFoundation 肯定有特殊原因?
    • 哦,你的意思是在上面的项目中,它同时具有 ffmpeg 和 avfoundation,我们使用 ffmpeg 作为 rtsp 流,然后我们使用 hw 从 rtsp 创建新电影。
    猜你喜欢
    • 2012-04-06
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-10-08
    • 2014-11-07
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    相关资源
    最近更新 更多