简体   繁体   English

使用h264编码流式传输openCV帧

[英]streaming openCV frame using h264 encoding

I created a python program using OpenCV and GStreamer to stream the frames to a GStreamer udpsink . 我使用OpenCV和GStreamer创建了一个python程序,以将帧流式传输到GStreamer udpsink Here is the code : 这是代码:

import cv2
import config

def send():

    cap = cv2.VideoCapture(0) #open the camera
    fourcc = cv2.VideoWriter_fourcc(*'H264')
    out = cv2.VideoWriter('appsrc ! videoconvert ! x264enc tune=zerolatency noise-reduction=10000 bitrate=2048 speed-preset=superfast ! rtph264pay config-interval=1 pt=96 ! udpsink host=127.0.0.1 port=5000',fourcc,config.CAP_PROP_FPS, (800,600),True) #ouput GStreamer pipeline

    if not out.isOpened():
        print('VideoWriter not opened')
        exit(0)

    while cap.isOpened():
        ret,frame = cap.read()

        if ret:


            # Write to pipeline
            out.write(frame)

            if cv2.waitKey(1)&0xFF == ord('q'):
                break

    cap_send.release()
    out_send.release()

send()

Then, in my terminal, my GStreamer receiver pipeline is : 然后,在我的终端中,我的GStreamer接收器管道为:

gst-launch-1.0 -v udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, payload=(int)96" ! rtph264depay ! decodebin ! videoconvert ! autovideosink

The problem is that the frames that I receive are like that : https://drive.google.com/open?id=14PeiGlEfcSuzRjSPENrCjGQIQk-04OHb 问题是我收到的框架像这样: https : //drive.google.com/open?id=14PeiGlEfcSuzRjSPENrCjGQIQk-04OHb

I guess it's all about color space conversion in openCV... What do you think ? 我想这全都与openCV中的色彩空间转换有关……您怎么看? Thank you ! 谢谢 !

Check the Video Resolution your camera is supporting . 检查相机支持的视频分辨率。

Example VGA : 640 x 480 VGA示例:640 x 480

Use the same resolution in your gstreamer pipeline. 在您的gstreamer管道中使用相同的分辨率。 ( Unless you are doing some rescaling) (除非您正在进行一些重新缩放)

with the 640x480 resolution, I can see some improvements but it's still far from being acceptable... (I put the link of the image here: https://drive.google.com/open?id=1YBNEKOcC9fK6hS5RatvkO9pjKhcbh6Eu ) 在640x480分辨率下,我可以看到一些改进,但仍远远不能接受...(我将图像的链接放在此处: https : //drive.google.com/open?id=1YBNEKOcC9fK6hS5RatvkO9pjKhcbh6Eu

But anyway, I found that for a 1280x720 resolution, it is pretty good! 但是无论如何,我发现对于1280x720的分辨率来说,这是相当不错的! Though, my camera is supporting other resolution (like 800x600 or 640x480) but there are not working as expected... 虽然,我的相机支持其他分辨率(例如800x600或640x480),但无法正常工作...

Thank you for all ! 感谢你所做的一切 !

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

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