从子流程标准输出解码原始H264帧

我正在尝试使用python从子进程的原始h264流中提取帧。该代码旨在用于流式传输Android屏幕,它基于休闲命令

adb exec-out screenrecord --output-format h264 --size 640x310 - | ffmpeg -i - -f sdl -

下面可以看到python代码:

import av
import subprocess as sp
import logging


adbcmd = ['adb','exec-out','screenrecord','--output-format=h264','-']
stream = sp.Popen(adbcmd,stdout = sp.PIPE,universal_newlines = True,errors='replace')

class H264Decoder:
    def __init__(self):
        self.codec = av.CodecContext.create("h264","r")

    def decode(self,encoded_frame):
        try:
            packet = av.Packet(encoded_frame)
            # packet.pts = encoded_frame.timestamp
            packet.time_base = VIDEO_TIME_BASE
            frames = self.codec.decode(packet)
        except av.AVError as e:
            logger.warning("failed to decode,skipping package: " + str(e))
            return []

        return frames


while True:
  line = stream.stdout.readline(4096)
  decoder = H264Decoder()
  decoder.decode(u' '.join(line).encode('utf-8').strip())
  if not line:
    break

输出是休闲的

No start code is found.
Error splitting the input into NAL units.
failed to decode,skipping package: [Errno 1094995529] Invalid data found when processing input (16: h264)
line
shi443213174 回答:从子流程标准输出解码原始H264帧

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2960268.html

大家都在问