python kivy添加背景视频mp4
可以在kivy中播放视频(mp4)作为背景吗?我正在使用下面的代码,但没有加载视频python kivy添加背景视频mp4,python,linux,kivy,Python,Linux,Kivy,可以在kivy中播放视频(mp4)作为背景吗?我正在使用下面的代码,但没有加载视频 __author__ = 'kshk' import kivy kivy.require('1.8.0') from kivy.app import App from kivy.uix.label import Label from kivy.uix.gridlayout import GridLayout from kivy.uix.textinput import TextInput from kivy.
__author__ = 'kshk'
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.video import Video
class Dashboard(GridLayout):
def __init__(self, **kwargs):
super(Dashboard,self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text="Login"))
self.username = TextInput(multiline=False)
self.add_widget(self.username)
self.add_widget(Label(text="Password"))
self.password = TextInput(password=True,multiline=False)
self.add_widget(self.password)
self.video = Video(source="/tmpt/driver.mp4")
self.add_widget(self.video)
class MyApp(App):
def build(self):
return Dashboard()
if __name__ == '__main__':
MyApp().run()
更新:
/usr/bin/python /home/kshk/PycharmProjects/KSHK-PYQT1/main.py
[INFO ] Kivy v1.8.0
[INFO ] [Logger ] Record log in /home/kshk/.kivy/logs/kivy_14-07-13_58.txt
[INFO ] [Factory ] 157 symbols loaded
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
[INFO ] [Text ] Provider: pygame
[DEBUG ] [Cache ] register <kv.loader> with limit=500, timeout=60s
[INFO ] [Loader ] using a thread pool of 2 workers
[DEBUG ] [Cache ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG ] [Cache ] register <textinput.width> with limit=None, timeout=60.0s
[DEBUG ] [Video ] Ignored <pygst> (import error)
[DEBUG ] [Video ] Ignored <ffmpeg> (import error)
[DEBUG ] [Video ] Ignored <pyglet> (import error)
[INFO ] [Video ] Provider: null(['video_pygst', 'video_ffmpeg', 'video_pyglet'] ignored)
[DEBUG ] [App ] Loading kv </home/kshk/PycharmProjects/KSHK-PYQT1/my.kv>
[DEBUG ] [App ] kv </home/kshk/PycharmProjects/KSHK-PYQT1/my.kv> not found
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
libpng warning: iCCP: known incorrect sRGB profile
[WARNING ] [WinPygame ] Video: failed (multisamples=2)
[WARNING ] [WinPygame ] trying without antialiasing
[DEBUG ] [Window ] Display driver x11
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a0
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 0
[INFO ] [GL ] OpenGL version <2.1 Mesa 10.1.5>
[INFO ] [GL ] OpenGL vendor <VMware, Inc.>
[INFO ] [GL ] OpenGL renderer <Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits)>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <1.30>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load </usr/lib/python2.7/site-packages/kivy/data/glsl/default.png>
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[DEBUG ] [Atlas ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme.atlas>
[DEBUG ] [Atlas ] Need to load 1 images
[DEBUG ] [Atlas ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
[DEBUG ] [ImagePygame ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
[INFO ] [OSC ] using <multiprocessing> for socket
[DEBUG ] [Base ] Create provider from mouse
[DEBUG ] [Base ] Create provider from probesysfs
[DEBUG ] [ProbeSysfs ] using probsysfs!
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
日志:
/usr/bin/python /home/kshk/PycharmProjects/KSHK-PYQT1/main.py
[INFO ] Kivy v1.8.0
[INFO ] [Logger ] Record log in /home/kshk/.kivy/logs/kivy_14-07-13_58.txt
[INFO ] [Factory ] 157 symbols loaded
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
[INFO ] [Text ] Provider: pygame
[DEBUG ] [Cache ] register <kv.loader> with limit=500, timeout=60s
[INFO ] [Loader ] using a thread pool of 2 workers
[DEBUG ] [Cache ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG ] [Cache ] register <textinput.width> with limit=None, timeout=60.0s
[DEBUG ] [Video ] Ignored <pygst> (import error)
[DEBUG ] [Video ] Ignored <ffmpeg> (import error)
[DEBUG ] [Video ] Ignored <pyglet> (import error)
[INFO ] [Video ] Provider: null(['video_pygst', 'video_ffmpeg', 'video_pyglet'] ignored)
[DEBUG ] [App ] Loading kv </home/kshk/PycharmProjects/KSHK-PYQT1/my.kv>
[DEBUG ] [App ] kv </home/kshk/PycharmProjects/KSHK-PYQT1/my.kv> not found
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
libpng warning: iCCP: known incorrect sRGB profile
[WARNING ] [WinPygame ] Video: failed (multisamples=2)
[WARNING ] [WinPygame ] trying without antialiasing
[DEBUG ] [Window ] Display driver x11
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a0
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 0
[INFO ] [GL ] OpenGL version <2.1 Mesa 10.1.5>
[INFO ] [GL ] OpenGL vendor <VMware, Inc.>
[INFO ] [GL ] OpenGL renderer <Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits)>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <1.30>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load </usr/lib/python2.7/site-packages/kivy/data/glsl/default.png>
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[DEBUG ] [Atlas ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme.atlas>
[DEBUG ] [Atlas ] Need to load 1 images
[DEBUG ] [Atlas ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
[DEBUG ] [ImagePygame ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
[INFO ] [OSC ] using <multiprocessing> for socket
[DEBUG ] [Base ] Create provider from mouse
[DEBUG ] [Base ] Create provider from probesysfs
[DEBUG ] [ProbeSysfs ] using probsysfs!
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
千伏
#文件widgets.kv
#:kivy 1.8.0
:
主持人安排:
视频:
资料来源:“driver.avi”
尺码:100100
网格布局:
按钮:
短信:“你好”
电话:0100
尺码:100,50
颜色:.8、.9、0、1
字体大小:32
按钮:
文字:“世界!”
位置:100,0
尺码:100,50
颜色:.8、.9、0、1
字体大小:32
我得到的只是一个黑屏
更新:
我指出了这个错误…你知道如何得到这个插件吗?我已经安装了gstreamer
[DEBUG ] [VideoPyGst ] Load <driver.mp4>
** Message: don't know how to handle video/x-h264, stream-format=(string)byte-stream, alignment=(string)au, level=(string)4.2, profile=(string)main, width=(int)1920, height=(int)1080, framerate=(fraction)2997/125, pixel-aspect-ratio=(fraction)1/1, parsed=(boolean)true
[ERROR ] [VideoPyGst ] There is no codec present that can handle the stream's type.
[DEBUG ] [VideoPyGst ] gstplaybasebin.c(2323): prepare_output (): /GstPlayBin:playbin
[ERROR ] [VideoPyGst ] GStreamer encountered a general stream error.
[DEBUG ] [VideoPyGst ] qtdemux.c(3891): gst_qtdemux_loop (): /GstPlayBin:playbin/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0:
streaming stopped, reason not-linked
[INFO ] [Base ] Leaving application in progress...
[DEBUG][VideoPyGst]加载
**消息:不知道如何处理视频/x-h264,流格式=(字符串)字节流,对齐=(字符串)au,级别=(字符串)4.2,配置文件=(字符串)main,宽度=(int)1920,高度=(int)1080,帧速率=(分数)2997/125,像素纵横比=(分数)1/1,解析=(布尔)true
[错误][VideoPyGst]没有可处理流类型的编解码器。
[DEBUG][VideoPyGst]gstplaybasebin.c(2323):准备输出():/GstPlayBin:playbin
[ERROR][VideoPyGst]GStreamer遇到一般流错误。
[DEBUG][VideoPyGst]qtdemux.c(3891):gst_qtdemux_loop():/GstPlayBin:playbin/GstDecodeBin:decodebin0/GstQTDemux:qtdemux0:
流停止,原因未链接
[INFO][Base]正在退出应用程序。。。
更新:
/usr/bin/python /home/kshk/PycharmProjects/KSHK-PYQT1/main.py
[INFO ] Kivy v1.8.0
[INFO ] [Logger ] Record log in /home/kshk/.kivy/logs/kivy_14-07-13_58.txt
[INFO ] [Factory ] 157 symbols loaded
[DEBUG ] [Cache ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG ] [Cache ] register <kv.image> with limit=None, timeout=60s
[DEBUG ] [Cache ] register <kv.atlas> with limit=None, timeout=Nones
[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif
[DEBUG ] [Cache ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG ] [Cache ] register <kv.shader> with limit=1000, timeout=3600s
[INFO ] [Text ] Provider: pygame
[DEBUG ] [Cache ] register <kv.loader> with limit=500, timeout=60s
[INFO ] [Loader ] using a thread pool of 2 workers
[DEBUG ] [Cache ] register <textinput.label> with limit=None, timeout=60.0s
[DEBUG ] [Cache ] register <textinput.width> with limit=None, timeout=60.0s
[DEBUG ] [Video ] Ignored <pygst> (import error)
[DEBUG ] [Video ] Ignored <ffmpeg> (import error)
[DEBUG ] [Video ] Ignored <pyglet> (import error)
[INFO ] [Video ] Provider: null(['video_pygst', 'video_ffmpeg', 'video_pyglet'] ignored)
[DEBUG ] [App ] Loading kv </home/kshk/PycharmProjects/KSHK-PYQT1/my.kv>
[DEBUG ] [App ] kv </home/kshk/PycharmProjects/KSHK-PYQT1/my.kv> not found
[DEBUG ] [Window ] Ignored <egl_rpi> (import error)
[INFO ] [Window ] Provider: pygame(['window_egl_rpi'] ignored)
libpng warning: iCCP: known incorrect sRGB profile
[WARNING ] [WinPygame ] Video: failed (multisamples=2)
[WARNING ] [WinPygame ] trying without antialiasing
[DEBUG ] [Window ] Display driver x11
[DEBUG ] [Window ] Actual window size: 800x600
[DEBUG ] [Window ] Actual color bits r8 g8 b8 a0
[DEBUG ] [Window ] Actual depth bits: 24
[DEBUG ] [Window ] Actual stencil bits: 8
[DEBUG ] [Window ] Actual multisampling samples: 0
[INFO ] [GL ] OpenGL version <2.1 Mesa 10.1.5>
[INFO ] [GL ] OpenGL vendor <VMware, Inc.>
[INFO ] [GL ] OpenGL renderer <Gallium 0.4 on llvmpipe (LLVM 3.4, 256 bits)>
[INFO ] [GL ] OpenGL parsed version: 2, 1
[INFO ] [GL ] Shading version <1.30>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[DEBUG ] [Shader ] Fragment compiled successfully
[DEBUG ] [Shader ] Vertex compiled successfully
[DEBUG ] [ImagePygame ] Load </usr/lib/python2.7/site-packages/kivy/data/glsl/default.png>
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[DEBUG ] [Atlas ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme.atlas>
[DEBUG ] [Atlas ] Need to load 1 images
[DEBUG ] [Atlas ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
[DEBUG ] [ImagePygame ] Load </usr/lib/python2.7/site-packages/kivy/data/../data/images/defaulttheme-0.png>
[INFO ] [OSC ] using <multiprocessing> for socket
[DEBUG ] [Base ] Create provider from mouse
[DEBUG ] [Base ] Create provider from probesysfs
[DEBUG ] [ProbeSysfs ] using probsysfs!
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
在mac上工作,没有问题,所以看起来像fedora上的插件问题….:(
可以在kivy中播放视频(mp4)作为背景吗
是的,只要把视频放在你想显示的任何东西后面就行了。你的例子不会这样做,因为它是gridlayout的一部分,你可能会想做一些事情,比如使用一个固定布局将两个孩子放在同一个地方(这不是唯一的方法,但很简单)
锚点布局:
视频:
资料来源:“随便”
网格布局:
# ...
我得到的只是一个黑屏
回答这个黑屏问题时,可能您没有将python文件与.kv文件链接。这两个文件的链接应该是Builder.load_file()
例如
...
from kivy.uix.anchorlayout import AnchorLayout
Builder.load_file("widgets.kv")
class MyWidget(Widget):
pass
...
希望这有帮助
...
from kivy.uix.anchorlayout import AnchorLayout
Builder.load_file("widgets.kv")
class MyWidget(Widget):
pass
...