[svn r800] Fixed the gmencoder.py get_all_log print that were writing PROGRESS twice
8 #include <libgnomevfs/gnome-vfs.h>
10 #include "gmencoder.h"
14 static GMainLoop *mainloop = NULL;
18 static gchar *input_file = NULL;
19 static gchar *video_encode = NULL;
20 static gchar *video_opts = NULL;
21 static gdouble video_fps = 0.0;
22 static gint video_rate = 0;
23 static gint video_width = 0;
24 static gint video_height = 0;
25 static gchar *audio_encode = NULL;
26 static gchar *audio_opts = NULL;
27 static double audio_rate = 0.0;
28 static gchar *mux_name = NULL;
29 static gchar *output_uri = NULL;
30 static gboolean chunked = FALSE;
31 static gboolean deinterlace = FALSE;
38 //g_object_unref(data);
39 g_main_loop_quit(mainloop);
44 _mencoder_eos_cb(GMencoder * mencoder, gpointer data)
46 g_print("PROGRESS: 100\n");
47 g_idle_add(_quit, mencoder);
52 _mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data)
54 g_print("Error: %s\n", msg);
55 g_idle_add(_quit, mencoder);
59 _io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data)
61 GString *cmd = g_string_new("");
62 g_io_channel_read_line_string(ch, cmd, NULL, NULL);
64 if (strcmp(cmd->str, "PLAY\n") == 0) {
65 g_mencoder_play_stream(G_MENCODER(data));
66 } else if (strcmp(cmd->str, "PAUSE\n") == 0) {
67 g_mencoder_pause_stream(G_MENCODER(data));
68 } else if (strcmp(cmd->str, "STOP\n") == 0) {
69 g_mencoder_close_stream(G_MENCODER(data));
70 } else if (strcmp(cmd->str, "QUIT\n") == 0) {
71 g_mencoder_close_stream(G_MENCODER(data));
72 g_main_loop_quit(mainloop);
74 g_string_free(cmd, TRUE);
79 main(int argc, char **argv)
81 GMencoder *coder = NULL;
89 GOptionContext *context;
90 static const GOptionEntry options[] = {
91 {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file,
94 {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode,
95 "GstElementName for used to video encode", NULL},
97 {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts,
98 "Properties to set on video element", NULL},
100 {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps,
103 {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate,
106 {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width,
107 "Video width", NULL},
109 {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height,
110 "Video height", NULL},
112 {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode,
113 "GstElementName for use to audio encode", NULL},
115 {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts,
116 "Properties to set on audio element", NULL},
118 {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate,
121 {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name,
122 "GstElementName for use to mux file", NULL},
124 {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri,
125 "Uri to output", NULL},
127 {"chunked", 'c', 0, G_OPTION_ARG_NONE, &chunked,
128 "Send package chunked", NULL},
130 {"deinterlace", 'd', 0, G_OPTION_ARG_NONE, &deinterlace,
131 "Use to deinterlace videos", NULL},
140 mainloop = g_main_loop_new(NULL, FALSE);
142 g_set_prgname("gmemcoder");
143 context = g_option_context_new(NULL);
144 g_option_context_set_help_enabled(context, TRUE);
145 g_option_context_add_main_entries(context, options, NULL);
146 g_option_context_add_group(context, gst_init_get_option_group());
147 g_option_context_parse(context, &argc, &argv, NULL);
149 gst_init(&argc, &argv);
151 if (output_uri == NULL) {
152 g_print("You need to specify output-uri.\nTry --help "
153 "for more information.\n");
157 if (input_file == NULL) {
158 g_print("You need to specify input file\nTry --help "
159 "for more information.\n");
162 coder = g_mencoder_new();
163 ch = g_io_channel_unix_new(0);
165 if (audio_opts != NULL)
166 aopts = g_strsplit(audio_opts, ",", 0);
170 if (video_opts != NULL)
171 vopts = g_strsplit(video_opts, ",", 0);
175 ret = g_mencoder_setup_stream(coder, chunked, deinterlace, mux_name,
176 video_encode, vopts, video_fps,
177 video_rate, video_width, video_height,
178 audio_encode, aopts, audio_rate, output_uri);
181 files = g_strsplit(input_file, ",", 0);
182 for (i = 0; i < g_strv_length(files); i++) {
183 if (!g_mencoder_append_uri(coder, files[i])) {
184 g_debug("Invalid uri: %s", files[i]);
194 g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
195 g_signal_connect(G_OBJECT(coder),
196 "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
198 g_signal_connect(G_OBJECT(coder),
199 "error", G_CALLBACK(_mencoder_error_cb), mainloop);
201 g_mencoder_play_stream(coder);
202 g_main_loop_run(mainloop);
205 g_object_unref(coder);