Live Video Streaming coming as RTSP URL
Unsolved
Qt for Python
-
Currently I am facing latency while I receive video in Qt from RTSP URL. Here is the code:
class Thread1(QThread): data_signal=pyqtSignal(str) is_running=True def __init__(self): super(Thread1, self).__init__() self.ser=serial.Serial("/dev/ttyACM0", 115200) def run(self): while True: #code to read the data and emit the signal self.data_signal.emit(self.line) def write_data(self, data): self.ser.write(data.encode()) def stop(self): self.is_running=False self.terminate() class Thread2(QThread): data_signal=pyqtSignal(object) is_running=True HOST = "127.0.0.6" PORT = 5001 def __init__(self): super(Thread2, self).__init__() self.client_socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.client_socket.connect((self.HOST, self.PORT)) def run(self): while True: #code to read the data and emit the signal self.data_signal.emit(self.t) def send_data(self, data): if self.is_running: self.client_socket.send(data) def stop(self): self.is_running=False self.terminate() class Thread3(QThread): data_signal=pyqtSignal(object) is_running=True def read(self): //reading keyboard buttons return (something) def run(self): while True: s=self.read() self.data_signal.emit(s) def stop(self): self.is_running=False self.terminate() class MainUI(QDialog): ImageUpdate = pyqtSignal(QImage) def __init__(self): super(MainUI, self).__init__() loadUi('UI.ui', self) self.media_player = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.media_player.setVideoOutput(self.video_label) media_content = QMediaContent(QUrl("rtsp://126.0.0.6:5000/test")) self.media_player.setMedia(media_content) self.timer = QTimer(self) #self.timer.timeout.connect(self.update_video_label) self.timer.start(0) # Set the update interval in milliseconds self.media_player.stateChanged.connect(self.on_state_changed) self.media_player.play() self.thread_1=Thread1() self.thread_3=Thread3() self.thread_2=Thread2() self.start_fetch_data() self.thread1.data_signal.connect(self.update_thread1) self.thread_3.data_signal.connect(self.update_thread3) self.thread_2.data_signal.connect(self.update_thread2) def start_fetch_data(self): self.thread_1.start() self.thread_3.start() self.thread_2.start() def update_thread2(self, data): data_transfer_variable=data self.thread_1.write_data(str(data_transfer_variable)) @pyqtSlot(str) def update_thread1(self, data): //data manipulation print(data) self.thread2.send_data(pickle.dumps(data)) def update_thread3(self, data): t=data def on_state_changed(self, state): if state == QMediaPlayer.StoppedState: print("Media player stopped") app=QApplication(sys.argv) mainwindow=MainUI() widget=QtWidgets.QStackedWidget() widget.addWidget(mainwindow) widget.show() app.exec_()
How can I achieve this live video feed with zero/negligible latency? Please suggest ways and sample code for it.