Removing silence from a stream
Mailing List SVR
lists at svrinformatica.it
Mon Feb 29 15:09:09 UTC 2016
Hi,
can you share your input file please?
Nicola
Il 29/02/2016 11:11, Sagar ha scritto:
> I am using /gst-launch-1.0 -v -t -m filesrc location=myvideo.webm ! decodebin
> ! audioconvert ! removesilence remove=true ! pulsesink/ what I want is that
> the audio to be played with out the silence
>
> but remove silence doesnt seem to be doing that.
>
>
> I also tried an alternative method by using /valve/ but there is some
> timestamp issue because of which some voice audio is lost.
>
> #define GLIB_DISABLE_DEPRECATION_WARNINGS
>
> #include <gst/gst.h>
> #include <string.h>
> #include <math.h>
>
> static GMainLoop *loop;
> GstElement *play;
> GstElement *valve;
>
> int isSpeaking =1;
> GstClockTime silencestarttime = 0;
> GstClockTime silenceendtime = 0;
>
> static gboolean
> my_voice_callback (GstBus *bus,
> GstMessage *message,
> gpointer data)
> {
> if (message->type == GST_MESSAGE_EOS) {
> g_main_loop_quit (loop);
> }
> return TRUE;
> }
>
> static gboolean
> my_bus_callback (GstBus *bus,
> GstMessage *message,
> gpointer data)
> {
> GstClockTime endtime;
> if (message->type == GST_MESSAGE_EOS) {
> if(isSpeaking ==0){
> silenceendtime = endtime;
> g_print ("\tsilence start time: %" GST_TIME_FORMAT "\n",GST_TIME_ARGS
> (silencestarttime));
> g_print ("\tsilence end time: %" GST_TIME_FORMAT "\n",GST_TIME_ARGS
> (silenceendtime));
>
> }
> g_main_loop_quit (loop);
> }
>
> if (message->type == GST_MESSAGE_ELEMENT) {
> const GstStructure *s = gst_message_get_structure (message);
> const gchar *name = gst_structure_get_name (s);
>
> if (strcmp (name, "level") == 0) {
> gint channels;
> GstClockTime starttime;
>
> gdouble rms_dB, peak_dB, decay_dB;
> gdouble rms;
> const GValue *array_val;
> const GValue *value;
> GValueArray *rms_arr, *peak_arr, *decay_arr;
> gint i;
>
> if (!gst_structure_get_clock_time (s, "endtime", &endtime))
> g_warning ("Could not parse endtime");
>
> starttime = endtime - GST_SECOND;
>
> if(silencestarttime == 0){
> silencestarttime =starttime ;
> }
>
> if(silenceendtime == 0){
> silenceendtime =starttime;
> }
>
> /* the values are packed into GValueArrays with the value per channel
> */
> array_val = gst_structure_get_value (s, "rms");
> rms_arr = (GValueArray *) g_value_get_boxed (array_val);
>
> array_val = gst_structure_get_value (s, "peak");
> peak_arr = (GValueArray *) g_value_get_boxed (array_val);
>
> array_val = gst_structure_get_value (s, "decay");
> decay_arr = (GValueArray *) g_value_get_boxed (array_val);
>
> /* we can get the number of channels as the length of any of the value
> * arrays */
> channels = rms_arr->n_values;
>
> for (i = 0; i < channels; ++i) {
> value = g_value_array_get_nth (rms_arr, i);
> rms_dB = g_value_get_double (value);
>
> value = g_value_array_get_nth (peak_arr, i);
> peak_dB = g_value_get_double (value);
>
> value = g_value_array_get_nth (decay_arr, i);
> decay_dB = g_value_get_double (value);
>
> if(rms_dB > -40){
> if(isSpeaking ==0){
> g_object_set(G_OBJECT(valve), "drop", FALSE , NULL);
>
>
> silenceendtime = starttime;
> g_print ("\tsilence start time: %" GST_TIME_FORMAT "\n",GST_TIME_ARGS
> (silencestarttime));
> g_print ("\tsilence end time: %" GST_TIME_FORMAT "\n",GST_TIME_ARGS
> (silenceendtime));
>
> }
> isSpeaking = 1;
> }
> else{
> if(isSpeaking==1){
> g_object_set(G_OBJECT(valve), "drop", TRUE , NULL);
> silencestarttime = starttime;
> }
> isSpeaking =0;
> g_print ("\nsilence: %" GST_TIME_FORMAT "\n",GST_TIME_ARGS (starttime));
> continue;
> }
> }
> }
> }
>
>
> /* we want to be notified again the next time there is a message
> * on the bus, so returning TRUE (FALSE means we want to stop watching
> * for messages on the bus and our callback should not be called again)
> */
> return TRUE;
> }
>
> int
> main (int argc, char *argv[])
> {
>
> GstBus *bus;
>
> /* gstreamer */
> gst_init (&argc, &argv);
>
> /* we need to run a GLib main loop to get the messages */
> loop = g_main_loop_new (NULL, FALSE);
>
> play = gst_parse_launch("filesrc location=audiosilence.mp4 ! decodebin !
> audioconvert ! level interval=1000000000 !tee name=t ! queue ! fakesink t.
> ! queue ! valve name=valve ! audioconvert ! wavenc ! filesink
> location=valve.wav", NULL);
> g_assert (play);
>
>
> bus = gst_pipeline_get_bus (GST_PIPELINE (play));
> gst_bus_add_watch (bus, my_bus_callback, NULL);
>
> gst_element_set_state (play, GST_STATE_PLAYING);
>
> valve = gst_bin_get_by_name(GST_PIPELINE (play),"valve");
> g_main_loop_run (loop);
>
> gst_element_set_state (play, GST_STATE_NULL);
> gst_object_unref (GST_OBJECT (play));
>
> gst_object_unref (bus);
>
> gst_object_unref (GST_OBJECT (valve));
> g_main_loop_unref (loop);
>
> return 0;
> }
>
>
>
>
> P.S: What I want to achive is a non silent chunks audio.
>
>
>
> --
> View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Removing-silence-from-a-stream-tp973199p4676108.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
More information about the gstreamer-devel
mailing list