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;
30 static gboolean deinterlace = FALSE;
38 g_main_loop_quit(mainloop);
43 _mencoder_eos_cb(GMencoder * mencoder, gpointer data)
45 g_print("PROGRESS: 100\n");
46 g_idle_add(_quit, mencoder);
51 _mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data)
53 g_print("Error: %s\n", msg);
54 g_idle_add(_quit, mencoder);
58 _io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data)
60 GString *cmd = g_string_new("");
61 g_io_channel_read_line_string(ch, cmd, NULL, NULL);
63 if (strcmp(cmd->str, "PLAY\n") == 0) {
64 g_mencoder_play_stream(G_MENCODER(data));
65 } else if (strcmp(cmd->str, "PAUSE\n") == 0) {
66 g_mencoder_pause_stream(G_MENCODER(data));
67 } else if (strcmp(cmd->str, "STOP\n") == 0) {
68 g_mencoder_close_stream(G_MENCODER(data));
69 } else if (strcmp(cmd->str, "QUIT\n") == 0) {
70 g_mencoder_close_stream(G_MENCODER(data));
71 g_main_loop_quit(mainloop);
73 g_string_free(cmd, TRUE);
78 main(int argc, char **argv)
80 GMencoder *coder = NULL;
88 GOptionContext *context;
89 static const GOptionEntry options[] = {
90 {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file,
93 {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode,
94 "GstElementName for used to video encode", NULL},
96 {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts,
97 "Properties to set on video element", NULL},
99 {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps,
102 {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate,
105 {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width,
106 "Video width", NULL},
108 {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height,
109 "Video height", NULL},
111 {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode,
112 "GstElementName for use to audio encode", NULL},
114 {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts,
115 "Properties to set on audio element", NULL},
117 {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate,
120 {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name,
121 "GstElementName for use to mux file", NULL},
123 {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri,
124 "Uri to output", NULL},
126 {"chunked", 'c', 0, G_OPTION_ARG_NONE, &chunked,
127 "Send package chunked", NULL},
129 {"deinterlace", 'd', 0, G_OPTION_ARG_NONE, &deinterlace,
130 "Use to deinterlace videos", NULL},
138 mainloop = g_main_loop_new(NULL, FALSE);
140 g_set_prgname("gmemcoder");
141 context = g_option_context_new(NULL);
142 g_option_context_set_help_enabled(context, TRUE);
143 g_option_context_add_main_entries(context, options, NULL);
144 g_option_context_add_group(context, gst_init_get_option_group());
145 g_option_context_parse(context, &argc, &argv, NULL);
147 gst_init(&argc, &argv);
149 if (output_uri == NULL) {
150 g_print("You need to specify output-uri.\nTry --help "
151 "for more information.\n");
155 if (input_file == NULL) {
156 g_print("You need to specify input file\nTry --help "
157 "for more information.\n");
160 coder = g_mencoder_new();
161 ch = g_io_channel_unix_new(0);
163 if (audio_opts != NULL)
164 aopts = g_strsplit(audio_opts, ",", 0);
168 if (video_opts != NULL)
169 vopts = g_strsplit(video_opts, ",", 0);
174 ret = g_mencoder_setup_stream(coder, chunked, deinterlace, mux_name,
175 video_encode, vopts, video_fps,
176 video_rate, video_width, video_height,
177 audio_encode, aopts, audio_rate, output_uri);
180 files = g_strsplit(input_file, ",", 0);
181 for (i = 0; i < g_strv_length(files); i++) {
182 if (!g_mencoder_append_uri(coder, files[i])) {
183 g_debug("Invalid uri: %s", files[i]);
193 g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
194 g_signal_connect(G_OBJECT(coder),
195 "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
197 g_signal_connect(G_OBJECT(coder),
198 "error", G_CALLBACK(_mencoder_error_cb), mainloop);
200 g_mencoder_play_stream(coder);
201 g_main_loop_run(mainloop);
204 g_object_unref(coder);