diff -r bd0ad44171e7 -r 5c5cff842d57 gmyth-stream/gmemcoder/src/main.c --- a/gmyth-stream/gmemcoder/src/main.c Mon Apr 23 18:50:32 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/main.c Wed Apr 25 15:53:19 2007 +0100 @@ -6,11 +6,24 @@ #include #include -#include "gmemcoder.h" +#include "gmencoder.h" -//#define FILE_OUT 1 +#define FILE_OUT 1 static GMainLoop *mainloop = NULL; +/* Options */ +static gchar* input_file = NULL; +static gchar* video_encode = NULL; +static gchar* video_opts = NULL; +static gdouble video_fps = 0.0; +static gint video_rate = 0; +static gint video_width = 0; +static gint video_height = 0; +static gchar* audio_encode = NULL; +static gchar* audio_opts = NULL; +static double audio_rate = 0.0; +static gchar* output_element = NULL; +static gchar* output_opts = NULL; static void _mencoder_ready_cb (GMencoder *mencoder, gpointer data) @@ -59,22 +72,64 @@ { GMencoder *coder; GIOChannel *ch; + gchar **oopts; + gchar **vopts; + gchar **aopts; + + GOptionContext *context; + static const GOptionEntry options [] = { + {"input-file", 'i', 0, G_OPTION_ARG_STRING, &input_file, "Input File", NULL}, + {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, "GstElementName for used to video encode", NULL}, + {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, "Properties to set on video element", NULL}, + {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, "Video FPS", NULL}, + {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, "Video rate", NULL}, + {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, "Video width", NULL}, + {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, "Video height", NULL}, + {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, "GstElementName for use to audio encode", NULL}, + {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, "Properties to set on audio element", NULL}, + {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, "Audio rate", NULL}, + {"output-element", 0, 0, G_OPTION_ARG_STRING, &output_element,"GstElementName for use to output", NULL}, + {"output-opts", 0, 0, G_OPTION_ARG_STRING, &output_opts, "Properties to set on output element", NULL}, + { NULL } + }; g_type_init (); + g_thread_init (NULL); + + //g_set_prgname ("gmemcoder"); + context = g_option_context_new (NULL); + g_option_context_set_help_enabled (context, TRUE); + g_option_context_add_main_entries (context, options, NULL); + g_option_context_add_group (context, gst_init_get_option_group ()); + g_option_context_parse (context, &argc, &argv, NULL); + gst_init (&argc, &argv); - g_set_prgname ("gmemcoder"); + if (output_element == NULL) { + g_print ("You need specify output-element name.\nTry --help for more information.\n"); + return 1; + } + + if (input_file == NULL) { + g_print ("You need specify input file\nTry --help for more information.\n"); + } coder = g_mencoder_new (); ch = g_io_channel_unix_new (0); -#ifdef FILE_OUT - int fd = open (argv[2], O_WRONLY | O_CREAT | O_TRUNC); - g_debug ("FD %d", fd); - g_mencoder_setup_stream (coder, argv[1], 320, 288, fd); -#else - g_mencoder_setup_stream (coder, argv[1], 320, 288, atoi (argv[2])); -#endif + aopts = g_strsplit (audio_opts, ",", 0); + vopts = g_strsplit (video_opts, ",", 0); + oopts = g_strsplit (output_opts, ",", 0); + + g_mencoder_setup_stream (coder, + input_file, + video_encode, vopts, video_fps, video_rate, video_width, video_height, + audio_encode, aopts, audio_rate, + output_element, oopts); + + g_strfreev (aopts); + g_strfreev (vopts); + g_strfreev (oopts); mainloop = g_main_loop_new (NULL, FALSE); g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder); @@ -97,9 +152,5 @@ g_main_loop_run (mainloop); -#if FILE_OUT - close (fd); -#endif - return 0; }