每当我尝试用ffmpeg获取有关我的视频文件的一些信息时,它就会把很多无用的信息与好东西混在一起.
我正在使用ffmpeg -i name_of_the_video.mpg
.
有可能以友好的方式获得它吗?我的意思是JSON会很棒(甚至丑陋的XML也很好).
到目前为止,我让我的应用程序使用正则表达式解析数据,但在某些特定的视频文件中出现了许多令人讨厌的角落.我修复了我遇到的所有问题,但可能会有更多.
我想要的东西:
{
"Stream 0": {
"type": "Video",
"codec": "h264",
"resolution": "720x480"
},
"Stream 1": {
"type": "Audio",
"bitrate": "128 kbps",
"channels": 2
}
}
Run Code Online (Sandbox Code Playgroud) 什么是最好的纯Python实现来检查字符串是否包含字母表中的任何字母?
string_1 = "(555).555-5555"
string_2 = "(555) 555 - 5555 ext. 5555
Run Code Online (Sandbox Code Playgroud)
如果没有字母表中的字母,string_1
将返回哪里False
,string_2
并将返回True
有信.
考虑一个简单的函数
def increment(self):
self.count += 1
Run Code Online (Sandbox Code Playgroud)
它通过Cython运行并编译成扩展模块.假设现在我想把这个函数作为一个类的方法.例如:
class Counter:
def __init__(self):
self.count = 0
from compiled_extension import increment
Counter.increment = increment
Run Code Online (Sandbox Code Playgroud)
现在这不起作用,因为C级别的调用约定将被打破.例如:
>>> c = Counter()
>>> c.increment()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: increment() takes exactly one argument (0 given)
Run Code Online (Sandbox Code Playgroud)
但是在Python 2中,我们可以通过执行以下操作将函数转换为未绑定的方法:
Counter.increment = types.MethodType(increment, None, Counter)
Run Code Online (Sandbox Code Playgroud)
我怎样才能在Python 3中完成同样的事情?
一种简单的方法是使用纤薄的包装:
from functools import wraps
def method_wraper(f):
def wrapper(*args, **kwargs):
return f(*args, **kwargs)
return wraps(f)(wrapper)
Counter.increment = method_wrapper(increment)
Run Code Online (Sandbox Code Playgroud)
有更有效的方法吗?
我正在尝试在我的应用上启用应用内购买项目(已在Windows 10商店中),但在尝试购买此项目时,我始终收到相同的错误消息:
MyAppName中不再提供此应用内购买项目
代码非常简单,只是文档推荐的内容:
var itemName = "app.advanced_items.full";
if (CurrentApp.LicenseInformation.ProductLicenses[itemName].IsActive) {
return true;
}
var results = await CurrentApp.RequestProductPurchaseAsync(itemName);
if (results.Status == ProductPurchaseStatus.Succeeded ||
results.Status == ProductPurchaseStatus.AlreadyPurchased) {
return true;
} else {
return false;
}
Run Code Online (Sandbox Code Playgroud)
更多信息:
itemName
上的项目名称相同(代码上)我怀疑问题可能与以下内容有关:
Package.appxmanifest
)与商店中的应用程序名称不同(我想要的名称不可用,因此我将其设置得更长,但安装后的应用程序将显示原始名称).这个较短的名称是错误消息中的名称...我将"显示名称"更改为应用程序的全名,但错误是相同的.我不知道是否将它发送到商店可能会改变这一点(我并不想为了测试这个理论而部署另一个错误的版本)
额外:我在网上找到的关于这个问题的唯一资源是无用的,与Windows 8相关:链接
建议?
我正在尝试在图像上应用Sobel滤镜以使用scipy来检测边缘.我在Windows 7旗舰版(64位)上使用Python 3.2(64位)和scipy 0.9.0.目前我的代码如下:
import scipy
from scipy import ndimage
im = scipy.misc.imread('bike.jpg')
processed = ndimage.sobel(im, 0)
scipy.misc.imsave('sobel.jpg', processed)
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,但处理过的图像看起来并不像它应该做的那样.图像'bike.jpg'是灰度(模式'L'而非'RGB')图像,因此每个像素只有一个与之关联的值.
不幸的是我还没有在这里发布图片(没有足够的声誉),但我提供了以下链接:
原始图像(bike.jpg):http://s2.postimage.org/64q8w613j/bike.jpg
Scipy Filtered(sobel.jpg):http://s2.postimage.org/64qajpdlb/sobel.jpg
预期产出:http: //s1.postimage.org/5vexz7kdr/normal_sobel.jpg
我显然在某个地方出错了!有人可以告诉我在哪里.谢谢.
我有一个课程需要为每个操作员制作一些魔法,比如__add__
,__sub__
等等.
我没有在类中创建每个函数,而是使用了一个元类来定义运算符模块中的每个运算符.
import operator
class MetaFuncBuilder(type):
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
attr = '__{0}{1}__'
for op in (x for x in dir(operator) if not x.startswith('__')):
oper = getattr(operator, op)
# ... I have my magic replacement functions here
# `func` for `__operators__` and `__ioperators__`
# and `rfunc` for `__roperators__`
setattr(self, attr.format('', op), func)
setattr(self, attr.format('r', op), rfunc)
Run Code Online (Sandbox Code Playgroud)
该方法工作正常,但我认为如果我只在需要时生成替换运算符会更好.
运营商的查询应该是元类,因为x + 1
做的type(x).__add__(x,1)
,而不是x.__add__(x,1)
,但它不会被抓到__getattr__
,也没有__getattribute__
方法.
这不起作用:
class Meta(type):
def …
Run Code Online (Sandbox Code Playgroud) 我试图将C样式const char []字符串指针(从DLL返回)转换为Python兼容的字符串类型.但是当Python27执行时:
import ctypes
charPtr = ctypes.cast( "HiThere", ctypes.c_char_p )
print( "charPtr = ", charPtr )
Run Code Online (Sandbox Code Playgroud)
我们得到: charPtr = c_char_p('HiThere')
也许某些事情无法正确评估.我的问题是:
我有一个像这个例子中的字典列表:
listofdict = [{'name': 'Foo', 'two': 'Baz', 'one': 'Bar'}, {'name': 'FooFoo', 'two': 'BazBaz', 'one': 'BarBar'}]
Run Code Online (Sandbox Code Playgroud)
我知道每个字典(以及其他键)中都存在'name',并且它是唯一的,并且不会出现在列表中的任何其他字典中.
我想通过使用键'name'来访问'two'和'one'的值.我想字典词典会最方便吗?喜欢:
{'Foo': {'two': 'Baz', 'one': 'Bar'}, 'FooFoo': {'two': 'BazBaz', 'one': 'BarBar'}}
Run Code Online (Sandbox Code Playgroud)
有了这个结构,我可以轻松地遍历名称,并通过使用名称作为键来获取其他数据.您对数据结构有任何其他建议吗?
我的主要问题是:进行这种转变的最好和最恐怖的方法是什么?
我有一些这样的board
numpy数组:
array([[0, 0, 0, 1, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 1, 0, 0]])
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码来查找每个第n个对角线上从-7到8(以及它的镜像版本)的元素总和.
n = 8
rate = [b.diagonal(i).sum()
for b in (board, board[::-1])
for …
Run Code Online (Sandbox Code Playgroud) 我有一个Cortana XML文件,我需要输入一个数字.我该怎么做才能确保将其转换为数字?
<Command Name="AddMoney">
<Example> Add 10 dollars </Example>
<ListenFor> add {amount} {currency} </ListenFor>
<Feedback> Adding some money </Feedback>
<Navigate/>
</Command>
<PhraseList Label="currency">
<item>dollar</item>
<item>euro</item>
<item>pound</item>
</PhraseList>
<PhraseList Label="amount">
</PhraseList>
Run Code Online (Sandbox Code Playgroud)