所以我现在要完成的工作是从树莓派相机获取h264流以在Windows Media Player中播放。我从PiCamera Documentation
获得了代码import socket
import subprocess
# Start a socket listening for connections on 0.0.0.0:8000 (0.0.0.0 means
# all interfaces)
server_socket = socket.socket()
server_socket.bind(('0.0.0.0', 12345))
server_socket.listen(0)
# Accept a single connection and make a file-like object out of it
connection = server_socket.accept()[0].makefile('rb')
try:
# Run a viewer with an appropriate command line. Uncomment the mplayer
# version if you would prefer to use mplayer instead of VLC
#cmdline = ['vlc', '--demux', 'h264', '-']
cmdline = ['C:\Program Files\Windows Media Player\wmplayer', '-fps', '25', '-cache', '1024', '-']
player = subprocess.Popen(cmdline, stdin=subprocess.PIPE)
while True:
# Repeatedly read 1k of data from the connection and write it to
# the media player's stdin
data = connection.read(1024)
if not data:
break
player.stdin.write(data)
finally:
connection.close()
server_socket.close()
我得到的错误在这里
line 24, in <module>
player.stdin.write(data)
OSError: [Errno 22] Invalid argument
我正在运行32位Windows 10。
server.py文件位于我桌面上的文件夹中,我尝试将其移至python文件夹时没有运气。我知道流通过是因为我可以在while循环中调用print(data)
,它开始打印掉所有字节码。我不确定从哪里开始此错误。我的第二个问题是,是否可以使用ffmpeg-python或cv2之类的东西来处理以帧为单位的字节?因此,可以在GUI画布中使用它。