I new to PyAV and need some help.
I need to use PyAV to decode H264 raw bytes from webscocket .
I read the docs and try to use CodecContext.parse to finished it but failded like this:
It won't raise exception or error, but it will success at some raw frames and not work at some other raw frames , and all the frames are KeyFrame(I) from A H264 video file (translate frame by frame on WebSocket Server).
import av
code_ctx = av.CodecContext.create("h264", "r")
code_ctx.pix_fmt = "yuv420p"
code_ctx.width = 1090
code_ctx.height = 1072
code_ctx.thread_type = "AUTO"
code_ctx.gop_size = 120
def test8(raw_bytes: bytes):
# packet = av.packet.Packet(fd1_bytes)
# print(type(packet))
packets = code_ctx.parse(raw_bytes)
## It should be decoded and results to a list a packets, but why it returns []
for i, packet in enumerate(packets):
print(type(packet))
frames = code_ctx.decode(packet)
for frame in frames:
print(type(frame), type(getattr(frame, "planes")))
which is refered from https://pyav.org/docs/develop/cookbook/basics.html