You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been working to get PyAV to decode raw h264 output from adb(android debug bridge) + screenrecord open as a python subprocess. This code is meant to be used to stream android screen and it's is based on the fallowing ffmpeg command:
The fallowing python code was used. The main idea is to read Popen stdout and provide to pyAV decode the h264 frame.
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
Actual behavior
Traceback:
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
importsubprocessimportsysimportavclassWrapper:
""" Wrapper which only exposes the `read` method to avoid PyAV trying to use `seek`. """name="<wrapped>"def__init__(self, fh):
self._fh=fhdefread(self, buf_size):
returnself._fh.read(buf_size)
wrapper=Wrapper(sys.stdin.buffer)
withav.open(wrapper, "r") ascontainer:
forframeincontainer.decode():
print(frame)
Overview
I have been working to get PyAV to decode raw h264 output from adb(android debug bridge) + screenrecord open as a python subprocess. This code is meant to be used to stream android screen and it's is based on the fallowing ffmpeg command:
adb exec-out screenrecord --output-format h264 --size 640x310 - | ffmpeg -i - -f sdl -
The fallowing python code was used. The main idea is to read Popen stdout and provide to pyAV decode the h264 frame.
Actual behavior
Traceback:
Investigation
I got this code working using c++ and libavcodec, where the main idea is to decode raw h264 output from adb subprocess and save each frame as ppg image.
gist.github.com/fabriciopk/6f583f079bd929ccc708aa3d3cb37b59
The text was updated successfully, but these errors were encountered: