问题描述
假设有一些mov文件。我想知道每个mov使用的编解码器。 谁能帮我? 我需要获取图片中的“ h264”,而不是Input(AVC1)。
import cv2
import glob
mov_files = glob.glob('*.mp4')
for eachFile in mov_files:
cap = cv2.VideoCapture(eachFile)
file_length = cap.get(cv2.CAP_PROP_FRAME_COUNT)
print(file_length)
codec ??
print(codec)
解决方法
您可以使用以下方法找到视频编解码器的4个字符代码:
h = int(cap.get(cv2.CAP_PROP_FOURCC))
codec = chr(h&0xff) + chr((h>>8)&0xff) + chr((h>>16)&0xff) + chr((h>>24)&0xff)
更新:
使用OpenCV只能获取视频编解码器的FourCC信息。没有有关编解码器的更多信息。您可以参考链接:https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture
还有FourCC代码列表:http://www.fourcc.org/codecs.php
因此,根据这个问题,您只能使用OpenCV获得FourCC代码信息。有关编解码器的更多详细信息,您可能需要使用其他库。