2016-10-21 121 views
0

我有以下代碼可以在窗口中工作並顯示視頻。有人可以幫助我,並提供一個簡單的python示例,瞭解如何提取視頻文件的視頻分辨率(寬度x高度)?Python:如何從Gst視頻playbin獲取視頻分辨率?

我被困在這個幾天...以及任何幫助將不勝感激。

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() 

回答

0

一旦設置了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") 
+0

謝謝,請嘗試! –