[svn r918] moved debian dir from gst-gmyth and libgnomevfs2-mythtv to packages project
2 * arch-tag: GMencoder main file
4 * Copyright (C) 2007 INdT - Renato Filho <renato.filho@indt.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <libgnomevfs/gnome-vfs.h>
31 #include "gmencoder.h"
35 static GMainLoop *mainloop = NULL;
39 static gchar *input_file = NULL;
40 static gchar *video_encode = NULL;
41 static gchar *video_opts = NULL;
42 static gdouble video_fps = 0.0;
43 static gint video_rate = 0;
44 static gint video_width = 0;
45 static gint video_height = 0;
46 static gchar *audio_encode = NULL;
47 static gchar *audio_opts = NULL;
48 static double audio_rate = 0.0;
49 static gchar *mux_name = NULL;
50 static gchar *output_uri = NULL;
51 static gboolean chunked = FALSE;
52 static gboolean deinterlace = FALSE;
59 //g_object_unref(data);
60 g_main_loop_quit(mainloop);
65 _mencoder_eos_cb(GMencoder * mencoder, gpointer data)
67 g_print("PROGRESS: 100\n");
68 g_idle_add(_quit, mencoder);
73 _mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data)
75 g_print("Error: %s\n", msg);
76 g_idle_add(_quit, mencoder);
80 _io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data)
82 GString *cmd = g_string_new("");
83 g_io_channel_read_line_string(ch, cmd, NULL, NULL);
85 if (strcmp(cmd->str, "PLAY\n") == 0) {
86 g_mencoder_play_stream(G_MENCODER(data));
87 } else if (strcmp(cmd->str, "PAUSE\n") == 0) {
88 g_mencoder_pause_stream(G_MENCODER(data));
89 } else if (strcmp(cmd->str, "STOP\n") == 0) {
90 g_mencoder_close_stream(G_MENCODER(data));
91 } else if (strcmp(cmd->str, "QUIT\n") == 0) {
92 g_mencoder_close_stream(G_MENCODER(data));
93 g_main_loop_quit(mainloop);
95 g_string_free(cmd, TRUE);
100 main(int argc, char **argv)
102 GMencoder *coder = NULL;
110 GOptionContext *context;
111 static const GOptionEntry options[] = {
112 {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file,
115 {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode,
116 "GstElementName for used to video encode", NULL},
118 {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts,
119 "Properties to set on video element", NULL},
121 {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps,
124 {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate,
127 {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width,
128 "Video width", NULL},
130 {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height,
131 "Video height", NULL},
133 {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode,
134 "GstElementName for use to audio encode", NULL},
136 {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts,
137 "Properties to set on audio element", NULL},
139 {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate,
142 {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name,
143 "GstElementName for use to mux file", NULL},
145 {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri,
146 "Uri to output", NULL},
148 {"chunked", 'c', 0, G_OPTION_ARG_NONE, &chunked,
149 "Send package chunked", NULL},
151 {"deinterlace", 'd', 0, G_OPTION_ARG_NONE, &deinterlace,
152 "Use to deinterlace videos", NULL},
161 mainloop = g_main_loop_new(NULL, FALSE);
163 g_set_prgname("gmemcoder");
164 context = g_option_context_new(NULL);
165 g_option_context_set_help_enabled(context, TRUE);
166 g_option_context_add_main_entries(context, options, NULL);
167 g_option_context_add_group(context, gst_init_get_option_group());
168 g_option_context_parse(context, &argc, &argv, NULL);
170 gst_init(&argc, &argv);
172 if (output_uri == NULL) {
173 g_print("You need to specify output-uri.\nTry --help "
174 "for more information.\n");
178 if (input_file == NULL) {
179 g_print("You need to specify input file\nTry --help "
180 "for more information.\n");
183 coder = g_mencoder_new();
184 ch = g_io_channel_unix_new(0);
186 if (audio_opts != NULL)
187 aopts = g_strsplit(audio_opts, ",", 0);
191 if (video_opts != NULL)
192 vopts = g_strsplit(video_opts, ",", 0);
196 ret = g_mencoder_setup_stream(coder, chunked, deinterlace, mux_name,
197 video_encode, vopts, video_fps,
198 video_rate, video_width, video_height,
199 audio_encode, aopts, audio_rate, output_uri);
202 files = g_strsplit(input_file, ",", 0);
203 for (i = 0; i < g_strv_length(files); i++) {
204 if (!g_mencoder_append_uri(coder, files[i])) {
205 g_debug("Invalid uri: %s", files[i]);
215 g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder);
216 g_signal_connect(G_OBJECT(coder),
217 "eos", G_CALLBACK(_mencoder_eos_cb), mainloop);
219 g_signal_connect(G_OBJECT(coder),
220 "error", G_CALLBACK(_mencoder_error_cb), mainloop);
222 g_mencoder_play_stream(coder);
223 g_main_loop_run(mainloop);
226 g_object_unref(coder);