13 static GMainLoop *mainloop = NULL;
17 static gchar *input_file = NULL;
18 static gchar *video_encode = NULL;
19 static gchar *video_opts = NULL;
20 static gdouble video_fps = 0.0;
21 static gint video_rate = 0;
22 static gint video_width = 0;
23 static gint video_height = 0;
24 static gchar *audio_encode = NULL;
25 static gchar *audio_opts = NULL;
26 static double audio_rate = 0.0;
27 static gchar *mux_name = NULL;
28 static gchar *output_uri = NULL;
29 static gboolean chunked = FALSE;
37 g_main_loop_quit(mainloop);
42 _mencoder_eos_cb(GMencoder * mencoder, gpointer data)
44 g_print("PROGRESS: 100\n");
45 g_idle_add(_quit, mencoder);
50 _mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data)
52 g_print("Error: %s\n", msg);
53 g_idle_add(_quit, mencoder);
57 _io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data)
59 GString *cmd = g_string_new("");
60 g_io_channel_read_line_string(ch, cmd, NULL, NULL);
62 if (strcmp(cmd->str, "PLAY\n") == 0) {
63 g_mencoder_play_stream(G_MENCODER(data));
64 } else if (strcmp(cmd->str, "PAUSE\n") == 0) {
65 g_mencoder_pause_stream(G_MENCODER(data));
66 } else if (strcmp(cmd->str, "STOP\n") == 0) {
67 g_mencoder_close_stream(G_MENCODER(data));
68 } else if (strcmp(cmd->str, "QUIT\n") == 0) {
69 g_mencoder_close_stream(G_MENCODER(data));
70 g_main_loop_quit(mainloop);
72 g_string_free(cmd, TRUE);
77 main(int argc, char **argv)
79 GMencoder *coder = NULL;
87 GOptionContext *context;
88 static const GOptionEntry options[] = {
89 {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file,
92 {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode,
93 "GstElementName for used to video encode", NULL},
95 {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts,
96 "Properties to set on video element", NULL},
98 {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps,
101 {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate,
104 {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width,
105 "Video width", NULL},
107 {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height,
108 "Video height", NULL},
110 {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode,
111 "GstElementName for use to audio encode", NULL},
113 {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts,
114 "Properties to set on audio element", NULL},
116 {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate,
119 {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name,
120 "GstElementName for use to mux file", NULL},
122 {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri,
123 "Uri to output", NULL},
125 {"chunked", 'c', 0, G_OPTION_ARG_NONE, &chunked,
126 "Send package chunked", NULL},
133 mainloop = g_main_loop_new(NULL, FALSE);
135 g_set_prgname("gmemcoder");
136 context = g_option_context_new(NULL);
137 g_option_context_set_help_enabled(context, TRUE);
138 g_option_context_add_main_entries(context, options, NULL);
139 g_option_context_add_group(context, gst_init_get_option_group());
140 g_option_context_parse(context, &argc, &argv, NULL);
142 gst_init(&argc, &argv);
144 if (output_uri == NULL) {
145 g_print("You need to specify output-uri.\nTry --help "
146 "for more information.\n");
150 if (input_file == NULL) {
151 g_print("You need to specify input file\nTry --help "
152 "for more information.\n");
155 coder = g_mencoder_new();
156 ch = g_io_channel_unix_new(0);
158 if (audio_opts != NULL)
159 aopts = g_strsplit(audio_opts, ",", 0);
163 if (video_opts != NULL)
164 vopts = g_strsplit(video_opts, ",", 0);
169 ret = g_mencoder_setup_stream(coder, chunked, mux_name,
170 video_encode, vopts, video_fps,
171 video_rate, video_width, video_height,
172 audio_encode, aopts, audio_rate, output_uri);
175 files = g_strsplit(input_file, ",", 0);
176 for (i = 0; i < g_strv_length(files); i++) {
177 if (!g_mencoder_append_uri(coder, files[i])) {
178 g_debug("Invalid uri: %s", files[i]);
188 g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
189 g_signal_connect(G_OBJECT(coder),
190 "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
192 g_signal_connect(G_OBJECT(coder),
193 "error", G_CALLBACK(_mencoder_error_cb), mainloop);
195 g_mencoder_play_stream(coder);
196 g_main_loop_run(mainloop);
199 g_object_unref(coder);