<div><div>Dear all,</div><div><br></div><div>I did not achieve to create full legible muxed files for Gstreamer 0.10 on top of multifilesink or output-selector.</div><div><br></div><div>After analysing lots of alternatives my solution takes as code base the example depicted in:</div>
<div><a href="http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-dynamic-pipelines.html">http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-dynamic-pipelines.html</a></div>
<div><br></div><div>The probes function API has been changed a bit but the solution below works to create every N seconds different MP4 files:</div><div><br></div><div><div>static GstElement *pipeline = NULL;</div><div><br>
</div><div>// Pipeline -> src -> dynamic pipeline</div><div>// Pipeline -> capsfilter(f264file) -> mp4mux(mux0) -> filesink(fsink0)</div><div>// Pipeline -> elem_before||blockpad| -> |elem_cur_sinkpad||elem_cur||elem_cur_srcpad -> |elem_cur_sinkpad||elem_cur</div>
<div>static gulong probe_id;<span class="Apple-tab-span" style="white-space:pre"> </span>// probe ID</div><div>static GstElement *elem_before;<span class="Apple-tab-span" style="white-space:pre"> </span>// SRC of dynamic pipeline</div>
<div>static GstElement *elem_after;<span class="Apple-tab-span" style="white-space:pre"> </span>// SINK of dynamic pipeline</div><div>static GstElement *elem_cur;<span class="Apple-tab-span" style="white-space:pre"> </span>// Main element of dynamic pipeline</div>
<div>static GstPad *blockpad;<span class="Apple-tab-span" style="white-space:pre"> </span>// SRC pad to be blocked</div><div>static GstPad *elem_cur_srcpad;<span class="Apple-tab-span" style="white-space:pre"> </span>// SRC pad where check EOS</div>
<div>static GstPad *elem_cur_sinkpad;<span class="Apple-tab-span" style="white-space:pre"> </span>// SINK of dynamic pipeline</div><div>static GstPad *elem_after_sinkpad; // SINK of SINK element</div><div><br></div><div>
// Last Buffer Timestamp</div><div>static GstClockTime last_ts = 0;</div><div><br></div><div>typedef enum {</div><div> NO_NEW_FILE,<span class="Apple-tab-span" style="white-space:pre"> </span>// Keep current file destination</div>
<div> NEW_FILE,<span class="Apple-tab-span" style="white-space:pre"> </span>// Switch file destination</div><div>} NewFileStatus;</div><div>static NewFileStatus newfile = NO_NEW_FILE; // Switch File Flag</div><div><br></div>
<div>static int counter = 1; // Index filename</div></div><div><br></div><div><div>// EOS listener to switch to other file destination</div><div>static gboolean</div><div>event_probe_cb (GstPad * pad, GstEvent * event, gpointer user_data)</div>
<div>{</div><div> g_print ("INSIDE event_probe_cb:%d type:%s\n",probe_id,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> GST_EVENT_TYPE (event)==GST_EVENT_EOS?"EOS":GST_EVENT_TYPE (event)==GST_EVENT_NEWSEGMENT?"NEWSEGMENT":"OTHER");</div>
<div><br></div><div> if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)</div><div> {</div><div> // Push the event in the pipe flow (false DROP)</div><div> return TRUE;</div><div> }</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div> // remove the probe first</div><div> gst_pad_remove_event_probe (pad, probe_id);</div><div><br></div><div> gst_object_unref (elem_cur_srcpad);</div><div> gst_object_unref (elem_after_sinkpad);</div><div> gst_element_release_request_pad(elem_cur, elem_cur_sinkpad);</div>
<div><br></div><div> gst_element_set_state (elem_cur, GST_STATE_NULL);</div><div> gst_element_set_state (elem_after, GST_STATE_NULL);</div><div><br></div><div> // remove unlinks automatically</div><div> GST_DEBUG_OBJECT (pipeline, "removing %" GST_PTR_FORMAT, elem_cur);</div>
<div> gst_bin_remove (GST_BIN (pipeline), elem_cur);</div><div> GST_DEBUG_OBJECT (pipeline, "removing %" GST_PTR_FORMAT, elem_after);</div><div> gst_bin_remove (GST_BIN (pipeline), elem_after);</div><div><br>
</div><div> GstElement * mux0 = gst_element_factory_make("mp4mux", "mux0");</div><div> GstElement * fsink0 = gst_element_factory_make("filesink", "fsink0");</div><div> elem_cur = mux0;</div>
<div> elem_after = fsink0;</div><div><br></div><div> if(!mux0 || !fsink0)</div><div> {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>printf("mising elements\n");</div><div> }</div><div>
<br></div><div> GST_DEBUG_OBJECT (pipeline, "adding %" GST_PTR_FORMAT, elem_cur);</div><div> gst_bin_add (GST_BIN (pipeline), elem_cur);</div><div> GST_DEBUG_OBJECT (pipeline, "adding %" GST_PTR_FORMAT, elem_after);</div>
<div> gst_bin_add (GST_BIN (pipeline), elem_after);</div><div><br></div><div> char buffer[128];</div><div> sprintf(buffer, "test_%d.mp4", counter++);</div><div> g_print ("File Switching %s\n", buffer);</div>
<div> g_object_set(G_OBJECT(elem_after), "location", buffer, NULL);</div><div><br></div><div> GST_DEBUG_OBJECT (pipeline, "linking..");</div><div> elem_cur_srcpad = gst_element_get_static_pad (elem_cur, "src");</div>
<div> elem_cur_sinkpad = gst_element_get_request_pad (elem_cur, "video_%d");</div><div> elem_after_sinkpad = gst_element_get_static_pad (elem_after, "sink");</div><div><br></div><div> if(gst_pad_link(blockpad, elem_cur_sinkpad) != GST_PAD_LINK_OK)</div>
<div> {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>printf("linking output 0 failed\n");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return -1;</div><div> }</div>
<div> if(gst_pad_link(elem_cur_srcpad, elem_after_sinkpad) != GST_PAD_LINK_OK)</div><div> {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>printf("linking output 1 failed\n");</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>return -1;</div><div> }</div><div><br></div><div> g_print ("Moving to PLAYING\n");</div><div> gst_element_set_state (elem_cur, GST_STATE_PLAYING);</div>
<div> gst_element_set_state (elem_after, GST_STATE_PLAYING);</div><div><br></div><div> GST_DEBUG_OBJECT (pipeline, "done");</div><div><br></div><div> newfile = NO_NEW_FILE;</div><div> // Push the event in the pipe flow (false DROP)</div>
<div> return TRUE;</div><div>}</div><div><br></div><div>// Check if Buffer contains a KEY FRAME</div><div>static gboolean</div><div>is_sync_frame (GstBuffer * buffer)</div><div>{</div><div> if (GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) </div>
<div> {</div><div> return FALSE;</div><div> }</div><div> else if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_IN_CAPS)) </div><div> {</div><div> return TRUE;</div><div> }</div><div>}</div><div><br></div><div>
// Block source and launch EOS to MUXER to achieve a full muxed file</div><div>static gboolean</div><div>pad_probe_cb (GstPad * pad, GstBuffer * buffer, gpointer user_data)</div><div>{</div><div> g_print ("\n\tINSIDE pad_probe_cb:%d %s %s\n",probe_id, (newfile?"newfile":"thesame"), </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> (is_sync_frame (buffer)?"KEYframe":"frame"));</div><div> GST_DEBUG_OBJECT (pad, "pad is blocked now");</div><div><br></div>
<div> last_ts = GST_BUFFER_TIMESTAMP(buffer);</div><div> if(!GST_CLOCK_TIME_IS_VALID(last_ts))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> last_ts=0;</div><div><br></div><div> if((newfile==NO_NEW_FILE) || !is_sync_frame (buffer))</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>return TRUE;</div><div><br></div><div> /* remove the probe first */</div><div> gst_pad_remove_buffer_probe (pad, probe_id);</div><div><br></div><div> /* install new probe for EOS */</div>
<div> probe_id = gst_pad_add_event_probe (elem_after_sinkpad, G_CALLBACK(event_probe_cb), user_data);</div><div><br></div><div> /* push EOS into the element, the probe will be fired when the</div><div> * EOS leaves the effect and it has thus drained all of its data */</div>
<div> gst_pad_send_event (elem_cur_sinkpad, gst_event_new_eos ());</div><div><br></div><div> // Wait til the EOS have been processed the Buffer with the Key frame will be the FIRST</div><div> while(newfile != NO_NEW_FILE)</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> Sleep(1);</div><div><br></div><div> // Push the buffer in the pipe flow (false DROP)</div><div> return TRUE;</div><div>}</div><div><br></div><div>// this timeout is periodically run as part of the mainloop</div>
<div>static gboolean timeout (gpointer user_data)</div><div>{</div><div> g_print ("TIMEOUT\n");</div><div> if(!playing)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> return false;</div>
<div> newfile = NEW_FILE;</div><div> /* install new probe for Keyframe and New File */</div><div> probe_id = gst_pad_add_buffer_probe (blockpad, G_CALLBACK(pad_probe_cb), pipeline);</div><div> return true;</div><div>}</div>
</div><div><br></div><div>Best,</div><div><br></div><div>Angel</div></div><br><div class="gmail_quote">2012/12/1 somnyrds <span dir="ltr"><<a href="mailto:tom.morrison@smith-nephew.com" target="_blank">tom.morrison@smith-nephew.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So, this again is the basic idea: I have a c-program that 'sorta' works that<br>
can be reduced to this:<br>
<br>
video_source->output-selector- - - - >video encoder->avimux->filesink<br>
\<br>
\<br>
v<br>
Fakesink<br>
<br>
The selector toggles every 5 seconds. I want to save each 5 second clip to a<br>
unique file.<br>
So, when the 5 second timer goes off, I send an EOS to video_source (to<br>
flush and fix<br>
the AVI file header).<br>
<br>
gst_element_set_state(video_source, GST_STATE_NULL);<br>
<br>
My intention is to then wait until the EOS has actually occurred (which<br>
means its flushed<br>
and the file has been finalized) and then switch to the fakesink...<br>
<br>
In MVC: mxc_v4l_open<br>
device name is Mxc Camera<br>
Exiting Pipeline1 because: Error (000149A0): Internal GStreamer error:<br>
negotiation problem.<br>
Please file a bug at<br>
<a href="http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer" target="_blank">http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer</a>.<br>
Stopped Playing (EOS) - Set State<br>
Now Cleanup/Delete pipeline<br>
<br>
This is with gstreamer-0.10.35 (as is part1)<br>
<br>
What could I be doing wrong?<br>
<br>
Thanks in advance<br>
<br>
Sincerely,<br>
<br>
Tom Morrison<br>
<br>
<br>
<br>
<br>
But, even before I get an EOS in the pipeline callback, I get<br>
- so I see 5 seconds worth in the file, and then<br>
another 5 seconds (5 seconds later)...but, I am getting this:<br>
<br>
GStreamer-CRITICAL **: gst_segment_set_newsegment_full: assertion<br>
`segment->format == format' failed<br>
<br>
Why am I getting this?<br>
<br>
Tom<br>
<br>
ps: Part (2) will be coming soon - and it involves switching filesink<br>
locations (filename) every time it switches to live video.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://gstreamer-devel.966125.n4.nabble.com/Part2-Output-Selectors-and-send-EOS-and-Internal-GSTREAMER-errors-tp4657164.html" target="_blank">http://gstreamer-devel.966125.n4.nabble.com/Part2-Output-Selectors-and-send-EOS-and-Internal-GSTREAMER-errors-tp4657164.html</a><br>
Sent from the GStreamer-devel mailing list archive at Nabble.com.<br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</blockquote></div><br>