怎么在python中使用gstreamer循环播放视频

  介绍

本篇文章给大家分享的是有关怎么在python中使用gstreamer循环播放视频,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

<强> 1。本地视频时长获取:

Gst.Pad。query_duration官方函数介绍:

def  Gst.Pad.query_duration (自我,,格式):   ,# python  wrapper  for  & # 39; gst_pad_query_duration& # 39;      Queries  a  pad  for 从而total  stream 持续时间。      参数:   pad  (), Gst.Pad , -a  Gst.Pad 用invoke 从而duration  query 。   format  (, Gst.Format ),从而,Gst.Format 请求      Returns  a  tuple  made :   (,gboolean ), -TRUE  (not  introspectable), if 从而query  could  be 执行。   duration  (), gint64 , -TRUE  (not  introspectable), if 从而query  could  be 执行。

使用如下:

pipeline.query_duration (Gst.Format.TIME) [1]

其中管道为播放本地视频的管道,query_duration()函数返回一个元组,元组的形式为(真正的、持续时间:* * * * * *),* * * * * *为以ns为单位的视频时长。

<强> 2。视频播放当前位置获取:

Gst.Pad。query_position官方函数介绍:

def  Gst.Pad.query_position (自我,,格式):   ,# python  wrapper  for  & # 39; gst_pad_query_position& # 39;      Queries  a  pad  for 从而stream 位置。      参数:   pad  (), Gst.Pad , -a  Gst.Pad 用invoke 从而position  query 。   format  (, Gst.Format ),从而,Gst.Format 请求      Returns  a  tuple  made :   (,gboolean ), -TRUE  (not  introspectable), if 从而query  could  be 执行。   cur  (), gint64 , -TRUE  (not  introspectable), if 从而query  could  be 执行。

使用方法与时长获取函数<代码> query_duration() 相同。

<强> 3。播放跳转函数:

Gst.Element。seek_simple官方函数介绍:

def  Gst.Element.seek_simple (自我,时间格式,大敌;;seek_flags, seek_pos):   ,# python  wrapper  for  & # 39; gst_element_seek_simple& # 39;   ,   参数:   element  (), Gst.Element , -a  Gst.Element 用seek    format  (), Gst.Format , -a  Gst.Format 用execute 从而seek , such  as  Gst.Format.TIME   seek_flags  (), Gst.SeekFlags , -seek 选项;,playback  applications  will  usually  want 用use  GST_SEEK_FLAG_FLUSH  |, GST_SEEK_FLAG_KEY_UNIT 这里   seek_pos  (), gint64 , -position 用seek 用(relative 用,并开始);,if 你断开连接;doing  a  seek  Gst.Format.TIME 却;能够拷贝value  is 拷贝nanoseconds 作用;multiply  with  Gst.SECOND 用convert  seconds 用nanoseconds 或是with  Gst.MSECOND 用convert  milliseconds 用纳秒。      Returns  (, gboolean ),:   TRUE  (not  introspectable), if 从而seek  operation 成功只Flushing  seeks  will  trigger  a 前滚,,which  will  emit  Gst.MessageType.ASYNC_DONE。

函数使用样例:

pipeline.seek_simple (Gst.Format。时间,Gst.SeekFlags。冲洗时间)

其中时间的单位为纳秒。

有视频快进/快退/循环播放功能的小播放器。

 import 操作系统,_thread,,时间
  import 胃肠道
  gi.require_version (“Gst",,“1.0”)
  gi.require_version (& # 39; gtk # 39;,, & # 39; 3.0 & # 39;)
  得到gi.repository  import 消费税,GObject,, Gtk, Gdk
  class  GTK_Main:
  自我,def  __init__ ():
  时间=window 才能;Gtk.Window (Gtk.WindowType.TOPLEVEL)
  window.set_title才能(“Vorbis-Player")
  window.set_default_size才能(500,1)
  window.connect才能(“destroy",, Gtk.main_quit,,“WM  destroy")
  时间=vbox 才能;Gtk.VBox ()
  window.add才能(vbox)
  时间=self.entry 才能;Gtk.Entry ()
  vbox.pack_start才能(self.entry,,假的,假的,,0)
  hbox 才能=,gtk . hbox ()
  vbox.add才能(hbox)
  时间=buttonbox 才能;Gtk.HButtonBox ()
  hbox.pack_start才能(buttonbox,,假的,假的,,0)
  时间=rewind_button 才能;Gtk.Button (“Rewind")
  rewind_button.connect才能(“clicked",, self.rewind_callback)
  buttonbox.add才能(rewind_button)
  时间=self.button 才能;Gtk.Button(“时)
  self.button.connect才能(“clicked",, self.start_stop)
  buttonbox.add才能(self.button)
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null
  null

怎么在python中使用gstreamer循环播放视频