flandre/test/legacy/test_ffmpeg_stdout.py

28 lines
652 B
Python
Raw Normal View History

2025-04-26 13:25:06 +08:00
import subprocess
import cv2
import numpy as np
cv2.namedWindow('video', cv2.WINDOW_AUTOSIZE)
def f1():
p = subprocess.Popen([
'ffmpeg',
'-loglevel', 'quiet',
'-flags', 'low_delay',
'-fflags', 'nobuffer',
'-i', 'rtsp://admin:ab12ab12@11.6.2.4:554/h264/ch1/main/av_stream',
'-pix_fmt', 'rgb24',
'-f', 'rawvideo',
'-'
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
b = p.stdout.read(1920 * 1080 * 3)
cv2.imshow('video', np.frombuffer(b, dtype=np.uint8).reshape((1080, 1920, 3)))
cv2.waitKey(1)
if __name__ == '__main__':
f1()