def play(self, video, callback=None): """ Plays a video on this screen, also makes the *speaker* aviable. :param string video: The relative path (from the data folder) of the video to use. :param function callback: Function to call once the video ends. """ #Video path = logic.expandPath("//" + video) if not os.path.isfile(path): raise FileNotFoundError(path + " doesn't exist") self.video = texture.Texture(self.obj, 0) self.video.source = texture.VideoFFmpeg(path) self.video.source.scale = True self.video.source.play() module.video_playback_list.append(self) #Audio try: self.speaker = AudioFile() self.speaker = self.speaker.play(video) except RuntimeError: pass #Callback self.callback = callback return self
def _getSource(self, filepath): """""" source = texture.VideoFFmpeg(filepath) source.repeat = -1 source.framerate = 1.2 # 30.0 / 25.0 source.play() return source
def playVideo(obj, video_path): matID = texture.materialID(obj, 'IMplaceholder.jpg') logic.video = texture.Texture(obj, matID) movie = logic.expandPath(video_path) logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.play()
def set_video(): gl.plane = gl.all_obj["Video"] # identify a static texture by name matID = texture.materialID(gl.plane, 'MAblack') # create a dynamic texture that will replace the static texture gl.my_video = texture.Texture(gl.plane, matID) # define a source of image for the texture, here a movie try: film = "Astrophotography-Stars-Sunsets-Sunrises-Storms.ogg" movie = "./video/" + film print('Movie =', movie) except: print("Une video valide doit être définie !") try: s = os.path.getsize(movie) print("Taille du film:", s) except: print("Problème avec la durée du film !") gl.my_video.source = texture.VideoFFmpeg(movie) gl.my_video.source.scale = False # Infinite loop gl.my_video.source.repeat = -1 # Vitesse normale: < 1 ralenti, > 1 accélère gl.my_video.source.framerate = 1.4 # quick off the movie, but it wont play in the background gl.my_video.source.play()
def main(): cont = logic.getCurrentController() owner = cont.owner if "Video" in owner: video = owner["Video"] video.refresh(True) else: #Insert material name. mat = "Movie" matID = texture.materialID(owner, "MA" + mat) video = texture.Texture(owner, matID) owner["Video"] = video #Insert path to movie file. movie_path = "" path = logic.expandPath('//' + movie_path) video.source = texture.VideoFFmpeg(path) video.source.play()
def reload(self, video): if video == self.path: return if USING_BGE_TEXTURE: vid = texture.VideoFFmpeg(video) vid.repeat = self.repeat vid.play() self.video = vid data = vid.image if self.play_audio: self.audio = aud.device().play(aud.Factory(video)) else: data = None if data == None: print("Unable to load the video", video) return self.bind() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vid.size[0], vid.size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, data) self.image_size = vid.size[:] self.path = video
def initWorld(cont): obj = cont.owner matID = VT.materialID(obj, 'MAvideo') G.video = VT.Texture(obj, matID) if sys.platform == 'darwin': print( 'webcam grabbing for FFMmpeg not supported on OSX at the moment (the backend for video texture)' ) return elif sys.platform == 'win32': video_source = VT.VideoFFmpeg('cam', 0, 20.0, 640, 480) else: # linux video_source = VT.VideoFFmpeg('/dev/video0', 0, 20.0, 640, 480) G.video.source = video_source G.video.source.play()
def source(self, file): self.__file = file print("player.source: ", self.__file) # -- Load the file self.video.source = texture.VideoFFmpeg(self.__file) # -- scale the video self.video.source.scale = True # -- play the video self.state = 'PLAY'
def init_pub(): cont = G.getCurrentController() obj = cont.owner matID = VT.materialID(obj, 'MApub') G.video = VT.Texture(obj, matID) S1 = G.expandPath("//circuits/circuitdesertlau3/pub.avi") video_source = VT.VideoFFmpeg(S1) video_source.repeat = -1 video_source.scale = True video_source.flip = True G.video.source = video_source G.video.source.play()
def set_device(self, device): self.__device = device if self.state != 'STOP': self.state = 'STOP' self._texture.source = texture.VideoFFmpeg(self.__device, 1, self.__rate, self.__width, self.__height) if not self._texture.source: print("Error! inopening Camera") return # -- scaler self._texture.source.scale = False
def set_source(self, _file): self.__file = _file if self.state != 'STOP': self.state = 'STOP' self._texture.source = texture.VideoFFmpeg(_file) if not self._texture.source: self.__file = None self.__audio = None return # --- configure and play audio stream self.setup_audio() # -- dont use scale the video (image quality becomes worst) self._texture.source.scale = False # -- play the video self.state = 'PLAY'
def initWorld(cont): obj = cont.owner matID = VT.materialID(obj, 'MAvideo') G.video = VT.Texture(obj, matID) url = G.expandPath("//media/trailer_400p.ogg") video_source = VT.VideoFFmpeg(url) video_source.repeat = -1 video_source.scale = False G.video.source = video_source G.video.source.play() # SOUND sound = cont.actuators["a_sound"] cont.activate(sound) G.sound = sound
def main(): cont = logic.getCurrentController() own = cont.owner MAT = texture.materialID(own, 'MASINTEL') logic.video = texture.Texture(own, MAT) movie = logic.expandPath('//sintel2.mp4') logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.scale = True logic.video.source.flip = True logic.video.source.repeat = 0 logic.video.source.play() sound = cont.actuators["movie_sound"] cont.activate(sound) logic.sound = sound print('Playing Film. Enjoy!')
def initWorld(cont): object = cont.owner matID = texture.materialID(object, 'MAvideo') logic.video = texture.Texture(object, matID) url = logic.expandPath("//media/trailer_400p.ogg") video_source = texture.VideoFFmpeg(url) video_source.repeat = -1 video_source.scale = True logic.video.source = video_source logic.video.source.play() # SOUND import aud device = aud.device() factory = aud.Factory(url) handle = device.play(factory) logic.sound = handle
def play(self, video, callback=None): """ Plays a video on this screen, also makes the *speaker* aviable. :param string video: The relative path (from the data folder) of the video to use. :param function callback: Function to call once the video ends. """ #Video path = logic.expandPath("//../data/" + video) self.video = texture.Texture(self.obj, 0) self.video.source = texture.VideoFFmpeg(path) self.video.source.scale = True self.video.source.play() module.video_playback_list.append(self) #Audio try: self.true_start_file = video self.speaker = AudioFile() except RuntimeError: pass #Callback self.callback = callback
def main(): cont = logic.getCurrentController() own = cont.owner MAT = texture.materialID(own, 'MAflashback_video') logic.video = texture.Texture(own, MAT) movie = logic.expandPath("//flashback.ogg") logic.video.source = texture.VideoFFmpeg(movie) #logic.video.source.scale = True logic.video.source.flip = True logic.video.source.repeat = 0 logic.video.source.play() sound = cont.actuators["movie_sound"] cont.activate(sound) logic.sound = sound #print('Playing Film. Enjoy!') print(movie)
def updateTexture(animated=False): print('animated: ', animated) obj = logic.scene.objects['Sphere'] ID = texture.materialID(obj, 'MAsky') objectTextures = texture.Texture(obj, ID) # create a new source with an external image if animated: source = texture.VideoFFmpeg(logic.mvb.bgImage) else: source = texture.ImageFFmpeg(logic.mvb.bgImage) # the texture has to be stored in a permanent Python object logic.skyTexture = objectTextures logic.skyTexture.source = source logic.skyTextureAnimated = animated if animated: logic.skyTexture.source.repeat = -1 logic.skyTexture.source.play() logic.skyTexture.refresh(True)
++++++++++++++++++++++ Example of how to replace a texture in game with a video. It needs to run everyframe """ import bge from bge import texture from bge import logic cont = logic.getCurrentController() obj = cont.owner # the creation of the texture must be done once: save the # texture object in an attribute of bge.logic module makes it persistent if not hasattr(logic, 'video'): # identify a static texture by name matID = texture.materialID(obj, 'IMvideo.png') # create a dynamic texture that will replace the static texture logic.video = texture.Texture(obj, matID) # define a source of image for the texture, here a movie movie = logic.expandPath('//trailer_400p.ogg') logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.scale = True # quick off the movie, but it wont play in the background logic.video.source.play() # you need to call this function every frame to ensure update of the texture. logic.video.refresh(True)
def __init__(self, baseObj, video, mat, viewport=[0.0, 100.0, 0.0, 100.0], rect=None, col=[1.0, 1.0, 1.0, 1.0], verco=None, texco=[(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]): """Initialisation de la video Parametres : - baseObj : Objet contenant la texture de base - video : Nom de la video - mat : Material de l'objet correspondant a l'image - viewport : Coordonnees minimales et maximales de l'affichage : [xmin, ymax, xmax, ymin] - rect : Coordonnees des coins de l'image pour un affichage rectangulaire : [x1, y1, x2, y2] - col : Couleur RVBA de l'image : [r, v, b, a] - verco : Liste des coordonnees x/y de chaque vertice. - texco : Liste des coordonnees u/v de chaque vertice.""" VT = __class__.VT gl = __class__.gl self.ok = True self.angle = 0 if verco == None and rect == None: verco = [(0.0, 0.0), (100.0, 0.0), (100.0, 100.0), (0.0, 100.0)] elif verco == None: verco = [(rect[0], rect[1]), (rect[2], rect[1]), (rect[2], rect[3]), (rect[0], rect[3])] self.texco = texco self.verco = verco self.bary = [0, 0] for i in range(len(self.verco)): self.bary[0] += self.verco[i][0] self.bary[1] += self.verco[i][1] self.bary[0] /= len(self.verco) self.bary[1] /= len(self.verco) self.couleur = col self.viewport = viewport root = gl.expandPath("//") VT_img_Video = VT.VideoFFmpeg(root + video) if VT_img_Video.status == 0: print("Erreur: Video introuvable a l'adresse '" + root + video + "'") self.ok = False return VT_img_Video.play() VT_img_Mat = VT.materialID(baseObj, "MA" + mat) VT_img_Tex = VT.Texture(baseObj, VT_img_Mat) VT_img_Tex.source = VT_img_Video self.VT_img = VT_img_Tex self.rafraichir() return
cont = logic.getCurrentController() obj = cont.owner # the creation of the texture must be done once: save the # texture object in an attribute of bge.logic module makes it persistent if not hasattr(logic, 'video'): # identify a static texture by name matID = texture.materialID(obj, 'IMvideo.png') # create a dynamic texture that will replace the static texture logic.video = texture.Texture(obj, matID) # define a source of image for the texture, here a movie movie = logic.expandPath('//trailer_400p.ogg') logic.video.source = texture.VideoFFmpeg(movie) logic.video.source.scale = True # Note that we can change the ``Texture`` source at any time. # Suppose we want to switch between two movies during the game: logic.mySources[0] = texture.VideoFFmpeg('movie1.avi') logic.mySources[1] = texture.VideoFFmpeg('movie2.avi') #And then assign (and reassign) the source during the game logic.video.source = logic.mySources[movieSel] # quick off the movie, but it wont play in the background logic.video.source.play() # Video playback is not a background process: it happens only when we refresh the texture. # So you need to call this function every frame to ensure update of the texture.