Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / old / examples / stats / mp2ogg.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gst/gst.h>
21
22 /* This example app demonstartes the use of pad query and convert to
23  * get useful statistics about a plugin. In this case we monitor the
24  * compression status of mpeg audio to ogg vorbis transcoding.
25  */
26
27 gint
28 main (gint argc, gchar * argv[])
29 {
30   GstElement *pipeline;
31   GError *error = NULL;
32   gchar *description;
33   GstElement *encoder, *decoder;
34   GstPad *dec_sink, *enc_src;
35
36   gst_init (&argc, &argv);
37
38   if (argc < 3) {
39     g_print ("usage: %s <inputfile> <outputfile>\n", argv[0]);
40     return -1;
41   }
42
43   description = g_strdup_printf ("filesrc location=\"%s\" ! mad name=decoder ! "
44       "vorbisenc name=encoder ! filesink location=\"%s\"", argv[1], argv[2]);
45
46   pipeline = GST_ELEMENT (gst_parse_launch (description, &error));
47   if (!pipeline) {
48     if (error)
49       g_print ("ERROR: pipeline could not be constructed: %s\n",
50           error->message);
51     else
52       g_print ("ERROR: pipeline could not be constructed\n");
53     return -1;
54   }
55
56   decoder = gst_bin_get_by_name (GST_BIN (pipeline), "decoder");
57   encoder = gst_bin_get_by_name (GST_BIN (pipeline), "encoder");
58
59   dec_sink = gst_element_get_pad (decoder, "sink");
60   enc_src = gst_element_get_pad (encoder, "src");
61
62   if (gst_element_set_state (pipeline,
63           GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS) {
64     g_print ("pipeline doesn't want to play\n");
65     return -1;
66   }
67
68   while (gst_bin_iterate (GST_BIN (pipeline))) {
69     gint64 position;
70     gint64 duration;
71     gint64 bitrate_enc, bitrate_dec;
72     GstFormat format;
73
74     format = GST_FORMAT_TIME;
75     /* get the position */
76     gst_pad_query (enc_src, GST_QUERY_POSITION, &format, &position);
77
78     /* get the total duration */
79     gst_pad_query (enc_src, GST_QUERY_TOTAL, &format, &duration);
80
81     format = GST_FORMAT_BYTES;
82     /* see how many bytes are genereated per 8 seconds (== bitrate) */
83     gst_pad_convert (enc_src, GST_FORMAT_TIME, 8 * GST_SECOND,
84         &format, &bitrate_enc);
85
86     gst_pad_convert (dec_sink, GST_FORMAT_TIME, 8 * GST_SECOND,
87         &format, &bitrate_dec);
88
89     g_print ("[%2dm %.2ds] of [%2dm %.2ds], "
90         "src avg bitrate: %" G_GINT64_FORMAT ", dest avg birate: %"
91         G_GINT64_FORMAT ", ratio [%02.2f]    \r",
92         (gint) (position / (GST_SECOND * 60)),
93         (gint) (position / (GST_SECOND)) % 60,
94         (gint) (duration / (GST_SECOND * 60)),
95         (gint) (duration / (GST_SECOND)) % 60, bitrate_dec, bitrate_enc,
96         (gfloat) bitrate_dec / bitrate_enc);
97   }
98
99   g_print ("\n");
100
101   return 0;
102 }