Python : Using Pyside6 and gi for GStreamer : Image without color and duplication of image

I stream a video webcamera from another computer with GStreamer with that commande line :

gst-launch-1.0 -v v4l2src device=/dev/<video4> ! image/jpeg,width=640,height=480,framerate=30/1 ! jpegdec ! videoconvert ! x264enc bitrate=2000 speed-preset=ultrafast tune=zerolatency ref=4 qp-min=5 qp-max=10 ! rtph264pay config-interval=1 ! udpsink host=<ip_destination> port=<port_dest>

Then in my code I get the video stream with Gst :

"self.pipeline = Gst.parse_launch(udpsrc address={ip_address} port={port} ! application/x-rtp, encoding-name=H264 ! rtph264depay ! decodebin ! videoconvert ! jpegenc ! appsink name={name}")

Then I make some treatment on the stream to display the image on pyside6 and i got this

My entire code :

import cv2
import gi
from PySide6.QtWidgets import QVBoxLayout, QWidget
from PySide6.QtCore import QTimer
from PySide6.QtGui import QImage, QPixmap
from PySide6.QtWidgets import QLabel

gi.require_version("Gst", "1.0")
from gi.repository import Gst


class VideoStreamWidget(QWidget):
    def __init__(self, port, node, parent=None):
        super(VideoStreamWidget, self).__init__(parent)
        self.node = node
        Gst.init(None)

        # Set up the label to display the video frames
        self.video_label = QLabel(self)

        layout = QVBoxLayout()
        layout.addWidget(self.video_label)
        self.setLayout(layout)

        self.create_pipeline_gs(port)
        self.bus = self.pipeline.get_bus()
        self.bus.add_signal_watch()
        self.bus.connect("message::eos", self.on_eos)
        self.bus.connect("message::error", self.on_error)

        self.pipeline.set_state(Gst.State.PLAYING)

    def create_pipeline_gs(self, port):
        name = f"appsink{port}"
        self.pipeline = Gst.parse_launch(
            f"udpsrc address=127.0.0.1 port={port} ! application/x-rtp, encoding-name=H264 ! rtph264depay ! decodebin ! videoconvert ! jpegenc ! appsink name={name}"
        )
        self.appsink = self.pipeline.get_by_name(name)
        self.appsink.set_property('emit-signals', True)
        self.appsink.set_property('sync', False)
        self.appsink.connect("new-sample", self.on_new_sample)

    def on_new_sample(self, sink):
        sample = sink.emit("pull-sample")
        if sample:
            caps = sample.get_caps()
            buffer = sample.get_buffer()
            structure = caps.get_structure(0)
            width = structure.get_value("width")
            height = structure.get_value("height")

            success, map_info = buffer.map(Gst.MapFlags.READ)
            if success:
                image = QImage(
                    map_info.data, width, height, width * 3, QImage.Format_RGB888
                )
                pixmap = QPixmap.fromImage(image)
                self.video_label.setPixmap(pixmap)
                buffer.unmap(map_info)
        return 0

    def on_eos(self, bus, msg):
        print("End of stream")
        self.pipeline.set_state(Gst.State.NULL)

    def on_error(self, bus, msg):
        err, debug = msg.parse_error()
        print(f"Error: {err}")
        self.pipeline.set_state(Gst.State.NULL)

    def closeEvent(self, event):
        self.pipeline.set_state(Gst.State.NULL)
        event.accept()
        super(VideoStreamWidget, self).closeEvent(event)

I try my code without pyside6 just with flask and it’s working well.enter image description here

So i think it’s an issue with how I transform my image into QImage and QPixmap, but can not find solution to solve this issue.

New contributor

user26714515 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật