def __init__(self, name, experiment, string=None): """ Initialize module. Link to the video can already be specified but this is optional vfile: The path to the file to be played screensize: An optional tuple with the preferred (w,h) of the output frame. Otherwise, the video is played in its original size """ # The version of the plug-in self.version = 0.11 self.mp = pyffmpeg.FFMpegReader(0, False) self.videoTrack = None self.audioTrack = None self.audioBuffer = [] self.bufferedAudio = True self.file_loaded = False self.frameTime = 0 self.paused = False self.item_type = "media_player" self.description = "Plays a video from file" self.duration = "keypress" self.fullscreen = "yes" self.playaudio = "yes" self.audioCorrection = 150000 self.video_src = "" self.sendInfoToEyelink = "yes" self.event_handler = "" # The parent handles the rest of the construction item.item.__init__(self, name, experiment, string)
def get_video_dims(fname): """ Pull out the frame length, spatial height and spatial width of a video file using ffmpeg. Parameters ---------- fname : str Path to video file to be inspected. Returns ------- shape : tuple The spatiotemporal dimensions of the video (length, height, width). """ try: import pyffmpeg except ImportError: raise ImportError("This function requires pyffmpeg " "<http://code.google.com/p/pyffmpeg/>") mp = pyffmpeg.FFMpegReader() try: mp.open(fname) tracks = mp.get_tracks() for track in tracks: if isinstance(track, pyffmpeg.VideoTrack): break else: raise ValueError('no video track found') return (track.duration(), ) + track.get_orig_size() finally: mp.close()
def testVideo(): mp = pf.FFMpegReader() mp.open("test.mp4",pf.TS_VIDEO_PIL) vt=mp.get_tracks()[0] # video track for k in xrange(0,10): image = vt.get_next_frame() image.save("test_%(number)03d.png" % {'number':k}, "PNG")
def add_vid_info(clips): for name, clip in clips.iteritems(): # set the resolution and duration by opening the file with ffmpeg reader = pyffmpeg.FFMpegReader(False) reader.open(clip['path'], { 'video1':(0, -1, { 'dest_height':-1, 'dest_width':-1, 'outputmode':pyffmpeg.OUTPUTMODE_NUMPY})})#, pyffmpeg.TS_VIDEO_) video_track = reader.get_tracks()[0] clip['duration'] = video_track.duration() clip['resolution'] = video_track.get_size()
def __init__(self, name, experiment, string=None): """ Constructor. Link to the video can already be specified but this is optional Arguments: name -- the name of the item experiment -- the opensesame experiment Keyword arguments: string -- a definition string for the item (Default = None) """ # The version of the plug-in self.version = 0.14 self.mp = pyffmpeg.FFMpegReader(0, False) self.videoTrack = None self.audioTrack = None self.audioBuffer = [] self.bufferedAudio = True self.file_loaded = False self.frameTime = 0 self.paused = False self.item_type = "media_player" self.description = "Plays a video from file" self.duration = "keypress" self.fullscreen = "yes" self.playaudio = "yes" self.audioCorrection = 150000 self.video_src = "" self.sendInfoToEyelink = "yes" self.event_handler = "" self.frameNo = 0 self.event_handler_trigger = "on keypress" # The parent handles the rest of the construction item.item.__init__(self, name, experiment, string) # Indicate function for clean up that is run after the experiment finishes self.experiment.cleanup_functions.append(self.closeStreams)
tracks[1].set_observer(lambda x:ao.write(x[0].data)) tracks[0].seek_to_seconds(10) ao.channels(tracks[1].get_channels()) ## play the movie ! mp.run() ########NEW FILE######## __FILENAME__ = seek_test # -*- coding: utf-8 -*- import sys import pyffmpeg reader = pyffmpeg.FFMpegReader(False) reader.open(sys.argv[1],pyffmpeg.TS_VIDEO_PIL) vt=reader.get_tracks()[0] print dir(vt) nframes=31 try: rdrdur=reader.duration() rdrdurtime=reader.duration_time() except: print "no duration information in reader" try: cdcdur=vt.duration() cdcdurtime=vt.duration_time() mt=max(cdcdurtime,rdrdurtime) print rdrdurtime, cdcdurtime print "FPS=",vt.get_fps()