我找不到任何可以帮助我解决此类问题的方法:我正在尝试获取作为嵌套结构一部分的属性的偏移量,例如:
数据类型.py
class FirstStructure (ctypes.Structure):
_fields_ = [('Junk', ctypes.c_bool),
('ThisOneIWantToGet', ctypes.c_int8)
]
class SecondStructure (ctypes.Structure):
_fields_ = [('Junk', ctypes.c_double),
('Example', FirstStructure)
]
Run Code Online (Sandbox Code Playgroud)
重要的是,我只知道父结构的名称,SecondStructure我完全不知道那里可以有多少嵌套结构。
我想在这里做的是ThisOneIWantToGet从SecondStructure.
我知道有一种ctypes.adressof方法适用于 ctypes 对象。有没有什么简单的方法来获取嵌套参数的对象,所以我可以做这样的事情:
do_something.py
import data_types as dt
par_struct_obj = getattr(dt, 'SecondStructure')
par_obj = getattr(par_struct_obj , 'ThisOneIWantToGet')
print ctypes.addressof(parameter) - ctypes.addressof(parent_structure)
Run Code Online (Sandbox Code Playgroud) 我在这里有点困惑,不太确定这一点。我想要做的是通过terminal/传递文件的名称,该文件cmd将被打开和读取。
myfunction(char* fileName, FILE* readFile)
{
if((readFile = fopen(fileName,"r")) == NULL)
{
return FILE_ERROR;
}
return FILE_NO_ERROR;
}
int main(int argc, char **argv)
{
FILE* openReadFile;
if(myfunction(argv[1], openReadFile) != FILE_NO_ERROR)
{
printf("\n %s : ERROR opening file. \n", __FUNCTION__);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我传递一个指针openReadFile,myfunction()将readFile指向打开文件的指针保存到openReadFile指针中,还是*readFile在打开时需要放置。
我正在开发一个需要打开.mp4文件格式的项目,逐个读取它的帧,解码它们并用更好的无损压缩类型对它们进行编码并将它们保存到文件中.
如果我对做事的顺序错了,请纠正我,因为我不是100%确定应该怎么做这件事.根据我的理解,它应该是这样的:
1. Open input .mp4 file
2. Find stream info -> find video stream index
3. Copy codec pointer of found video stream index into AVCodecContext type pointer
4. Find decoder -> allocate codec context -> open codec
5. Read frame by frame -> decode the frame -> encode the frame -> save it into a file
Run Code Online (Sandbox Code Playgroud)
到目前为止,我遇到了几个问题.例如,如果我想使用av_interleaved_write_frame()函数保存框架,我无法打开输入.mp4文件,avformat_open_input()因为它将使用输入文件名填充结构的filename一部分,AVFormatContext因此我无法"写入"该文件.我尝试过不同的解决方案,av_guess_format()但是当我使用i转储格式时,我dump_format()什么都没得到,所以我找不到关于它使用哪种编解码器的流信息.
所以如果有人有任何建议,我会非常感激他们.先感谢您.
我正在尝试将帧数据从AVFrame结构复制到缓冲区。我知道如何使用YUV420P格式来做到这一点,因为 Y 数据存储在内部AVFrame frame->data[0],U 数据存储在内部AVFrame frame->data[1],V 数据存储在内部AVFrame frame->data[2],因此很容易memcpy()单独处理 Y、U 和 V 数据+它是平面格式,所以我能够做到这一点轻松:
for (y = 0; y < height; y++)
{
memcpy(buffer + y*frame->linesize[0], frame->data[0] + y*frame->linesize[0], width);
}
buffer += ySize;
for (y = 0; y < height / 2; y++)
{
memcpy(buffer + y*frame->linesize[1], frame->data[1] + y*frame->linesize[1], width / 2);
}
buffer += uSize;
for (y = 0; y < height / 2; y++)
{
memcpy(buffer …Run Code Online (Sandbox Code Playgroud) 有没有办法在 python 中做类似的事情?
def foo(str(arg).lower()):
print arg
foo('LOL')
Run Code Online (Sandbox Code Playgroud)
我首先想创建装饰器,但无论我尝试什么,我都无法让它按我想要的方式工作,我要么返回生成器,要么列出生成器。
编辑:这就是我想要完成的。
def to_lowercase(function):
def wrapper(*args):
return function(*[x.lower() if isinstance(x, str) else x for x in args])
return wrapper
Run Code Online (Sandbox Code Playgroud) 这是以下问题:
main_module.py
from collections import OrderedDict
from my_other_module import foo
a = OrderedDict([
('a', 1),
('b', 2),
('c', 3),
('d', 4),
])
foo(**a)
Run Code Online (Sandbox Code Playgroud)
my_other_module.py
def foo(**kwargs):
for k, v in kwargs.items():
print k, v
Run Code Online (Sandbox Code Playgroud)
当我运行时,main_module.py我希望按照我指定的顺序打印输出:
a 1
b 2
c 3
d 4
Run Code Online (Sandbox Code Playgroud)
但相反,我得到:
a 1
c 3
b 2
d 4
Run Code Online (Sandbox Code Playgroud)
我确实理解这与**操作符的实现方式有关,并且它以某种方式丢失了字典对传入的顺序.我也明白python中的字典不是按列表排序的,因为它们是作为哈希表实现的.是否有任何类型的"黑客"我可以应用,所以我得到了在这种情况下所需的行为?
PS - 在我的情况下,我无法对foo函数内的字典进行排序,因为除了传递值的严格顺序之外,没有可遵循的规则.
python ×3
c ×2
ffmpeg ×2
libavcodec ×2
ctypes ×1
dictionary ×1
libav ×1
mp4 ×1
pointers ×1
video ×1