Linux 使用 gstreamer 和 gst-launch 循环播放视频?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6833147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Looping a video with gstreamer and gst-launch?
提问by Rory
I am able to play a video on the command line with gstreamer's gst-launch
like this:
我可以在命令行上使用 gstreamer 播放视频,gst-launch
如下所示:
gst-launch gnlfilesource location=file:///tmp/myfile.mov start=0 duration=2000000000 ! autovideosink
This plays the first 2 seconds of the file in /tmp/myfile.mov, afterwards the video playback stops. Is there anyway to get this to loop repeatidly? i.e. turn the 2 second long gnlfilesource
into an infinite length video that plays those 2 seconds again and again and again?
这将播放 /tmp/myfile.mov 中文件的前 2 秒,之后视频播放停止。有没有办法让它重复循环?即把 2 秒长gnlfilesource
变成无限长的视频,一遍又一遍地播放那 2 秒?
采纳答案by Fredrik Pihl
Assuming bash...
假设 bash ...
Wrap it in a while
-loop?
将它包裹在一个循环中while
?
while true; do [your command]; done
where true
does nothing sucessfully, i.e.
哪里true
没有成功,即
true: true
Return a successful result.
Exit Status:
Always succeeds.
It allows you to create infinite loops, e.g.
它允许您创建无限循环,例如
$ while true; do echo "run..."; sleep 1; done
run...
run...
run...
run...
run...
...
回答by Rory
According to folks on the #gstreamer
IRC channel, you can't do this with gstreamer itself, you'd need something outside the gstreamer pipeline to loop it.
根据#gstreamer
IRC 频道上的人的说法,你不能用 gstreamer 本身来做到这一点,你需要 gstreamer 管道之外的东西来循环它。
回答by enthusiasticgeek
If using gst-launch then you may have to use while true; do [your command]; done
as Fredrik has stated. However if interested in C code, I have written a code which may help you. Looping of video every 2 seconds from the beginning of the file at the end of the stream of first run.
如果使用 gst-launch 那么您可能必须使用while true; do [your command]; done
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;
}
Update:See the following link http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-dataaccess.html
更新:请参阅以下链接 http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-dataaccess.html
[Section 19.1.2. Play a region of a media file]. This could be used in conjugation with my code.
[第 19.1.2 节。播放媒体文件的一个区域]。这可以与我的代码结合使用。
回答by Baris Demiray
This seems to be possible with multifilesrc
plugin,
这似乎可以通过multifilesrc
插件实现,
gst-launch-1.0 multifilesrc location=alien-age.mpg loop=true ! decodebin ! autovideosink
Seems to be added back in June 2011.
似乎是在 2011 年 6 月添加回来的。