[Python] How i can use hardware decode h264

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am decoding a H264 stream using python av,but it can not use gpu,so i want to use Deffcode or other to instead.But I can't make the h264 frame as the input of Deffcode.

    codec = CodecContext.create("h264", "r")
    while self.alive:
    try:
    raw_h264 = self.__video_socket.recv(0x10000)
    if raw_h264 == b"":
    raise ConnectionError("Video stream is disconnected")
    packets = codec.parse(raw_h264)
    for packet in packets:
    frames = codec.decode(packet)
    for frame in frames:
    frame = frame.to_ndarray(format="bgr24")
    if self.flip:
    frame = frame[:, ::-1, :]
    self.last_frame = frame
    self.resolution = (frame.shape[1], frame.shape[0])
    self.__send_to_listeners(EVENT_FRAME, frame)
    except (BlockingIOError, InvalidDataError):
    time.sleep(0.01)
    if not self.block_frame:
    self.__send_to_listeners(EVENT_FRAME, None)
    except (ConnectionError, OSError) as e: # Socket Closed
    if self.alive:
    self.__send_to_listeners(EVENT_DISCONNECT)
    self.stop()
    raise e

    Continue reading...

Compartilhe esta Página