<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">Hi,</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">To fully understand the elements/pads structure the right schedule is:</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px;background-color:rgb(255,255,255)"><div class="im" style="color:rgb(80,0,80)"><div style="color:rgb(34,34,34)">// Pipeline -> src -> dynamic pipeline</div>
<div style="color:rgb(34,34,34)">// Pipeline -> capsfilter(f264file) -> mp4mux(mux0) -> filesink(fsink0)</div></div><div>// Pipeline -> elem_BEFORE||blockpad| -> |elem_CUR_sinkpad||elem_CUR||elem_CUR_srcpad -> |elem_AFTER_sinkpad||elem_AFTER</div>
<div><br></div><div>Best,</div><div><br></div><div>Angel</div></div><div><pre><table border="0" cellpadding="0" cellspacing="0" align="center" style="color:rgb(0,0,0);font-family:'Times New Roman'"><tbody></tbody></table>
</pre></div>
2013/6/4 Angel Martin <span dir="ltr"><<a href="mailto:amartin@vicomtech.org" target="_blank">amartin@vicomtech.org</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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" target="_blank">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 style="white-space:pre-wrap"> </span>// probe ID</div><div>static GstElement *elem_before;<span style="white-space:pre-wrap"> </span>// SRC of dynamic pipeline</div>
<div>static GstElement *elem_after;<span style="white-space:pre-wrap"> </span>// SINK of dynamic pipeline</div><div>static GstElement *elem_cur;<span style="white-space:pre-wrap"> </span>// Main element of dynamic pipeline</div>
<div>static GstPad *blockpad;<span style="white-space:pre-wrap"> </span>// SRC pad to be blocked</div><div>static GstPad *elem_cur_srcpad;<span style="white-space:pre-wrap"> </span>// SRC pad where check EOS</div>
<div>static GstPad *elem_cur_sinkpad;<span style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </span>// Keep current file destination</div>
<div> NEW_FILE,<span style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </span>printf("linking output 0 failed\n");</div><div><span style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </span>printf("linking output 1 failed\n");</div><div>
<span style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </span> last_ts=0;</div><div><br></div><div> if((newfile==NO_NEW_FILE) || !is_sync_frame (buffer))</div>
<div><span style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </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 style="white-space:pre-wrap"> </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 class="HOEnZb"><div class="h5"><br><div class="gmail_quote">2012/9/19 Stefan Sauer <span dir="ltr"><<a href="mailto:ensonic@hora-obscura.de" target="_blank">ensonic@hora-obscura.de</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div>
<div>On 09/19/2012 07:03 PM, Alexander
Botero wrote:<br>
</div>
<blockquote type="cite">
<div class="gmail_quote">
<div>Stefan, I took your "encodebin" very literally and made
some tests with it.</div>
<div><br>
</div>
<div>I learned that it's possible to create a media (encoding)
profile during runtime.</div>
<div>I even tried to drop the container from ogg-vorbis
recording, but the file was not playable;-)</div>
<div>I also tested "encodebin" with you GstTee pipeline. </div>
<div><br>
</div>
<div>I haven't managed to adjust the internal clock of AAC, OGG
Vorbis and SPX formats. </div>
<div>They still "remember" the slient parts. But these tests
have been very interesting to do.</div>
</div>
</blockquote></div>
For these format, you will need to send a new-segment event to
inform them elements about the gap. You should find an example
inside camerabin2 in gst-plugins-bad.<span><font color="#888888"><br>
<br>
Stefan<br>
</font></span><blockquote type="cite"><div><div>
<div class="gmail_quote">
<div><br>
</div>
<div>Current solution / eu resolvi por esta solução:</div>
<div>I have decided to use the VADer element i our (GPL'ed)
audio-recorder because it has a very good algorithm for audio
detection and noise filtering.</div>
<div>I will now bake it to the "audio-recorder" project so it
gets compiled and packaged. </div>
<div><br>
</div>
<div>The "silent" detection in the recorder will become much
simpler. The actual, old version creates two (2) long
pipelines; one for the "silent" detection and second (similar)
pipeline for recording. This is awful waste of resources. </div>
<div><br>
</div>
<div>But of course, the new recorder must live with the above
problem with AAC, OGG and SPX formats. That's life!</div>
<div>------------</div>
<div><br>
</div>
<div>static GstElement *create_pipeline() {</div>
<div>
<div> GstElement *pipeline = gst_pipeline_new("a simple
recorder");</div>
<div><br>
</div>
<div> GstElement *src =
gst_element_factory_make("pulsesrc", "source");</div>
<div> g_object_set(G_OBJECT(src), "device",
"alsa_input.usb-Creative_....", NULL);</div>
<div><br>
</div>
<div> GstElement *filesink =
gst_element_factory_make("filesink", "filesink");</div>
<div> g_object_set(G_OBJECT(filesink), "location",
"test.xxx", NULL);</div>
<div>
<br>
</div>
<div> GstElement *queue = gst_element_factory_make("queue",
NULL);</div>
<div> GstElement *ebin =
gst_element_factory_make("encodebin", NULL);</div>
<div><br>
</div>
<div> GstEncodingProfile *prof =
create_ogg_vorbis_profile(1, NULL);</div>
<div> g_object_set (ebin, "profile", prof, NULL);</div>
<div> gst_encoding_profile_unref (prof);</div>
<div><br>
</div>
<div> gst_bin_add_many(GST_BIN(pipeline), src, queue, ebin,
filesink, NULL);</div>
<div>
<br>
</div>
<div> if (!gst_element_link_many(src, queue, ebin,
filesink, NULL)) {</div>
<div> g_printerr("Cannot link many.\n");</div>
<div> }</div>
<div><br>
</div>
<div> GstBus *bus =
gst_pipeline_get_bus(GST_PIPELINE(pipeline));</div>
<div> gst_bus_add_signal_watch(bus);</div>
<div> g_signal_connect(bus, "message::element",
G_CALLBACK(level_message_cb), NULL);</div>
<div> gst_object_unref(bus);</div>
<div>}</div>
</div>
<div><br>
</div>
<div>
<div>static GstEncodingProfile *create_ogg_vorbis_profile
(guint presence, gchar * preset) {</div>
<div> // I copied this from gstreamer's test-module. It
seems to be very easy to create new profiles.</div>
<div> GstEncodingContainerProfile *cprof;</div>
<div> GstCaps *ogg, *vorbis;</div>
<div><br>
</div>
<div> ogg = gst_caps_new_simple ("application/ogg", NULL);</div>
<div> cprof = gst_encoding_container_profile_new ((gchar *)
"oggprofile", NULL, ogg, NULL);</div>
<div> gst_caps_unref (ogg);</div>
<div><br>
</div>
<div> vorbis = gst_caps_new_simple ("audio/x-vorbis",
NULL);</div>
<div> gst_encoding_container_profile_add_profile (cprof,
(GstEncodingProfile *) gst_encoding_audio_profile_new
(vorbis, preset, NULL, presence));</div>
<div> gst_caps_unref (vorbis);</div>
<div><br>
</div>
<div> // vorbisenc:</div>
<div> // audio/x-raw-float, rate=(int)[ 1, 200000 ],
channels=(int)[ 1, 255 ], endianness=(int)1234,
width=(int)32</div>
<div> //</div>
<div>
<div> // caps =
gst_caps_new_simple("audio/x-raw-float", </div>
<div> // "rate",G_TYPE_INT, 8000, </div>
<div> // "channels" ,G_TYPE_INT, (gint)1, </div>
<div> //
"endianness",G_TYPE_INT,(gint)1234, </div>
<div> // "width" ,G_TYPE_INT,
(gint)8, NULL); </div>
</div>
<div><br>
</div>
<div> return (GstEncodingProfile *)cprof;</div>
<div>}</div>
</div>
<div><br>
</div>
<div>Kindly</div>
<div> Osmo Antero</div>
<div><br>
</div>
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
You could do something like this:<br>
autoaudiosrc ! level ! tee name=t ! queue ! autoaudiosink t.
! queue ! valve ! encodebin ! filesink<br>
<br>
when the level drops below a threshold, you close the valve
and remember the position. When the level gets above the
threshold again, you open he valve (and eventually push a
newsegment event).<span><font color="#888888"><br>
<br>
Stefan<br>
<br>
</font></span></div>
</blockquote>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><div><pre>_______________________________________________
gstreamer-devel mailing list
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesktop.org</a>
<a href="http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a>
</pre>
</div></blockquote>
<br>
</div>
<br>_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">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>
<br></blockquote></div><br>
</div></div></blockquote></div><br>