简体   繁体   English

如何在 Python 中使用 Ursina 播放 MP4

[英]How to play MP4 with Ursina in Python

I am new to game development.我是游戏开发的新手。 I am trying to start high and make a 3D RPG.我试图从高起点开始制作 3D RPG。 I know the road is not gonna be easy.我知道这条路不会一帆风顺。 That is why i decided to use Ursina and python to make my game.这就是为什么我决定使用 Ursina 和 python 来制作我的游戏。

However i wanna add a cutscene showing a Backstory.但是我想添加一个显示背景故事的过场动画。 I have the video in mp4 format but i cannot seem to know how to play it inside the game with Ursina.我有 mp4 格式的视频,但我似乎不知道如何在 Ursina 的游戏中播放它。

Anyhelp will be much appreciated.任何帮助都感激不尽。 (Side question: do you think Ursina is good for a beginner in 3D gaming? If i want to publish my game on my website, isn't it better for me to learn javascript? I read about Unity but it is too big to download for a little side project) (附带问题:你认为 Ursina 适合 3D 游戏的初学者吗?如果我想在我的网站上发布我的游戏,学习 javascript 对我来说不是更好吗?我读过关于 Unity 但它太大而无法下载对于一个小项目)

You can set the video as a texture of any element.您可以将视频设置为任何元素的纹理。 You'll want to fix it to the UI using its parent attribute and you have to load the sound separately from the same file (as described in the Panda3D documentation ).您需要使用其parent属性将其修复到 UI 中,并且您必须从同一文件中单独加载声音(如Panda3D 文档中所述)。

from ursina import *

app = Ursina()

video = 'video.mp4'
video_player = Entity(model='quad', parent=camera.ui, scale=(1.5, 1), texture=video)
video_sound = loader.loadSfx(video)
video_player.texture.synchronizeTo(video_sound)
video_sound.play()

app.run()

The above code assumes that the video file is in the same folder as the Python script.上述代码假定视频文件与 Python 脚本位于同一文件夹中。

Well, I don't think there is a way to do that.好吧,我认为没有办法做到这一点。 the closest thing you can do to that is having a folder filled with all the frames of your video in.png or.jpg files, then adding a quad to the world and changing the texture of it to the next frame every fraction of a second depending on the framerate.你能做的最接近的事情是有一个文件夹,里面装满你的视频 in.png 或 .jpg 文件的所有帧,然后向世界添加一个四边形,并每隔几分之一秒将其纹理更改为下一帧取决于帧率。 this, however would make your computer la g.但是,这会使您的计算机滞后。 trust me, I've tried it.相信我,我已经试过了。 it would probably be better to have a separate window with some sort of module that plays.mp4 files for playing the file.最好有一个单独的 window 和某种可以播放.mp4 文件的模块来播放文件。 In other words, there is no feasible way to do that.换句话说,没有可行的方法来做到这一点。

From Entity Basics in the documentation:从文档中的实体基础知识:

e4 = Entity(model='cube', texture='movie_name.mp4') # set video texture

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM