diff --git a/src/C++/Driver/src/main.cpp b/src/C++/Driver/src/main.cpp index 9947f31..faabda2 100644 --- a/src/C++/Driver/src/main.cpp +++ b/src/C++/Driver/src/main.cpp @@ -289,12 +289,23 @@ void sendKobukiData(TKobukiData &data) { } void CapnSend() { - VideoCapture cap(0); + int fps = 15; + int width = 800; + int height = 600; + + VideoCapture cap("/dev/video0"); if (!cap.isOpened()) { cerr << "Error: Could not open camera" << endl; return; } + VideoWriter out("appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=" + to_string(fps * 2) + " ! video/x-h264,profile=baseline ! rtspclientsink location=rtsp://localhost:8554/mystream", + CAP_GSTREAMER, 0, fps, Size(width, height), true); + if (!out.isOpened()) { + cerr << "Error: Can't open video writer" << endl; + return; + } + Mat frame; while (true) { cap >> frame; // Capture a new image frame @@ -303,15 +314,10 @@ void CapnSend() { continue; } - // Convert the image to a byte array - vector buf; - imencode(".jpg", frame, buf); - auto* enc_msg = reinterpret_cast(buf.data()); - - // Publish the image data - client.publishMessage("kobuki/cam", string(enc_msg, enc_msg + buf.size())); + // Write the frame to the RTSP stream + out.write(frame); cout << "Sent image" << endl; - std::this_thread::sleep_for(std::chrono::milliseconds(200)); // Send image every 200ms + std::this_thread::sleep_for(std::chrono::milliseconds(1000 / fps)); // Control the frame rate } } \ No newline at end of file