2 * This example shows how to use interfaces and the tag subsystem.
3 * It takes an mp3 file as input, and makes an ogg file out of it. While doing
4 * this, it parses the filename and sets artist and title in the ogg file.
5 * It assumes the filename to be "<artist> - <title>.mp3"
7 * Run the program as "transcode <mp3 file>"
9 * To run this program, you need to have the gst-plugins package (specifically
10 * the vorbis and mad plugins) installed.
15 /* and a header we need for the string manipulation */
19 main (int argc, char *argv[])
21 GstElement *bin, *filesrc, *decoder, *encoder, *filesink;
22 gchar *artist, *title, *ext, *filename;
24 /* initialize GStreamer */
25 gst_init (&argc, &argv);
27 /* check that the argument is there */
29 g_print ("usage: %s <mp3 file>\n", argv[0]);
33 /* parse the mp3 name */
34 artist = strrchr (argv[1], '/');
37 artist = g_strdup (artist);
38 ext = strrchr (artist, '.');
40 title = strstr (artist, " - ");
42 g_print ("The format of the mp3 file is invalid.\n");
43 g_print ("It needs to be in the form of artist - title.mp3.\n");
50 /* create a new bin to hold the elements */
51 bin = gst_pipeline_new ("pipeline");
54 /* create a file reader */
55 filesrc = gst_element_factory_make ("filesrc", "disk_source");
58 /* now it's time to get the decoder */
59 decoder = gst_element_factory_make ("mad", "decode");
61 g_print ("could not find plugin \"mad\"");
65 /* create the encoder */
66 encoder = gst_element_factory_make ("vorbisenc", "encoder");
68 g_print ("cound not find plugin \"vorbisenc\"");
72 /* and a file writer */
73 filesink = gst_element_factory_make ("filesink", "filesink");
76 /* set the filenames */
77 filename = g_strdup_printf ("%s.ogg", argv[1]); /* easy solution */
78 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
79 g_object_set (G_OBJECT (filesink), "location", filename, NULL);
82 /* make sure the tag setter uses our stuff
83 (though that should already be default) */
84 gst_tag_setter_set_merge_mode (GST_TAG_SETTER (encoder), GST_TAG_MERGE_KEEP);
85 /* set the tagging information */
86 gst_tag_setter_add (GST_TAG_SETTER (encoder), GST_TAG_MERGE_REPLACE,
87 GST_TAG_ARTIST, artist,
91 /* add objects to the main pipeline */
92 gst_bin_add_many (GST_BIN (bin), filesrc, decoder, encoder, filesink, NULL);
94 /* link the elements */
95 gst_element_link_many (filesrc, decoder, encoder, filesink, NULL);
98 gst_element_set_state (bin, GST_STATE_PLAYING);
100 while (gst_bin_iterate (GST_BIN (bin)));
103 gst_element_set_state (bin, GST_STATE_NULL);