Rtspvideoplugin -
extern "C" __declspec(dllexport) void* CreateRTSPPlayer() return new FFmpegRTSPDecoder(); __declspec(dllexport) bool OpenStream(void* player, const char* url) return ((FFmpegRTSPDecoder*)player)->open(url);
Use OBS's obs_source_info structure:
def start(self): self.cap = cv2.VideoCapture(self.url, cv2.CAP_FFMPEG) # Set options self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('H','2','6','4')) self.running = True Thread(target=self._update, daemon=True).start() def _update(self): while self.running: ret, self.frame = self.cap.read() if not ret: self.cap.release() self.cap = cv2.VideoCapture(self.url) # Reconnect def get_frame(self): return self.frame rtspvideoplugin
RTSPVideoPlugin() = default; ~RTSPVideoPlugin() stop();
bool connect(const std::string& url, FrameCallback callback) m_callback = callback; m_url = url; // 1. Parse URL (rtsp://ip:port/path) // 2. Open TCP socket to server:554 // 3. Send OPTIONS, DESCRIBE, SETUP, PLAY (see full code in repo) // 4. Start receive thread m_running = true; m_thread = std::thread(&RTSPVideoPlugin::receiveLoop, this); return true; Send OPTIONS, DESCRIBE, SETUP, PLAY (see full code
void stop() m_running = false; if (m_thread.joinable()) m_thread.join();
void Start() player = CreateRTSPPlayer(); OpenStream(player, "rtsp://192.168.1.100/stream"); videoTexture = new Texture2D(1920, 1080, TextureFormat.RGB24, false); GetComponent<Renderer>().material.mainTexture = videoTexture; m_thread = std::thread(&RTSPVideoPlugin::receiveLoop
; 4.1 Unity Plugin (C++ -> C#) Expose C functions:
