0

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

NicoNing
  • 3,076
  • 12
  • 23
  • you claim it failed yet I don't see an error message. curious. pls provide one, or go into detail on what happened. – Christoph Rackwitz Nov 30 '21 at 10:46
  • in principle your code looks similar to which I do, did your raw bytes include Nal units and sps PPS information ? – Christoph Jan 10 '22 at 17:48
  • @Christoph I don't sure if the raw bytes include Nal units and sps PPS. I will check it , thank you for your tips . And , it didn't raise a Exception but it just not work, so it make me very confused . (because if it raise error , I can try to fix error.) – NicoNing Mar 24 '22 at 14:12
  • @Christoph Do you have any good tools/docs/web-site/git to analyze the raw frame ? I am a newbie to VideoDecode ... – NicoNing Mar 24 '22 at 14:24
  • 1
    Look into this Post https://stackoverflow.com/questions/24884827/possible-locations-for-sequence-picture-parameter-sets-for-h-264-stream/24890903#24890903 you can use a HEX viewer to check your data – Christoph Mar 25 '22 at 14:51

0 Answers0