bugfix
This commit is contained in:
parent
f4e8d384c5
commit
b80987ce72
@ -9,7 +9,8 @@ from kivy.factory import Factory
|
|||||||
from kivy.app import App
|
from kivy.app import App
|
||||||
from kivy.core.window import Window
|
from kivy.core.window import Window
|
||||||
from kivy.uix.image import Image
|
from kivy.uix.image import Image
|
||||||
from kivy.uix.widget import Widget
|
from kivy.uix.label import Label
|
||||||
|
from kivy.uix.boxlayout import BoxLayout
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
from kivy.properties import StringProperty, BooleanProperty, \
|
from kivy.properties import StringProperty, BooleanProperty, \
|
||||||
OptionProperty, NumericProperty
|
OptionProperty, NumericProperty
|
||||||
@ -33,14 +34,22 @@ vhks = ['v_src',
|
|||||||
'repeat'
|
'repeat'
|
||||||
]
|
]
|
||||||
|
|
||||||
class FFVideo(WidgetReady, VideoBehavior, Widget):
|
class FFVideo(WidgetReady, VideoBehavior, BoxLayout):
|
||||||
def __init__(self, **kw):
|
def __init__(self, **kw):
|
||||||
kw1 = {k:v for k,v in kw.items() if k in vhks}
|
kw1 = {k:v for k,v in kw.items() if k in vhks}
|
||||||
kw1['renderto'] = 'background'
|
kw1['renderto'] = 'background'
|
||||||
kw2 = {k:v for k,v in kw.items() if k not in vhks}
|
kw2 = {k:v for k,v in kw.items() if k not in vhks}
|
||||||
Widget.__init__(self, **kw2)
|
kw2['orientation'] = 'vertical'
|
||||||
|
BoxLayout.__init__(self, **kw2)
|
||||||
VideoBehavior.__init__(self, **kw1)
|
VideoBehavior.__init__(self, **kw1)
|
||||||
WidgetReady.__init__(self)
|
WidgetReady.__init__(self)
|
||||||
|
self.msg_w = Label(text='Hello')
|
||||||
|
self.add_widget(self.msg_w)
|
||||||
|
self.bind(on_frame=self.show_info)
|
||||||
|
|
||||||
|
def show_info(self, o, d):
|
||||||
|
txt = f"size={d['size']}, vpos={d['pos']}, vsize={d['texture_size']}"
|
||||||
|
self.msg_w.text = txt
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class FFVideo(WidgetReady, Image):
|
class FFVideo(WidgetReady, Image):
|
||||||
|
@ -1 +1 @@
|
|||||||
__version__ = '0.4.5'
|
__version__ = '0.4.6'
|
||||||
|
@ -145,13 +145,6 @@ class VideoBehavior(object):
|
|||||||
|
|
||||||
def on_frame(self, *args):
|
def on_frame(self, *args):
|
||||||
return
|
return
|
||||||
w = self.get_root_window()
|
|
||||||
if w is None:
|
|
||||||
self.status = 'stop'
|
|
||||||
print('root is None................')
|
|
||||||
|
|
||||||
if self._player is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._play_stop()
|
self._play_stop()
|
||||||
@ -301,7 +294,7 @@ class VideoBehavior(object):
|
|||||||
size=self.size, colorfmt='rgb')
|
size=self.size, colorfmt='rgb')
|
||||||
buf = b'\x00' * int(self.width * self.height * 3)
|
buf = b'\x00' * int(self.width * self.height * 3)
|
||||||
image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
|
image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')
|
||||||
self.texture = image_texture
|
self._draw_texture(image_texture, *self.size)
|
||||||
self.is_black = True
|
self.is_black = True
|
||||||
|
|
||||||
def show_yuv420(self, img):
|
def show_yuv420(self, img):
|
||||||
@ -346,14 +339,23 @@ class VideoBehavior(object):
|
|||||||
# print('img_size=', w, h, 'window size=', self.size)
|
# print('img_size=', w, h, 'window size=', self.size)
|
||||||
|
|
||||||
def draw_texture(self, texture, w, h):
|
def draw_texture(self, texture, w, h):
|
||||||
if self.width != w and self.height != h:
|
d = self._draw_texture(texture, w, h)
|
||||||
self.set_video_size()
|
if d:
|
||||||
return
|
self.dispatch('on_frame', d)
|
||||||
|
|
||||||
|
def _draw_texture(self, texture, w, h):
|
||||||
|
if abs(self.width - w) > 1 and abs(self.height - h) > 1:
|
||||||
|
self._set_video_size()
|
||||||
|
if w > self.width:
|
||||||
|
w = self.width
|
||||||
|
if h > self.height:
|
||||||
|
h = self.height
|
||||||
canvas = self.canvas
|
canvas = self.canvas
|
||||||
if self.renderto == 'background':
|
if self.renderto == 'background':
|
||||||
canvas = self.canvas.before
|
canvas = self.canvas.before
|
||||||
elif self.renderto == 'cover':
|
elif self.renderto == 'cover':
|
||||||
canvas = self.canvas.after
|
canvas = self.canvas.after
|
||||||
|
p = 0
|
||||||
if self.duration > 0:
|
if self.duration > 0:
|
||||||
p = self.position / self.duration * self.width
|
p = self.position / self.duration * self.width
|
||||||
pos = (self.width - w)/2, (self.height - h)/2
|
pos = (self.width - w)/2, (self.height - h)/2
|
||||||
@ -364,6 +366,15 @@ class VideoBehavior(object):
|
|||||||
Line(points=[0, 1, self.width, 1], width=2)
|
Line(points=[0, 1, self.width, 1], width=2)
|
||||||
Color(1,0,0,1)
|
Color(1,0,0,1)
|
||||||
Line(points=[0,1,p,1], width=2)
|
Line(points=[0,1,p,1], width=2)
|
||||||
|
d = {
|
||||||
|
'texture':texture,
|
||||||
|
'position':self.position,
|
||||||
|
'duration':self.duration,
|
||||||
|
'pos':pos,
|
||||||
|
'texture_size':(w, h),
|
||||||
|
'size':self.size
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
|
||||||
def video_handle(self, *args):
|
def video_handle(self, *args):
|
||||||
if self._update_task:
|
if self._update_task:
|
||||||
@ -420,7 +431,6 @@ class VideoBehavior(object):
|
|||||||
self.show_yuv420(img)
|
self.show_yuv420(img)
|
||||||
else:
|
else:
|
||||||
self.show_others(img)
|
self.show_others(img)
|
||||||
self.dispatch('on_frame', self.last_frame)
|
|
||||||
self.last_frame = None
|
self.last_frame = None
|
||||||
self.vh_task = Clock.schedule_once(self.video_handle, 0)
|
self.vh_task = Clock.schedule_once(self.video_handle, 0)
|
||||||
self.block_task = Clock.schedule_once(self.video_blocked, self.timeout)
|
self.block_task = Clock.schedule_once(self.video_blocked, self.timeout)
|
||||||
|
Loading…
Reference in New Issue
Block a user