gpt4 book ai didi

linux - 使用 gstreamer 和 gst-launch 循环播放视频?

转载 作者:IT王子 更新时间:2023-10-29 00:46:03 26 4
gpt4 key购买 nike

我可以像这样使用 gstreamer 的 gst-launch 在命令行上播放视频:

gst-launch gnlfilesource location=file:///tmp/myfile.mov start=0 duration=2000000000 ! autovideosink

这会播放/tmp/myfile.mov 中文件的前 2 秒,之后视频播放停止。有没有办法让它重复循环?即将 2 秒长的 gnlfilesource 变成一个无限长的视频,一次又一次地播放这 2 秒?

最佳答案

如果使用 gst-launch 那么您可能必须使用 while true;执行[你的命令];正如 Fredrik 所说,完成了。但是,如果对 C 代码感兴趣,我编写了一个代码,可能会对您有所帮助。在第一次运行的流结束时从文件开头开始每 2 秒循环一次视频。

  //(c) 2011 enthusiasticgeek
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

#include <gst/gst.h>

gboolean bus_callback(GstBus *bus, GstMessage *msg, gpointer data)
{
GstElement *play = GST_ELEMENT(data);
switch (GST_MESSAGE_TYPE(msg))
{
case GST_MESSAGE_EOS:
/* restart playback if at end */
if (!gst_element_seek(play,
1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
GST_SEEK_TYPE_SET, 2000000000, //2 seconds (in nanoseconds)
GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
g_print("Seek failed!\n");
}
break;
default:
break;
}
return TRUE;
}

gint
main (gint argc,
gchar *argv[])
{
GMainLoop *loop;
GstElement *play;
GstBus *bus;

/* init GStreamer */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);

/* make sure we have a URI */
if (argc != 2) {
g_print ("Usage: %s <URI>\n", argv[0]);
return -1;
}

/* set up */
play = gst_element_factory_make ("playbin", "play");
g_object_set (G_OBJECT (play), "uri", argv[1], NULL);

bus = gst_pipeline_get_bus (GST_PIPELINE (play));
gst_bus_add_watch (bus, bus_callback, play);
gst_object_unref (bus);

gst_element_set_state (play, GST_STATE_PLAYING);

/* 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;
}

更新:请参阅以下链接 http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-dataaccess.html

[第 19.1.2 节。播放媒体文件的一个区域]。这可以与我的代码结合使用。

关于linux - 使用 gstreamer 和 gst-launch 循环播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6833147/

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