简体   繁体   English

使用Python在以太网上实现高FPS直播

[英]High FPS livestream over ethernet using Python

I plan on building a ROV and I am working on my video feed atm. 我计划建立ROV,并且正在处理视频提要atm。 I will be using fiber optics for all communications and I am tinkering with opencv to stream a webcam feed with python. 我将使用光纤进行所有通信,并且我将修改opencv以使用python传输网络摄像头。 I might choose to use IP cameras but I wanted to learn more about how to capture frames from a webcam in python first. 我可能会选择使用IP摄像机,但我想了解更多有关如何首先使用python从网络摄像机捕获帧的信息。 Since I didn't know what I was going to use in the end I bought a cheap-as-they-get noname USB webcam just to try and get everything working. 由于最终我不知道要使用什么,所以我买了一个便宜的无名USB网络摄像头,只是为了使所有功能正常工作。 This camera feed is going to be used for navigation, a seperate video recorder will probably be used for recording video. 该摄像机供稿将用于导航,可能会使用单独的录像机来录制视频。

Enough about that, now to my issue. 够了,现在到我的问题。 I am getting only 8 FPS when I am capturing the frames but I suspect that is due to the cheap webcam. 捕获帧时,我只有8 FPS,但我怀疑这是由于廉价的网络摄像头造成的。 The webcam is connected to a pcduino 3 nano which is connected to a arduino for controlling thrusters and reading sensors. 网络摄像头连接到pcduino 3 nano,后者连接到用于控制推进器和读取传感器的arduino。 I never thought of how to utilize hardware in encoding and decoding images, I don't know enough about that part yet to tell if I can utilize any of the hardware. 我从没想过如何利用硬件对图像进行编码和解码,对此我还不了解,是否可以利用任何硬件。

Do you guys believe it's my web cam that is the bottleneck? 你们相信瓶颈是我的网络摄像头吗? Is it a better idea to use a IP camera or should I be able to get a decent FPS using a webcam connected to a pcduino 3 nano capturing frames with opencv or perhaps some other way? 使用IP摄像机是一个更好的主意吗?或者我应该能够通过使用opencv或其他方法连接到pcduino 3 nano捕获帧的网络摄像机获得像样的FPS吗? I tried capturing frames with Pygame which gave me the same result, I also tried mjpg-streamer. 我尝试使用Pygame捕获帧,这给了我相同的结果,我也尝试了mjpg-streamer。

Im programming in Python, this is the test I made: 我正在用Python编程,这是我所做的测试:

import cv2, time
FPS = 0
cap = cv2.VideoCapture(0)

last = time.time()

for i in range(0,100):
    before = time.time()
    rval, frame = cap.read()
    now = time.time()
    print("cap.read() took: " + str(now - before))
    if(now - last >= 1):
        print(FPS)
        last = now
        FPS = 0
    else:
        FPS += 1
cap.release()

And the result is in the line of: 结果在以下行中:

cap.read() took: 0.118262052536
cap.read() took: 0.118585824966
cap.read() took: 0.121902942657
cap.read() took: 0.116680860519
cap.read() took: 0.119271993637
cap.read() took: 0.117949008942
cap.read() took: 0.119143009186
cap.read() took: 0.122378110886
cap.read() took: 0.116139888763
8

The webcam should explicitly state its frame rate in its specifications, and that will definitively tell you whether the bottleneck is the camera. 网络摄像头应在其规格中明确说明其帧速率,这将明确告诉您瓶颈是否是摄像头。

However, I would guess that the bottleneck is the pcDuino3. 但是,我猜想瓶颈是pcDuino3。 Most likely it can't decode the video very fast and that causes the low frame rate. 它很可能无法非常快速地解码视频,从而导致较低的帧速率。 You can try this exact code on an actual computer to verify this. 您可以在实际的计算机上尝试使用此确切的代码进行验证。 Also, I believe OpenCV and mjpg-streamer both use libjpeg to decode the jpeg frames, so their similar frame rate is not surprising. 另外,我相信OpenCV和mjpg-streamer都使用libjpeg解码jpeg帧,因此它们相似的帧速率也就不足为奇了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM