Beispiel #1
0
 def __init__(self, name, coord=None):
     mkdir_if_not_exist(os.path.join(LEVEL_PATH, 'octopus'))
     self.data = self._parse(name)
     self.name = name
     if coord: # use coordinate from file.
         self.coord_data = self._parse(coord)
     else:
         self.coord_data = None
Beispiel #2
0
 def reset(self):
     self.terminate()
     self.num_reset += 1
     os.environ['level'] = self.level
     if self.video_path:
         mkdir_if_not_exist(self.video_path)
         os.environ['video'] = self.video_path + '/%d' % self.num_reset + '.mp4'
     self.game_process = pexpect.spawn('python %s' % OctopusTask.GAME_PATH, maxread=999999)
Beispiel #3
0
    def __init__(self, fname):
        mkdir_if_not_exist(os.path.dirname(fname))
        command = [ VideoRecorder.FFMPEG_BIN,
            '-y', # (optional) overwrite output file if it exists
            '-f', 'image2pipe',
            '-vcodec', 'mjpeg',
            '-r', '48', # frames per second
            '-i', '-', # The input comes from a pipe
            '-vcodec', 'libx264',
            '-an', # Tells FFMPEG not to expect any audio
            fname ]

        self.output = open('_video_recorder.out', 'w')
        movie = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=self.output, stderr=self.output)

        self.movie = movie
        self.finished = False
Beispiel #4
0
    def __init__(self, fname, screen_size):
        self.output = open('_video_recorder.out', 'w')

        mkdir_if_not_exist(os.path.dirname(fname))
        command = [ VideoRecorder.FFMPEG_BIN,
            '-y', # (optional) overwrite output file if it exists
            '-f', 'rawvideo',
            '-vcodec','rawvideo',
            '-s', '%sx%s' % (screen_size[0], screen_size[1]), # size of one frame
            '-pix_fmt', 'rgb24',
            '-r', '48', # frames per second
            '-i', '-', # The input comes from a pipe
            '-an', # Tells FFMPEG not to expect any audio
            '-vcodec', 'mpeg4',
            fname ]

        self.movie = subprocess.Popen(command, close_fds=True, stdin=subprocess.PIPE, stdout=self.output, stderr=self.output)
        self.finished = False
Beispiel #5
0
def record_game(policy, task, output_path, max_step=9999, **policy_args):
    '''
    record the play of policy on task, and save each frame to *output_path*.

    Requirements:
        task should have visualize(self, fname=None) implemented.
    '''
    step = 0
    mkdir_if_not_exist(output_path)
    task.reset()

    while step < max_step:
        task.visualize(path.join(output_path, '%d' % step))
        curr_state = task.curr_state
        action = policy.get_action(curr_state, valid_action=task.valid_actions, **policy_args)
        task.step(action)
        step += 1

    task.reset()
Beispiel #6
0
    def __init__(self, surface, fname):
        screen_size = (surface.get_width(), surface.get_height())

        mkdir_if_not_exist(os.path.dirname(fname))
        command = [ VideoRecorder.FFMPEG_BIN,
            '-y', # (optional) overwrite output file if it exists
            '-f', 'rawvideo',
            '-vcodec','rawvideo',
            '-s', '%sx%s' % (screen_size[0], screen_size[1]), # size of one frame
            '-pix_fmt', 'rgb24',
            '-r', '24', # frames per second
            '-i', '-', # The input comes from a pipe
            '-an', # Tells FFMPEG not to expect any audio
            '-vcodec', 'mpeg4',
            fname ]

        movie = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=None)

        self.surface = surface
        self.movie = movie
        self.running = True

        thread = threading.Thread(target=self.record)
        thread.start()