python如何调用在ROC-RK3568-PC盒子中调用ffmpeg?
python如何调用在ROC-RK3568-PC盒子中调用ffmpeg?需求:想在python代码中通过ffmpeg拉rtsp流;因为固件中自带ffmpeg,且有h264---rkmmp视频流解码。
目前以下测试代码不行,请大神指点。
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import subprocess
import cv2
import numpy as np
rtspUrl: str = 'rtsp://admin:js123456@192.168.8.216:554/h264/ch1/main/av_stream'
width, height = 2160, 3840
command: list = ['ffmpeg', '-i', rtspUrl, '-loglevel', 'verbose', '-f', 'image2pipe', '-']
def display_video():
# 启动FFmpeg子进程
ffmpeg_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
# 通过管道逐帧读取流数据
while True:
# 从子进程标准输出流读取一帧数据
frame_data = ffmpeg_process.stdout.read(width * height * 3)# 假设图像宽高为width和height
if len(frame_data) != width * height * 3:
break
# 将原始数据转换为OpenCV格式
frame = np.frombuffer(frame_data, dtype=np.uint8).reshape((height, width, 3))
# 在窗口中显示帧
cv2.imshow('Frame', frame)
# 按下'q'键退出循环
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 清理资源
ffmpeg_process.kill()
cv2.destroyAllWindows()
if __name__ == '__main__':
try:
display_video()
except Exception as e:
print(e)输出结果
qt.qpa.xcb: QXcbConnection: XCB error: 148 (Unknown), sequence: 185, resource id: 0, major code: 140 (Unknown), minor code: 20过一会儿进程就自己断掉了,是写法上哪里不对吗?
有没有大神有例子的,带带~~~
每日一顶~~~
每日一顶~~~ 每日一顶~~~ 每日一顶~~~ 每日一顶~~~ 每日一顶~~~
页:
[1]