I am receiving frames of H264 video in C++ code from a camera which is connected to my PC via USB. See below my pseudo code:
class VideoServer {
public:
VideoServer() {
std::string write_pipe =
"appsrc ! video/x-raw,format=BGR ! queue ! videoconvert ! x264enc bitrate=5000 ! mpegtsmux alignment=7 ! "
"rndbuffersize max=1316 min=1316 ! udpsink host=127.0.0.1 port=5004";
writer = std::make_unique<cv::VideoWriter>(write_pipe, cv::CAP_GSTREAMER, 0, fps_, cv::Size(width_, height_));
writer->isOpened()
}
void VideoDataCallack(const uint8_t *data, size_t size,
int64_t timestamp) override {
std::cout << "At timestamp: " << timestamp << " video data of size " << size << " received." << std::endl;
// write_to_stream(data, sizeof(uint8_t), size, ptr_);
writer->write(h264_frame);
}
private:
std::unique_ptr<cv::VideoWriter> writer;
};
I am able to receive video data on terminal as reported by std::cout
. I want to stream this video over the local network using UDP (or any real-time protocol say RTMP). I am targeting for minimal latency.
BTW, I tried the following pipe in terminal and I could see dummy output in VLC:
gst-launch-1.0 -vv -e videotestsrc ! queue ! x264enc bitrate=1024 speed-preset=superfast qp-min=30 tune=zerolatency ! mpegtsmux alignment=7 ! rndbuffersize max=1316 min=1316 ! udpsink host=127.0.0.1 port=5004
Thanks