1.1 --- a/gmyth-stream/gmemcoder/src/main.c Mon Apr 23 18:50:32 2007 +0100
1.2 +++ b/gmyth-stream/gmemcoder/src/main.c Thu Apr 26 16:30:23 2007 +0100
1.3 @@ -6,11 +6,24 @@
1.4 #include <gst/gst.h>
1.5 #include <glib.h>
1.6
1.7 -#include "gmemcoder.h"
1.8 +#include "gmencoder.h"
1.9
1.10 -//#define FILE_OUT 1
1.11 +#define FILE_OUT 1
1.12
1.13 static GMainLoop *mainloop = NULL;
1.14 +/* Options */
1.15 +static gchar* input_file = NULL;
1.16 +static gchar* video_encode = NULL;
1.17 +static gchar* video_opts = NULL;
1.18 +static gdouble video_fps = 0.0;
1.19 +static gint video_rate = 0;
1.20 +static gint video_width = 0;
1.21 +static gint video_height = 0;
1.22 +static gchar* audio_encode = NULL;
1.23 +static gchar* audio_opts = NULL;
1.24 +static double audio_rate = 0.0;
1.25 +static gchar* output_element = NULL;
1.26 +static gchar* output_opts = NULL;
1.27
1.28 static void
1.29 _mencoder_ready_cb (GMencoder *mencoder, gpointer data)
1.30 @@ -59,22 +72,64 @@
1.31 {
1.32 GMencoder *coder;
1.33 GIOChannel *ch;
1.34 + gchar **oopts;
1.35 + gchar **vopts;
1.36 + gchar **aopts;
1.37 +
1.38 + GOptionContext *context;
1.39 + static const GOptionEntry options [] = {
1.40 + {"input-file", 'i', 0, G_OPTION_ARG_STRING, &input_file, "Input File", NULL},
1.41 + {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, "GstElementName for used to video encode", NULL},
1.42 + {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, "Properties to set on video element", NULL},
1.43 + {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, "Video FPS", NULL},
1.44 + {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, "Video rate", NULL},
1.45 + {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, "Video width", NULL},
1.46 + {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, "Video height", NULL},
1.47 + {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, "GstElementName for use to audio encode", NULL},
1.48 + {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, "Properties to set on audio element", NULL},
1.49 + {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, "Audio rate", NULL},
1.50 + {"output-element", 0, 0, G_OPTION_ARG_STRING, &output_element,"GstElementName for use to output", NULL},
1.51 + {"output-opts", 0, 0, G_OPTION_ARG_STRING, &output_opts, "Properties to set on output element", NULL},
1.52 + { NULL }
1.53 + };
1.54
1.55 g_type_init ();
1.56 + g_thread_init (NULL);
1.57 +
1.58 + //g_set_prgname ("gmemcoder");
1.59 + context = g_option_context_new (NULL);
1.60 + g_option_context_set_help_enabled (context, TRUE);
1.61 + g_option_context_add_main_entries (context, options, NULL);
1.62 + g_option_context_add_group (context, gst_init_get_option_group ());
1.63 + g_option_context_parse (context, &argc, &argv, NULL);
1.64 +
1.65 gst_init (&argc, &argv);
1.66
1.67 - g_set_prgname ("gmemcoder");
1.68 + if (output_element == NULL) {
1.69 + g_print ("You need specify output-element name.\nTry --help for more information.\n");
1.70 + return 1;
1.71 + }
1.72 +
1.73 + if (input_file == NULL) {
1.74 + g_print ("You need specify input file\nTry --help for more information.\n");
1.75 + }
1.76
1.77 coder = g_mencoder_new ();
1.78 ch = g_io_channel_unix_new (0);
1.79
1.80 -#ifdef FILE_OUT
1.81 - int fd = open (argv[2], O_WRONLY | O_CREAT | O_TRUNC);
1.82 - g_debug ("FD %d", fd);
1.83 - g_mencoder_setup_stream (coder, argv[1], 320, 288, fd);
1.84 -#else
1.85 - g_mencoder_setup_stream (coder, argv[1], 320, 288, atoi (argv[2]));
1.86 -#endif
1.87 + aopts = g_strsplit (audio_opts, ",", 0);
1.88 + vopts = g_strsplit (video_opts, ",", 0);
1.89 + oopts = g_strsplit (output_opts, ",", 0);
1.90 +
1.91 + g_mencoder_setup_stream (coder,
1.92 + input_file,
1.93 + video_encode, vopts, video_fps, video_rate, video_width, video_height,
1.94 + audio_encode, aopts, audio_rate,
1.95 + output_element, oopts);
1.96 +
1.97 + g_strfreev (aopts);
1.98 + g_strfreev (vopts);
1.99 + g_strfreev (oopts);
1.100
1.101 mainloop = g_main_loop_new (NULL, FALSE);
1.102 g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder);
1.103 @@ -97,9 +152,5 @@
1.104
1.105 g_main_loop_run (mainloop);
1.106
1.107 -#if FILE_OUT
1.108 - close (fd);
1.109 -#endif
1.110 -
1.111 return 0;
1.112 }