gpt4 book ai didi

c - 在同一窗口中加入图片

转载 作者:行者123 更新时间:2023-11-30 19:48:16 25 4
gpt4 key购买 nike

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

有没有办法在同一窗口中连接两张图片?

#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.

说明:

我们为图像创建两个解码器,使用 videoscale 将它们调整为任意大小(此处为 320 x 240),卡住它们并将它们发送到 videomixer。 videomixer 将 sink_1 的 x 位置设置为 320,这会偏移第一个图像,以便第二个图像也出现。

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com