"Resource not found"

Stefan Kost ensonic at hora-obscura.de
Thu Sep 8 11:35:54 PDT 2011


On 09/06/11 08:12, rg wrote:
> Hello, I am totally new with GStreamer, I attemp to achieve a
> crossfade effect between 2 videos.
> When I run the application I get the "Resource not found" error.
Are both video URL correct?

Stefan


>
> the idea behind crossfade is to add an alpha channel to both streams.
> A video mixer mixes them according to the alpha channel. Then a
> control on the alpha channel to linearly sweep it over the duration of
> the crossfade. The returned bin should get placed in a
> gnloperation.The reason to put the alpha and final ffmpegcolorspace
> conversion in this bin is that are only applied during the crossfade
> and not all the time (saves some processing time). We play two clips
> serially with a crossfade between them using the gnonlin
> gnlcomposition element.
>
> thanks for any tip I don't know if I am applying this idea in the
> right way
>
> #include <gst.h>
> #include <controller/gstcontroller.h>
>
> #include <iostream>
>
> using namespace std;
>
> // Manejador de errores
> static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
> {
>     GMainLoop *loop = (GMainLoop *) data;
>
>     switch (GST_MESSAGE_TYPE (msg))
>     {
>     case GST_MESSAGE_EOS:
>         g_print ("Final de stream\n");
>         g_main_loop_quit (loop);
>         break;
>     case GST_MESSAGE_ERROR:
>     {
>         gchar *debug;
>         GError *error;
>         gst_message_parse_error (msg, &error, &debug);
>         g_free (debug);
>         g_printerr ("Error: %s\n", error->message);
>         g_error_free (error);
>         g_main_loop_quit (loop);
>         break;
>     }
>     default:
>         break;
>     }
>     return TRUE;
> }
>
> static void on_pad_added (GstElement *element, GstPad *pad, gpointer 
> data)
> {
>   GstPad *sinkpad;
>   GstElement * queue = (GstElement *) data;
>
>   /* We can now link this pad with the vorbis-decoder sink pad */
>   g_print ("Dynamic pad created, linking demuxer/decoder\n");
>   sinkpad = gst_element_get_static_pad (queue, "sink");
>
>   gst_pad_link (pad, sinkpad);
>
>   gst_object_unref (sinkpad);
> }
>
> GstElement * getBin(const gchar * nomBin, GstElement * &alfa1,
> GstElement *&alfa2, GstElement * &color)
> {
>
>   GstElement * bin = gst_bin_new(nomBin);
>
>   if (!bin)
>   {
>       g_printerr ("No se pudo crear el bin. Saliendo\n");
>      return NULL;
>   }
>
>   alfa1   = gst_element_factory_make ("alpha","alfa1");
>   alfa2  = gst_element_factory_make ("alpha","alfa2");
>   color  = gst_element_factory_make ("ffmpegcolorspace", "color");
>   GstElement * mixer  = gst_element_factory_make("videomixer", "mixer");
>
>   if ((!alfa1) || (!alfa2) || (!color) || (!mixer))
>   {
>       g_printerr ("Alguno de los elementos del Bin no pudo ser creado.
> Saliendo\n");
>      return NULL;
>   }
>
>   // Anexamos al bin
>   gst_bin_add_many(GST_BIN (bin),alfa1,alfa2,mixer,color,NULL);
>
>   // Enlazamos elementos
>   gst_element_link (alfa1, mixer);
>   gst_element_link (alfa2, mixer);
>   gst_element_link (mixer,color);
>
>   return bin;
> }
>
> void getAndSetController(GstElement * alfa2, gdouble duracion)
> {
>     GstController * ctrl = NULL;
>     if (!(ctrl = gst_controller_new (G_OBJECT (alfa2), "alpha",NULL))) {
>         GST_WARNING ("No puede controlar el elemento fuente\n");
>         return;
>   }
>
>   // Todo valor GValue debe inicializarse en 0
>   GValue val_double = { 0, };
>   g_value_init (&val_double, G_TYPE_DOUBLE);
>
>
>   // Seteo los valores de control del alfa2
>
>   GstInterpolationControlSource * csource =
> gst_interpolation_control_source_new();
>   cout << "creo interpolacion" << endl;
>
>   gst_controller_set_control_source (ctrl, "alpha", GST_CONTROL_SOURCE
> (csource));
>
>  
> gst_interpolation_control_source_set_interpolation_mode(csource,GST_INTERPOLATE_LINEAR);
>
>
>   cout << "seteo modo interpolacion" << endl;
>
>   g_value_set_double(&val_double, 0.0);
>   cout << "seteo primer valor" << endl;
>   gst_interpolation_control_source_set(csource,(0*
> GST_MSECOND),&val_double);
>   cout << "asigno valor ini modo interpolacion" << endl;
>
>   g_value_set_double (&val_double, duracion);
>   cout << "seteo 2º valor" << endl;
>   gst_interpolation_control_source_set(csource,(1 *
> GST_MSECOND),&val_double);
>   cout << "asigno valor fin modo interpolacion" << endl;
>
>   //gst_controller_set_control_source (ctrl, "alpha",
> GST_CONTROL_SOURCE (csource));
>
>   g_object_unref (csource);
>
>   //return ctrl;
> }
>
> void addGhostPadsToBin(GstElement *alfa1, GstElement * alfa2,
> GstElement * color, GstElement* bin)
> {
>     /* add ghostpad */
>   GstPad * pad1 = gst_element_get_static_pad (alfa1, "sink");
>   gst_element_add_pad(bin, gst_ghost_pad_new("alfasink1", pad1));
>   gst_object_unref (GST_OBJECT (pad1));
>
>   GstPad * pad2 = gst_element_get_static_pad (alfa2, "sink");
>   gst_element_add_pad(bin, gst_ghost_pad_new("alfasink2", pad2));
>   gst_object_unref(GST_OBJECT(pad2));
>
>   GstPad * pad3 = gst_element_get_static_pad (color, "src");
>   gst_element_add_pad(bin, gst_ghost_pad_new("colorsrc", pad3));
>   gst_object_unref(GST_OBJECT(pad3));
>
>
>   /* create element, add to bin */
> //sink = gst_element_factory_make ("fakesink", "sink");
> //bin = gst_bin_new ("mybin");
> //gst_bin_add (GST_BIN (bin), sink);
> /* add ghostpad */
> //pad = gst_element_get_static_pad (sink, "sink");
> //gst_element_add_pad (bin, gst_ghost_pad_new ("sink", pad));
>
> /*
> bin.add_pad(gst.GhostPad("sink1", alpha1.get_pad("sink")))
>     bin.add_pad(gst.GhostPad("sink2", alpha2.get_pad("sink")))
>     bin.add_pad(gst.GhostPad("src",   color.get_pad("src")))
>
>
> */
>
> }
>
> void crossFade(gdouble duracion, GstElement * & bin)
> {
>     // devuelve el bin
>     GstElement * alfa1, *alfa2, *color;
>     alfa1 = 0;
>     alfa2 = 0;
>     color = 0;
>
>     bin = getBin("bin",alfa1, alfa2,color);  // Crea el bin y los
> elementos
>
>     getAndSetController(alfa2,duracion);
>
>     addGhostPadsToBin(alfa1, alfa2, color, bin);
>
>     cout << "hizo crossfade!" << endl;
>
> }
>
> GstElement * getSetPipeline(gchar *argv[])
> {
>     gint dur1 = 9000; // duration (in ms) to play of first clip
>     gint dur2 = 8000; // duration (in ms) to play of second clip
>     gint dur_crossfade = 500; //number of milliseconds to crossfade for
>     GstElement *comp = 0;
>     GstElement *pipeline, *video1, *video2, *op, *bin, *queue, *sink;
>
>      //we play two clips serially with a crossfade between them
>      // using the gnonlin gnlcomposition element.
>     if ((comp = gst_element_factory_make("gnlcomposition",
> "mycomposition")) == NULL)
>     {
>       printf ("\n Fallo al crear gnlcomposition \n");
>       return NULL;
>     }
>
>     // setup first clip
>
>     if ((video1 = gst_element_factory_make("gnlfilesource", "video1"))
> == NULL)
>     {
>       printf ("\n Falló la creacion del gnlfilesource \n");
>       return NULL;
>     }
>     if (gst_bin_add (GST_BIN (comp), video1) == FALSE)
>     {
>       printf ("\n No pudo agregar video1 a comp \n");
>       return NULL;
>     }
>
>     //location "/home/lane/work/sshow/src/test1.mp4"
>     g_object_set (video1, "location", argv[1], NULL);
>     g_object_set (video1, "start", 0 * GST_MSECOND, NULL);
>     g_object_set (video1, "duration", dur1 * GST_MSECOND, NULL);
>     g_object_set (video1, "media-start", 0* GST_MSECOND, NULL);
>     g_object_set (video1, "media-duration", dur1 * GST_MSECOND, NULL);
>     g_object_set (video1, "priority", 1,NULL);
>
>     if ((video2 = gst_element_factory_make("gnlfilesource", "video2"))
> == NULL)
>     {
>       printf ("\n Falló la creacion del gnlfilesource \n");
>       return NULL;
>     }
>     if (gst_bin_add (GST_BIN (comp), video2) == FALSE)
>     {
>       printf ("\n No pudo agregar video2 a comp \n");
>       return NULL;
>     }
>
>     // setup second clip
>     //location "/home/lane/work/sshow/src/test2.mp4"
>     g_object_set (video2, "location", argv[2], NULL);
>     g_object_set (video2, "start", (dur1-dur_crossfade) * GST_MSECOND,
> NULL);
>     g_object_set (video2, "duration", dur2 * GST_MSECOND, NULL);
>     g_object_set (video2, "media-start", 0 * GST_MSECOND, NULL);
>     g_object_set (video2, "media-duration", dur2 * GST_MSECOND, NULL);
>     g_object_set (video2, "priority", 2,NULL);
>
>     // setup the crossfade
>     op = gst_element_factory_make("gnloperation", "op");
>
>     crossFade(dur_crossfade, bin);
>
>     if (gst_bin_add (GST_BIN (op), bin) == FALSE)
>     {
>       printf ("\n No pudo agregar el bin a la gnloperacion op \n");
>       return NULL;
>     }
>
>     g_object_set (op,"start", (dur1-dur_crossfade) * GST_MSECOND,NULL);
>     g_object_set (op,"duration", dur_crossfade *  GST_MSECOND,NULL);
>     g_object_set (op,"media-start", 0 *  GST_MSECOND,NULL);
>     g_object_set(op,"media-duration", dur_crossfade * GST_MSECOND,NULL);
>     g_object_set(op,"priority",0,NULL);
>
>     if (gst_bin_add (GST_BIN (comp), op) == FALSE)
>     {
>       printf ("\n No pudo agregar la gnloperacion a la gnlcomposition
> \n");
>       return NULL;
>     }
>
>     // setup the backend viewer
>     queue = gst_element_factory_make("queue", "queue");
>     sink  = gst_element_factory_make("autovideosink", "sink");
>
>     pipeline = gst_pipeline_new ("video-player");
>
>
>     /* Agrego elementos al pipeline */
>
>     gst_bin_add_many (GST_BIN (pipeline),comp, queue, sink, NULL);
>
>     g_signal_connect (comp, "pad-added", G_CALLBACK (on_pad_added),
> queue);
>
>     gst_element_link (queue, sink);
>
>     cout << "creó pipeline!!!" << endl;
>
>     return pipeline;
>
> }
>
> void startPlay(GstElement * pip)
> {
>     /* Set the pipeline to "playing" state*/
>   cout << "antes del PLAY" << endl;
>   gst_element_set_state (pip, GST_STATE_PLAYING);
>   cout << "dp del PLAY" << endl;
>
> }
>
>
> int main(gint argc, gchar *argv[])
> {
>     GMainLoop *loop = NULL;
>
>     /* init GStreamer */
>     gst_init (&argc, &argv);
>     gst_controller_init (&argc, &argv);
>
>
>     loop = g_main_loop_new (NULL, FALSE);
>
>     /* make sure we have a URI */
>     if (argc != 3)
>     {
>         g_print ("Uso: %s <URI1> <URI2>\n", argv[0]);
>         return -1;
>     }
>
>     GstElement * play = getSetPipeline(argv);
>
>     cout << "creo pipeline" << endl;
>
>     //"<" and ">"
>
>     GstBus *bus2 = gst_pipeline_get_bus (GST_PIPELINE (play));
>     gst_bus_add_watch (bus2, bus_call, loop);
>     gst_object_unref (bus2);
>
>     cout << "comienza el play" << endl;
>
>     startPlay(play);
>
>     /* now run */
>     g_main_loop_run (loop);
>
>     /* also clean up */
>     gst_element_set_state (play, GST_STATE_NULL);
>     gst_object_unref (GST_OBJECT (play));
>     return 0;
> }
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



More information about the gstreamer-devel mailing list