[gst-devel] Conversion in C

Christoffer Sørensen gstreamer at curo.dk
Tue Feb 8 13:54:39 CET 2005


I want to make an app to convert various audio files to wav using decodebin.

My sample code is as follows:

#include "gst/gst.h"

GstElement *pipeline, *decoder, *converter;

static void
cb_newpad (GstElement *element,
	   GstPad     *pad,
	   gpointer    data)


void media_convert(void)
	GstElement *dest, *src,*encoder;

	/* create a new thread to hold the elements */
/*	thread = gst_thread_new ("org-gnome-audio-inline-mpeg-thread"); */

	/* create the pipeline */
	pipeline = gst_pipeline_new ("audio-converter");
	g_return_if_fail(pipeline != NULL);

	src = gst_element_factory_make("filesrc","file-source");
	g_return_if_fail(src != NULL);

	g_object_set (G_OBJECT (src), "location", "/home/cs/Naturally.ogg", NULL);

	/* decoder */

	decoder = gst_element_factory_make ("decodebin", "decoder");
	g_signal_connect (decoder, "new-decoded-pad", G_CALLBACK (cb_newpad), NULL);

	/* create an audio converter */
	converter = gst_element_factory_make ("audioconvert", "converter");
	g_assert (converter != NULL);

	/* and an wav encoder */
	encoder = gst_element_factory_make ("wavenc", "encoder");
	g_return_if_fail(encoder != NULL);
	/* finally the output filesink */

	dest = gst_element_factory_make("filesink","file-out");
	g_return_if_fail(dest != NULL);

	g_object_set (G_OBJECT (dest), "location", "/home/cs/Naturally.wav", NULL);

    gst_bin_add_many (GST_BIN (pipeline), src, decoder, NULL);


  	gst_element_set_state (pipeline, GST_STATE_PLAYING);

	while (gst_bin_iterate (GST_BIN (pipeline))) ;

  	/* clean up nicely */
  	gst_element_set_state (pipeline, GST_STATE_NULL);
  	gst_object_unref (GST_OBJECT (pipeline));

The resulting file is of size zero. Could you give me any pointers to what is
wrong here ?

Forgive me, if it is obvious, but I am just starting out in gstreamer land :-)



More information about the gstreamer-devel mailing list