I have written a C++ code using a GStreamer pipeline that takes a UDP stream as input and writes the frames into JPEG images. However, some of the output images have scattered pixels and are also blurr, and I’m not sure what’s causing this issue. The input video which used in udp stream is clear and high-quality video and it is 1fps, H264 (baseline) video. We are using ubuntu 20.04 on Virtual Box.
1st code is a server code which creates udp stream from input video.
int main(int argc, char *argv[]) {
gst_init(&argc, &argv);
// path to your video file
const char *video_path = "./data/test_video.mp4";
// the host address
const char *host_address = "224.1.1.1";
//the port
int port = 5000;
GstElement *pipeline = gst_parse_launch(
g_strdup_printf("filesrc location=%s ! qtdemux ! rtph264pay config-interval=1 ! udpsink host=%s port=%d auto-multicast=true", video_path, host_address, port), NULL);
}
then 2nd code consumes this stream and write frames into jpeg images.
static GstFlowReturn new_sample(GstElement *sink, gpointer user_data) {
static int frame_count = 1;
GstSample *sample;
GstBuffer *buffer;
GstMapInfo map;
g_signal_emit_by_name(sink, "pull-sample", &sample);
if (sample) {
buffer = gst_sample_get_buffer(sample);
gst_buffer_map(buffer, &map, GST_MAP_READ);
std::string directory = "output/";
std::string filename = directory + "frame_" + std::to_string(frame_count) + ".jpg";
std::ofstream file(filename, std::ios::binary);
file.write(reinterpret_cast<const char *>(map.data), map.size);
file.close();
frame_count++;
}
}
int main(int argc, char *argv[]) {
gst_init(&argc, &argv);
const gchar *pipeline_str =
"udpsrc multicast-group=224.1.1.1 auto-multicast=true port=5000 "
"caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" "
"! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! videorate ! video/x-raw, framerate=1/1 ! jpegenc ! appsink name=sink sync=false";
}
The code correctly writes the frames to the specified path. However, some of the output JPEG images contain scattered pixels and artifacts.
Any insights into what might be causing these issues and how to resolve them would be greatly appreciated.
This is the Jpeg image we get from our pipeline. I have put bounding box on the area where pixels are scattered
This the expected image
sonusi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3