如何使用x264 C API将RBG图像编码为H264帧?我已经创建了一系列RBG图像,我现在如何将该序列转换为H264帧序列?特别是,如何将这个RGB图像序列编码为H264帧序列,该帧由单个初始H264关键帧后跟依赖H264帧组成?
它是在运行时简单的创建副本MyNSObject中的类 NSObject的:
首先,创建一个新的类对.
Class MyNSObject = objc_allocateClassPair(nil, "MyNSObject", 0);
Run Code Online (Sandbox Code Playgroud)
第二步从NSObject读取方法,协议和ivars ,并将它们添加到新类中.
uint instanceMethodCount;
Method *instanceMethodArray = class_copyMethodList([NSObject class], &instanceMethodCount);
for (int i = 0; i < instanceMethodCount; i++) {
Method method = *(instanceMethodArray + i);
SEL selector = method_getName(method);
IMP implementation = method_getImplementation(method);
const char *types = method_getTypeEncoding(method);
BOOL success = class_addMethod(MyNSObject, selector, implementation, types);
}
free(instanceMethodArray);
uint protocolCount;
Protocol **protocolArray = class_copyProtocolList([NSObject class], &protocolCount);
for (int i = 0; i < …Run Code Online (Sandbox Code Playgroud) 给定Objective-C类型type,可以轻松获得该类型的编码 encoding和大小size:
const char *encoding = @encode(type);
size_t size = sizeof(type);
Run Code Online (Sandbox Code Playgroud)
换句话说,我们有映射
@encode: type_t -> const char *
sizeof: type_t -> size_t
Run Code Online (Sandbox Code Playgroud)
这提出了两个问题:
(1)假设我们只有一个编码,而不是一个类型.获得映射会很不错
sizeofencodedtype: const char * -> size_t
Run Code Online (Sandbox Code Playgroud)
这样,对于每个type_t type我们都有
sizeofencodedtype(@encode(type)) = sizeof(type)
Run Code Online (Sandbox Code Playgroud)
这样的功能是否已经存在?如果没有,怎么可能建立一个?
(2)理想情况下,我们可以反转@encode映射来进行映射
decode: const char * -> type_t
Run Code Online (Sandbox Code Playgroud)
但这似乎不可能,因为type_t不是真正的C类型.我想我可以等待@decode添加到语言中,但这不是很现实或时间敏感.但是,如果不能使用其编码在运行时实例化类型吗?
在某些上下文中(例如,当挂钩到内部进行测试时),能够创建不采用NSCopying(不实现-copyWithZone:)的类的实例的副本将是方便的.怎么能实现这一目标?(注意:在类别中实现协议是不够的,因为并非所有类的实例变量都在其标题中可见.)
我已经试过遍历对象的Ivars和(1)对象类型递归(或保留),和(2)的基本类型,获得在原有的实例化而这正在取得和拷贝伊娃的地址memcpy荷兰国际集团缓冲区从源ivar的地址开始到目的地ivar的地址.
@interface NSObject (ADDLCopy)
- (id)addl_generateCopyDeep:(BOOL)deepCopy;
@end
@implementation NSObject (ADDLCopy)
//modified from http://stackoverflow.com/a/12265664/1052673
- (void *)addl_ivarPointerForName:(const char *)name
{
void *res = NULL;
Ivar ivar = class_getInstanceVariable(self.class, name);
if (ivar) {
res = (void *)self + ivar_getOffset(ivar);
}
return res;
}
- (id)addl_generateCopyDeep:(BOOL)deepCopy;
{
id res = [[self.class alloc] init];
unsigned int count = 0;
Ivar *ivars = class_copyIvarList(self.class, &count);
for (unsigned int i = 0; i < count; i++) { …Run Code Online (Sandbox Code Playgroud)