我想在同一窗口中显示两张图片。此代码在两个不同的窗口中显示它们。

是否有将两个图片合并在同一窗口中的解决方案?

#include <gst/gst.h>
#include <glib.h>

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 ("End of 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 *decoder = (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 (decoder, "sink");

    gst_pad_link (pad, sinkpad);
    gst_object_unref (sinkpad);
}

int main (int argc, char *argv[]) {
    GMainLoop *loop;
    GstElement *pipeline,*freeze,*clrspace, *source1, *source2, *videobox1,*videobox2, *mixer,*sink,*queuevideo;
    GstBus *bus;

    loop = g_main_loop_new (NULL, FALSE);
    gst_init (&argc, &argv);
    /* Create gstreamer elements */
    pipeline   = gst_pipeline_new ("player");
    source1    = gst_element_factory_make ("playbin2", "dec1");
    source2    = gst_element_factory_make ("playbin2", "dec2");
    freeze     = gst_element_factory_make ("imagefreeze", "fr");
    videobox1  = gst_element_factory_make ("videobox",       "videobox1");
    videobox2  = gst_element_factory_make ("videobox",       "videobox2");
    clrspace   = gst_element_factory_make ("ffmpegcolorspace",       "clrspace");
    mixer      = gst_element_factory_make ("videomixer",       "mixer");
    queuevideo = gst_element_factory_make ("queue", "queue-video");
    sink       = gst_element_factory_make ("autovideosink", "sink");

    if (!pipeline || !source1 || !source2 || !sink || !mixer ||!freeze || !clrspace || !queuevideo ) {
        g_printerr ("One element could not be created. Exiting.\n");
        exit(1);
    }

    g_object_set (source1, "uri", "http://www.logotheque.fr/6396-2/logo+RMC+INFO.jpg", NULL);
    g_object_set (source2, "uri", "http://www.logotheque.fr/6396-2/logo+RMC+INFO.jpg", NULL);

    g_object_set(videobox1,"border-alpha",0,"top",0,"left",0,NULL);
    g_object_set(videobox2,"border-alpha",0,"top",0,"left",-200,NULL);

    /* we add a message handler */
    bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
    gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);

    /* we add all elements into the pipeline */
    gst_bin_add_many (GST_BIN(pipeline), source1,mixer, clrspace, freeze,videobox1, sink, NULL);

    /* we link the elements together */
    gst_element_link_many (source2, mixer, clrspace, freeze,videobox2,sink, NULL);
    //gst_element_link_many(source[1], mixer, NULL);
    g_signal_connect (source1, "pad-added", G_CALLBACK (on_pad_added), queuevideo);
    g_signal_connect (source2, "pad-added", G_CALLBACK (on_pad_added), queuevideo);


    /* Set the pipeline to "playing" state*/
    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    /* Iterate */
    g_print ("Running...\n");
    g_main_loop_run (loop);

    /* Out of the main loop, clean up nicely */
    g_print ("Returned, stopping playback\n");
    gst_element_set_state (pipeline, GST_STATE_NULL);

    g_print ("Deleting pipeline\n");
    gst_object_unref (GST_OBJECT(pipeline));
}

最佳答案

这是从命令行使用gstreamer合并两个图像的方法:

gst-launch-1.0 uridecodebin uri=file:///home/meh/Pictures/questions.jpg ! videoscale ! video/x-raw, width=320, height=240 ! imagefreeze ! videomixer name=m sink_1::xpos=320 ! autovideosink uridecodebin uri=file:///home/meh/Pictures/testsrc.png ! videoscale ! video/x-raw, width=320, height=240 ! imagefreeze ! m.


说明:

我们为图像创建两个解码器,使用视频缩放将它们调整为任意大小(此处为320 x 240),将其冻结并将其发送到videomixer。 videomixer的sink_1的x位置设置为320,它偏移了第一张图像,因此第二张图像也出现了。

关于c - 在同一窗口中加入图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19696324/

10-09 12:42