Dynamically record a h264 stream
Davide Tuccilli
tuccio89 at hotmail.com
Fri Mar 18 03:59:05 UTC 2016
I have a pipeline like this:
v4l2src device=/dev/video0 ! video/x-h264 ! tee ! queue ! h264parse !
omxh264dec ! glimagesink
And the stream is correctly displayed. I want to dynamically attach a
branch to the tee to save the stream into a mp4 file, and I'm using this
code to attach the recording branch:
m_recordPad = gst_element_get_request_pad(m_tee, "src_%u");
GstElement * queue = gst_element_factory_make("queue", "recqueue");
GstElement * h264parse = gst_element_factory_make("h264parse",
"rech264parse");
GstElement * mux = gst_element_factory_make("mp4mux", "recmux");
GstElement * fileSink = gst_element_factory_make("filesink",
"recfilesink");
g_object_set(G_OBJECT(fileSink), "location", filename, nullptr);
gst_bin_add_many(GST_BIN(m_pipeline), queue, h264parse, mux,
fileSink, nullptr);
if (gst_element_link_many(queue, h264parse, mux, fileSink, nullptr)) {
GstPad * sinkpad = gst_element_get_static_pad(queue, "sink");
gst_element_sync_state_with_parent(queue);
gst_element_sync_state_with_parent(h264parse);
gst_element_sync_state_with_parent(mux);
gst_element_sync_state_with_parent(fileSink);
if (!GST_PAD_LINK_FAILED(gst_pad_link(m_recordPad, sinkpad))) {
return true;
}
gst_object_unref(sinkpad);
}
return false;
It should be extremely similiar to what I've found here
https://coaxion.net/blog/2014/01/gstreamer-dynamic-pipelines/
Now, when I try to start recording, every frame is dropped with messages
like this:
0:01:23.413955057 1546 0x6bb03340 WARN h264parse
gsth264parse.c:1205:gst_h264_parse_handle_frame:<rech264parse>
broken/invalid nal Type: 1 Slice, Size: 6860 will be dropped
Am I doing this wrong? How can h264parse fail on the recording branch
when it succeeds on the decoding one?
More information about the gstreamer-devel
mailing list