没有合适的资源?快使用搜索试试~ 我知道了~
首页python gstreamer实现视频快进/快退/循环播放功能
资源详情
资源评论
资源推荐
python gstreamer实现视频快进实现视频快进/快退快退/循环播放功能循环播放功能
主要介绍了python gstreamer 实现视频快进/快退/循环播放功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
Gstreamer到底是个啥?到底是个啥?
GStreamer 是一个 基于pipeline的多媒体框架,基于GObject,以C语言写成。
应用GStreamer这个这个多媒体框架,你可以写出任意一种流媒体的应用来如:meidaplayer、音视频编辑器、VOIP、流媒体服务器、音视频编码等等。
关于视频快进/快退/循环播放的知识总结:
1.本地视频时长获取本地视频时长获取:
Gst.Pad.query_duration官方函数介绍:
def Gst.Pad.query_duration (self, format):
#python wrapper for 'gst_pad_query_duration'
Queries a pad for the total stream duration.
Parameters:
pad ( Gst.Pad ) –a Gst.Pad to invoke the duration query on.
format ( Gst.Format ) –the Gst.Format requested
Returns a tuple made of:
( gboolean ) –TRUE (not introspectable) if the query could be performed.
duration ( gint64 ) –TRUE (not introspectable) if the query could be performed.
使用如下:
pipeline.query_duration(Gst.Format.TIME)[1]
其中pipeline为播放本地视频的管道,query_duration()函数返回一个元组,元组的形式为[Ture,duration:******],******为以ns为单位的视频时长。
2.视频播放当前位置获取:视频播放当前位置获取:
Gst.Pad.query_position官方函数介绍:
def Gst.Pad.query_position (self, format):
#python wrapper for 'gst_pad_query_position'
Queries a pad for the stream position.
Parameters:
pad ( Gst.Pad ) –a Gst.Pad to invoke the position query on.
format ( Gst.Format ) –the Gst.Format requested
Returns a tuple made of:
( gboolean ) –TRUE (not introspectable) if the query could be performed.
cur ( gint64 ) –TRUE (not introspectable) if the query could be performed.
使用方法与时长获取函数query_duration()相同。
3.播放跳转函数:播放跳转函数:
Gst.Element.seek_simple官方函数介绍:
def Gst.Element.seek_simple (self, format, seek_flags, seek_pos):
#python wrapper for 'gst_element_seek_simple'
Parameters:
element ( Gst.Element ) –a Gst.Element to seek on
format ( Gst.Format ) –a Gst.Format to execute the seek in, such as Gst.Format.TIME
seek_flags ( Gst.SeekFlags ) –seek options; playback applications will usually want to use GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here
seek_pos ( gint64 ) –position to seek to (relative to the start); if you are doing a seek in Gst.Format.TIME this value is in nanoseconds - multiply with Gst.SECOND to convert seconds to nanoseconds or with Gst.MSECOND to convert milliseconds to nanoseconds.
Returns ( gboolean ) :
TRUE (not introspectable) if the seek operation succeeded. Flushing seeks will trigger a preroll, which will emit Gst.MessageType.ASYNC_DONE.
函数使用样例:
pipeline.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, time)
其中time的单位为nanoseconds。
有视频快进/快退/循环播放功能的小播放器.
import os, _thread, time
import gi
gi.require_version("Gst", "1.0")
gi.require_version('Gtk', '3.0')
from gi.repository import Gst, GObject, Gtk, Gdk
class GTK_Main:
def __init__(self):
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, False, False, 0)
hbox = Gtk.HBox()
vbox.add(hbox)
buttonbox = Gtk.HButtonBox()
hbox.pack_start(buttonbox, False, False, 0)
rewind_button = Gtk.Button("Rewind")
rewind_button.connect("clicked", self.rewind_callback)
buttonbox.add(rewind_button)
self.button = Gtk.Button("Start")
self.button.connect("clicked", self.start_stop)
buttonbox.add(self.button)
forward_button = Gtk.Button("Forward")
forward_button.connect("clicked", self.forward_callback)
buttonbox.add(forward_button)
self.time_label = Gtk.Label()
self.time_label.set_text("00:00 / 00:00")
hbox.add(self.time_label)
window.show_all()
self.player = Gst.Pipeline.new("player")
source = Gst.ElementFactory.make("filesrc", "file-source")
demuxer = Gst.ElementFactory.make("decodebin", "demuxer")
videoconv = Gst.ElementFactory.make("videoconvert", "converter")
videosink = Gst.ElementFactory.make("xvimagesink", "video-output")
demuxer.connect("pad-added", self.demuxer_callback, videoconv)
for ele in [source, demuxer, videoconv, videosink]:
self.player.add(ele)
source.link(demuxer)
videoconv.link(videosink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
def start_stop(self, w):
if self.button.get_label() == "Start":
weixin_38621638
- 粉丝: 1
- 资源: 984
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- ExcelVBA中的Range和Cells用法说明.pdf
- 基于单片机的电梯控制模型设计.doc
- 主成分分析和因子分析.pptx
- 共享笔记服务系统论文.doc
- 基于数据治理体系的数据中台实践分享.pptx
- 变压器的铭牌和额定值.pptx
- 计算机网络课程设计报告--用winsock设计Ping应用程序.doc
- 高电压技术课件:第03章 液体和固体介质的电气特性.pdf
- Oracle商务智能精华介绍.pptx
- 基于单片机的输液滴速控制系统设计文档.doc
- dw考试题 5套.pdf
- 学生档案管理系统详细设计说明书.doc
- 操作系统PPT课件.pptx
- 智慧路边停车管理系统方案.pptx
- 【企业内控系列】企业内部控制之人力资源管理控制(17页).doc
- 温度传感器分类与特点.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0