renatofilho@586: #include renatofilho@586: #include renatofilho@586: #include renatofilho@586: #include renatofilho@586: renatofilho@586: #include morphbr@748: #include renatofilho@586: renatofilho@588: #include "gmencoder.h" renatofilho@586: renatofilho@588: #define FILE_OUT 1 renatofilho@586: renatofilho@586: static GMainLoop *mainloop = NULL; renatofilho@588: /* Options */ renatofilho@588: static gchar* input_file = NULL; renatofilho@588: static gchar* video_encode = NULL; renatofilho@588: static gchar* video_opts = NULL; renatofilho@588: static gdouble video_fps = 0.0; renatofilho@588: static gint video_rate = 0; renatofilho@588: static gint video_width = 0; renatofilho@588: static gint video_height = 0; renatofilho@588: static gchar* audio_encode = NULL; renatofilho@588: static gchar* audio_opts = NULL; renatofilho@588: static double audio_rate = 0.0; renatofilho@600: static gchar* mux_name = NULL; renatofilho@600: static gchar* output_uri = NULL; renatofilho@586: renatofilho@586: renatofilho@678: renatofilho@678: static gboolean renatofilho@678: _quit (gpointer data) renatofilho@678: { morphbr@748: g_object_unref (data); morphbr@748: g_main_loop_quit (mainloop); morphbr@748: return FALSE; renatofilho@678: } renatofilho@678: renatofilho@586: static void renatofilho@586: _mencoder_eos_cb (GMencoder *mencoder, gpointer data) morphbr@748: { renatofilho@586: g_print ("EOS\n"); morphbr@748: g_idle_add (_quit, mencoder); renatofilho@586: } renatofilho@586: renatofilho@678: renatofilho@586: static void renatofilho@586: _mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data) renatofilho@586: { renatofilho@586: g_print ("Error: %s\n", msg); morphbr@748: g_idle_add (_quit, mencoder); renatofilho@586: } renatofilho@586: renatofilho@586: static gboolean renatofilho@586: _io_channel_cb (GIOChannel *ch, renatofilho@586: GIOCondition condition, renatofilho@586: gpointer data) renatofilho@586: { renatofilho@586: GString *cmd = g_string_new (""); renatofilho@586: g_io_channel_read_line_string (ch, cmd, NULL, NULL); renatofilho@586: renatofilho@586: if (strcmp (cmd->str, "PLAY\n") == 0) { renatofilho@586: g_mencoder_play_stream (G_MENCODER (data)); renatofilho@586: } else if (strcmp (cmd->str, "PAUSE\n") == 0) { renatofilho@586: g_mencoder_pause_stream (G_MENCODER (data)); renatofilho@586: } else if (strcmp (cmd->str, "STOP\n") == 0) { renatofilho@586: g_mencoder_close_stream (G_MENCODER (data)); renatofilho@586: } else if (strcmp (cmd->str, "QUIT\n") == 0) { renatofilho@586: g_mencoder_close_stream (G_MENCODER (data)); renatofilho@586: g_main_loop_quit (mainloop); renatofilho@586: } renatofilho@586: g_string_free (cmd, TRUE); renatofilho@586: return TRUE; renatofilho@586: } renatofilho@586: morphbr@748: int renatofilho@586: main (int argc, char** argv) renatofilho@586: { renatofilho@600: GMencoder *coder = NULL; renatofilho@586: GIOChannel *ch; renatofilho@588: gchar **vopts; renatofilho@588: gchar **aopts; renatofilho@600: gchar **files; renatofilho@600: gint i; renatofilho@588: renatofilho@588: GOptionContext *context; renatofilho@588: static const GOptionEntry options [] = { morphbr@748: {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file, morphbr@748: "Input File", NULL}, morphbr@748: morphbr@748: {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, morphbr@748: "GstElementName for used to video encode", NULL}, morphbr@748: morphbr@748: {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, morphbr@748: "Properties to set on video element", NULL}, morphbr@748: morphbr@748: {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, morphbr@748: "Video FPS", NULL}, morphbr@748: morphbr@748: {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, morphbr@748: "Video rate", NULL}, morphbr@748: morphbr@748: {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, morphbr@748: "Video width", NULL}, morphbr@748: morphbr@748: {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, morphbr@748: "Video height", NULL}, morphbr@748: morphbr@748: {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, morphbr@748: "GstElementName for use to audio encode", NULL}, morphbr@748: morphbr@748: {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, morphbr@748: "Properties to set on audio element", NULL}, morphbr@748: morphbr@748: {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, morphbr@748: "Audio rate", NULL}, morphbr@748: morphbr@748: {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name, morphbr@748: "GstElementName for use to mux file", NULL}, morphbr@748: morphbr@748: {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri, morphbr@748: "Uri to output", NULL}, morphbr@748: renatofilho@588: { NULL } renatofilho@588: }; renatofilho@586: morphbr@748: g_type_init (); renatofilho@588: g_thread_init (NULL); morphbr@748: mainloop = g_main_loop_new (NULL, FALSE); renatofilho@588: morphbr@748: g_set_prgname ("gmemcoder"); renatofilho@588: context = g_option_context_new (NULL); renatofilho@588: g_option_context_set_help_enabled (context, TRUE); renatofilho@588: g_option_context_add_main_entries (context, options, NULL); renatofilho@588: g_option_context_add_group (context, gst_init_get_option_group ()); renatofilho@588: g_option_context_parse (context, &argc, &argv, NULL); renatofilho@588: morphbr@748: gst_init (&argc, &argv); renatofilho@586: renatofilho@600: if (output_uri == NULL) { morphbr@748: g_print ("You need to specify output-uri.\nTry --help " morphbr@748: "for more information.\n"); morphbr@748: return 1; renatofilho@588: } renatofilho@588: renatofilho@588: if (input_file == NULL) { morphbr@748: g_print ("You need to specify input file\nTry --help " morphbr@748: "for more information.\n"); renatofilho@588: } renatofilho@586: renatofilho@586: coder = g_mencoder_new (); renatofilho@586: ch = g_io_channel_unix_new (0); renatofilho@586: renatofilho@588: aopts = g_strsplit (audio_opts, ",", 0); renatofilho@588: vopts = g_strsplit (video_opts, ",", 0); renatofilho@588: morphbr@748: g_mencoder_setup_stream (coder, mux_name, morphbr@748: video_encode, vopts, video_fps, morphbr@748: video_rate, video_width, video_height, morphbr@748: audio_encode, aopts, audio_rate, morphbr@748: output_uri); renatofilho@588: renatofilho@600: files = g_strsplit (input_file, ",", 0); renatofilho@600: for (i=0; i < g_strv_length (files); i++) { renatofilho@600: if (!g_mencoder_append_uri (coder, files[i])) { renatofilho@600: g_debug ("Invalid uri: %s", files[i]); morphbr@748: } renatofilho@600: } morphbr@748: renatofilho@600: g_strfreev (files); renatofilho@588: g_strfreev (aopts); renatofilho@588: g_strfreev (vopts); renatofilho@586: renatofilho@600: morphbr@748: g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder); renatofilho@586: renatofilho@586: g_signal_connect (G_OBJECT (coder), morphbr@748: "eos", morphbr@748: G_CALLBACK (_mencoder_eos_cb), morphbr@748: mainloop); renatofilho@586: renatofilho@586: g_signal_connect (G_OBJECT (coder), morphbr@748: "error", morphbr@748: G_CALLBACK (_mencoder_error_cb), morphbr@748: mainloop); renatofilho@586: renatofilho@600: g_mencoder_play_stream (coder); renatofilho@600: renatofilho@600: g_debug ("RUNNING.."); morphbr@748: g_main_loop_run (mainloop); morphbr@748: g_debug ("DONE"); renatofilho@600: g_object_unref (coder); renatofilho@600: morphbr@748: return 0; renatofilho@586: }