cv2.VideoWriter_fourcc的反面是什么? [英] What is the opposite of cv2.VideoWriter_fourcc?
问题描述
函数cv2.VideoWriter_fourcc从字符串(四个字符)转换为int.例如,cv2.VideoWriter_fourcc(*'MJPG')为编解码器MJPG(无论是哪种格式)提供了一个int.
The function cv2.VideoWriter_fourcc converts from a string (four chars) to an int. For example, cv2.VideoWriter_fourcc(*'MJPG') gives an int for codec MJPG (whatever that is).
cv2是否提供相反的功能?我想将值显示为字符串.我想从fourcc int值中获取一个字符串.
Does cv2 provide the opposite function? I'd like to display the value as a string. I'd like to get a string from a fourcc int value.
我可以自己编写转换,但是如果cv2存在,我会使用它.
I could write the conversion myself, but I'd use something from cv2 if it exists.
推荐答案
我认为cv2没有这种转换.这是如何从fourcc数字代码转换为fourcc字符串字符代码(假设数字是cv2.CAP_PROP_FOURCC返回的数字):
I don't think cv2 has that conversion. Here is how to convert from fourcc numerical code to fourcc string character code (assuming the numerical number is the one returned by cv2.CAP_PROP_FOURCC):
# python3
def decode_fourcc(cc):
return "".join([chr((int(cc) >> 8 * i) & 0xFF) for i in range(4)])
例如,如果您打开视频捕获流以获取有关编解码器的信息或获取有关特定编解码器的信息,则可以尝试以下操作:
So for example if you open a video capture stream to get info about the codec or to get info about a specific codec you could try this:
c = cv2.VideoCapture(0)
# codec of current video
codec = c.get(cv2.CAP_PROP_FOURCC)
print(codec, decode_fourcc(codec))
# codec of mjpg
codec = cv2.VideoWriter_fourcc(*'MJPG')
print(codec, decode_fourcc(codec))
这篇关于cv2.VideoWriter_fourcc的反面是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!