- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个库的文档基本上不存在,所以我真的需要你的帮助。
目标:我需要 H264 编码(最好同时使用音频和视频,但只有视频就可以了,我会玩几天让音频也能正常工作),这样我就可以将它传递到 MPEG 传输流中。
我有什么:我有一个记录和输出样本缓冲区的相机。输入是相机背面和内置麦克风。
几个问题:A. 是否可以让相机以 H264 格式输出 CMSampleBuffers?我的意思是,2014 年它是从 VTCompressionSessions 生成的,但是在编写我的 captureOutput 时,我看到我已经得到了一个 CMSampleBuffer ...B. 如何设置 VTCompressionSession? session 是如何使用的?一些关于此的总体顶级讨论可能有助于人们了解这个几乎没有记录的库中实际发生的事情。
此处的代码(如果需要,请索取更多;我只放了 captureOutput,因为我不知道其余代码的相关性如何):
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
println(CMSampleBufferGetFormatDescription(sampleBuffer))
var imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
if imageBuffer != nil {
var pixelBuffer = imageBuffer as CVPixelBufferRef
var timeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer as CMSampleBufferRef)
//Do some VTCompressionSession stuff
}
}
谢谢大家!
最佳答案
首先初始化 VTCompression session 并设置其属性
NSDictionary* bAttributes= @{};
VTCompressionSessionRef vtComp;
OSStatus result = VTCompressionSessionCreate(NULL,
trackSize.width,
trackSize.height,
kCMVideoCodecType_H264,
NULL,
(CFDictionaryRef)bAttributes,
NULL,
compressCallback,
NULL,
&vtComp);
NSLog(@"create VTCS Status: %d",result);
NSDictionary* compProperties = @{
(id)kVTCompressionPropertyKey_ProfileLevel: (id)kVTProfileLevel_H264_High_AutoLevel,
(id)kVTCompressionPropertyKey_H264EntropyMode: (id)kVTH264EntropyMode_CABAC,
(id)kVTCompressionPropertyKey_Quality: @(0.95),
(id)kVTCompressionPropertyKey_RealTime: @(YES),
(id)kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder: @(YES),
(id)kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder: @(YES)
};
result=VTSessionSetProperties(vtComp,(CFDictionaryRef)compProperties);
compressCallback
是您的方法,它在压缩数据可用时调用。看起来像这样;
void compressCallback(void *outputCallbackRefCon, void *sourceFrameRefCon, OSStatus status, VTEncodeInfoFlags infoFlags, CMSampleBufferRef sampleBuffer)
{
AVAssetWriterInput* aw = (AVAssetWriterInput*)sourceFrameRefCon;
[aw appendSampleBuffer:sampleBuffer];
}
然后你有你的读取/压缩循环。您从 CMSample 缓冲区获取 CVImage 缓冲区并将其传递给压缩器。
CVPixelBufferRef buffer = CMSampleBufferGetImageBuffer(cmbuf);
VTEncodeInfoFlags encodeResult;
result = VTCompressionSessionEncodeFrame (vtComp,
buffer,
currentTime,
frameDuration,
NULL, // frameProperties
writerInput, // opaque context to callback
&encodeResult);
显然,您需要检查状态和返回值,但这应该让您找到正确的方向。
关于ios - 在 WWDC2014 中使用 VTCompressionSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31467571/
我正在检查 WWDC-2018(面向开发人员的平台国情咨文事件)。 Apple 概述了 Mac OS Mojave 和 iOS 12 即将推出的一些新保护措施。 其中一点是公证审查在分发 Mac OS
我不确定这是不是问这个问题的正确论坛,但我试图找到 WWDC 2013 示例代码。我遇到了这个:https://github.com/jfahrenkrug/WWDC-Downloader 我没有从命
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improv
我查看了有关核心数据更改的 WWDC 2014 视频,我认为它很棒。但是,当我尝试使用 Apple 网站中的示例代码时:Earthquakes: Using Second Core Data Stac
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我正在尝试使用命令行将我的 .obj 对象转换为 .usdz 并使用漫反射颜色丰富它,如 WWDC 19 Working with USD 中所述.但我得到 command not found: us
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
SwiftUI具有用于延迟加载和PageView的网格列表的新功能,我有兴趣在与iOS 13兼容的现有SwiftUI应用中实现该功能。 假设我在Xcode 12中编译了我的应用程序并添加了这些新代码,
虽然我没有实际使用过它,但我看过 WWDC 2012 应用程序的图片,其中似乎每个研讨会在事件 map 上都有自己的位置。这只是一个带有大头针掉落的 UIImage 吗? 我还发现了这个本地映射启动:
每年发布的视频太多,要真正看完它们会花费太多时间。很多时候,在您真正了解细节之前,您甚至不知道它对您来说很有趣。 因此我的问题是:是否有 Apple 发布的最重要事实(不是转录,仅此而已)的协议(pr
在苹果 WWDC 2012 的视频 session 506 中,他们展示了一款专为高性能绘图而设计的绘图应用程序(因此帧率永远不会低于 30)。 我尝试复制代码,但在多个点上卡住了。 我正在寻找的是一
我将 UICollectionView 与 AutoSizing 单元格一起使用,它看起来类似于 UITableView。 如前几个问题所述:q1 , q2采用 Self-Sizing 单元格需要实现
我一直在努力反对 Cocoa 和 Xcode,并且已经持续了几个月了。我似乎永远无法摆脱教程,它们通常不完整,或者苹果开发人员文档,样本很少。我观看了视频、下载了源代码并向开发人员寻求帮助。我仍然觉得
苹果的开发者网站上有很多WWDC 2011视频。视频中还有一些关于xcode编码的demo。 神奇的是:在这些演示中,演讲者并没有一一键入示例代码。他们只需在xcode中按一些键,然后代码就存在于xc
session 426“最先进的 cocoa - 用户界面设计”(MAC session )非常有帮助。 session 期间使用的代码示例的标题是“Exposure”。我在 Mac 开发中心找不到它
我正在试用 WWDC 2010 中的 CoreMotion 茶壶示例代码。现在,代码考虑了设备运动,除了渲染的 3d 对象和设备的距离。我怎样才能添加这个? 例子:如果我将设备拉离渲染的 3d 对象,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的
我是一名优秀的程序员,十分优秀!