I am trying to get the i-frames of a video using opencv.
I have read that the header of a keyframe should look like this: b'\x00\x00\x01\xb0', but the problem I am facing is that I can not seem to find the header of the frame if I just do something like this:
我正在尝试使用OpenCV获取视频的I帧。我读到关键帧的标题应该是这样的:B‘\x00\x00\x01\xb0’,但我面临的问题是,如果我只是这样做,似乎找不到帧的标题:
while True:
ret, frame = vid.read()
if ret == False:
break
print(bytes(frame))
I did not find anything that can locate keyframes only ffprobe and I am trying to find something else to use, if there is a library of something please let me know!
我没有找到任何可以定位关键帧的东西,我正在尝试找到其他的东西来使用,如果有什么东西的库,请让我知道!
Got back something that starts like this:
我得到了一些像这样开始的东西:
b'YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YK<YL:YL:YM9YM9YM9YM9YM9YM9YM9YM9YM9YM9YM9YM9ZN:ZN:ZN:[O;[O;[O;[O;[O;[N<[N<[M>[M>[L?[L?[L?[L?[L?[L?YN>YN>VN;VN;UM:UM:TJ<TJ<TJ<TJ<SH?SH?SH?QF=QF=QF=PE:OD9ND6MC5LB4I?1E:1C8/B42B42@14?03?03?03@14?03<02<026,.4*,3)+0&(-#%,"$)\x1f!\'\x1d\x1f%\x1b\x1d#\x19\x1b"\x18\x1a#\x19\x1b!\x19\x1b$\x1c\x1e% \x1f&! \x1e\x1a\x1d\x1b\x17\x1a\x18\x14\x16\x14\x10\x0f\r\t\x0b\t\x05\x07\x05\x01\x07\x05\x01\x06\x04\x00\x05\x03\x00\x04\x02\x00\x03\x01\x00\x03\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 ......
更多回答
"can not seem to find the header of the frame" -- you're definitely not going to find it in the already decoded pixel buffer that vid.read()
returns.
“似乎找不到帧的头”--您肯定不会在vid.read()返回的已经解码的像素缓冲区中找到它。
优秀答案推荐
I Like pyav for more flexible things like U want.
我喜欢更灵活的东西,比如你想要的东西。
you got raw frame data because its already Decoded, so there are no nal unit Headers anymore.
你得到了原始的帧数据,因为它已经被解码了,所以不再有NAL单元头。
import av
container = av.open(path_to_video)
for frame in container.decode(video=0):
if frame.key_frame:
frame_bytes = bytes(frame)
更多回答
我是一名优秀的程序员,十分优秀!