【问题标题】:Python: How can I get the video resolution from a Gst video playbin?Python:如何从 Gst 视频播放箱中获取视频分辨率?
【发布时间】:2016-10-21 15:13:44
【问题描述】:

我有以下代码可以工作并在窗口中显示视频。有人可以帮助我并给出一个简单的 python 示例,说明如何提取视频文件的视频分辨率(宽 x 高)吗?

几天以来我一直坚持这一点......如果有任何帮助,我们将不胜感激。

import os
import Tkinter as tkinter

import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstVideo', '1.0')
from gi.repository import Gst, GObject, GstVideo

def set_frame_handle(bus, message, frame_id):
    if not message.get_structure() is None:
        if message.get_structure().get_name() == 'prepare-window-handle':
            display_frame = message.src
            display_frame.set_property('force-aspect-ratio', True)
            display_frame.set_window_handle(frame_id)

window = tkinter.Tk()
window.title('')
window.geometry('400x300-30-100')

Gst.init(None)
GObject.threads_init()

display_frame = tkinter.Frame(window, bg='')
display_frame.place(relx = 0, rely = 0, anchor = tkinter.NW, relwidth = 1, relheight = 1)
frame_id = display_frame.winfo_id()
player = Gst.ElementFactory.make('playbin', None)
filepath = os.path.realpath('kbps.mp4')
filepath2 = "file:///" + filepath.replace('\\', '/').replace(':', '|')
print filepath2
player.set_property('uri', filepath2)

player.set_state(Gst.State.PLAYING)

bus = player.get_bus()
bus.enable_sync_message_emission()
bus.connect('sync-message::element', set_frame_handle, frame_id)

window.geometry('400x300+30+300')
window.update
window.mainloop()

【问题讨论】:

    标签: python gstreamer playbin2


    【解决方案1】:

    设置 URI 后,将管道设置为 PAUSED 状态。完成后,您应该被预卷,并且可以检查 gst-video-pad 上的当前上限。例如:

    self._playBin.set_state(Gst.State.PAUSED)
    self._playBin.get_state(5000000000)
    videoPad=self._playBin.emit("get-video-pad", 0)
    videoPadCapabilities=videoPad.get_current_caps()(success, videoWidth) = \
    videoPadCapabilities.get_structure(0).get_int("width")
    (success, videoHeight) = \
    videoPadCapabilities.get_structure(0).get_int("height") 
    

    【讨论】:

    • 谢谢,会试试的!
    • 嗨,你能扩大答案吗?对我来说,emit("get-video-pad",0) 出于未知原因返回 None。
    • 您是否已经有一个使用playbin=Gst.ElementFactory.make('playbin',None) 创建的playBin 元素您是否正确设置了URI?你预卷了吗?哪个版本的消费税?
    猜你喜欢
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2015-11-02
    • 2011-07-05
    • 2022-08-03
    • 2017-05-09
    相关资源
    最近更新 更多