Python moviepy.editor 模块,ImageSequenceClip() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用moviepy.editor.ImageSequenceClip()

项目:tensorflow-srgan    作者:olgaliak    | 项目源码 | 文件源码
def demo1(sess):
    """Demo based on images dumped during training"""

    # Get images that were dumped during training
    filenames = tf.gfile.ListDirectory(FLAGS.train_dir)
    filenames = sorted(filenames)
    filenames = [os.path.join(FLAGS.train_dir, f) for f in filenames if f[-4:]=='.png']

    assert len(filenames) >= 1

    fps        = 30

    # Create video file from PNGs
    print("Producing video file...")
    filename  = os.path.join(FLAGS.train_dir, 'demo1.mp4')
    clip      = mpe.ImageSequenceClip(filenames, fps=fps)
    clip.write_videofile(filename)
    print("Done!")
项目:Generative-Adversarial-Network    作者:K-Du    | 项目源码 | 文件源码
def demo1(sess):
    """Demo based on images dumped during training"""

    # Get images that were dumped during training
    filenames = tf.gfile.ListDirectory(FLAGS.train_dir)
    filenames = sorted(filenames)
    filenames = [os.path.join(FLAGS.train_dir, f) for f in filenames if f[-4:]=='.png']

    assert len(filenames) >= 1

    fps = 5

    # Create video file from PNGs
    print("Producing video file...")
    filename  = os.path.join(FLAGS.train_dir, 'demo1.mp4')
    clip      = mpe.ImageSequenceClip(filenames, fps=fps)
    clip.write_videofile(filename)
    print("Done!")
项目:srez    作者:david-gpu    | 项目源码 | 文件源码
def demo1(sess):
    """Demo based on images dumped during training"""

    # Get images that were dumped during training
    filenames = tf.gfile.ListDirectory(FLAGS.train_dir)
    filenames = sorted(filenames)
    filenames = [os.path.join(FLAGS.train_dir, f) for f in filenames if f[-4:]=='.png']

    assert len(filenames) >= 1

    fps        = 30

    # Create video file from PNGs
    print("Producing video file...")
    filename  = os.path.join(FLAGS.train_dir, 'demo1.mp4')
    clip      = mpe.ImageSequenceClip(filenames, fps=fps)
    clip.write_videofile(filename)
    print("Done!")
项目:conway    作者:avyfain    | 项目源码 | 文件源码
def create_gif():
    file_names = (fn for fn in os.listdir('.') if fn.endswith('.png'))
    s_file_names = sorted(file_names, key=lambda x: int(x.split('.')[0]))
    clip = mpy.ImageSequenceClip(s_file_names, fps=12)
    name = '{}.gif'.format(uuid4())
    clip.write_gif(name, fps=12)
    delete_pngs()
    return name
项目:visual_mpc    作者:febert    | 项目源码 | 文件源码
def npy_to_gif(im_list, filename):

    save_dir = '/'.join(str.split(filename, '/')[:-1])

    if not os.path.exists(save_dir):
        print 'creating directory: ', save_dir
        os.mkdir(save_dir)

    clip = mpy.ImageSequenceClip(im_list, fps=4)
    clip.write_gif(filename + '.gif')
    return
项目:visual_mpc    作者:febert    | 项目源码 | 文件源码
def save_highres(self):
        # clip = mpy.ImageSequenceClip(self.highres_imglist, fps=10)
        # clip.write_gif(self.image_folder + '/highres_traj{}.mp4'.format(self.itr))
        writer = imageio.get_writer(self.image_folder + '/highres_traj{}.mp4'.format(self.itr), fps=10)
        print 'shape highes:', self.highres_imglist[0].shape
        for im in self.highres_imglist:
            writer.append_data(im)
        writer.close()
项目:lsdc    作者:febert    | 项目源码 | 文件源码
def npy_to_gif(im_list, filename):
    clip = mpy.ImageSequenceClip(im_list, fps=4)
    clip.write_gif(filename + '.gif')
    return
项目:lsdc    作者:febert    | 项目源码 | 文件源码
def npy_to_gif(im_list, filename):

    # import pdb; pdb.set_trace()

    clip = mpy.ImageSequenceClip(im_list, fps=10)
    clip.write_gif(filename)
项目:eva-didi    作者:eljefec    | 项目源码 | 文件源码
def _make_subclip(self):
    subclip_path = os.path.join(self.out_dir, 'subclip_{}.mp4'.format(self.frame_idx))
    clip = mpy.ImageSequenceClip(self.images, fps=20)
    clip.write_videofile(subclip_path)
    self.subclip_paths.append(subclip_path)
    del self.images[:]
项目:CarND-Behavioral-Cloning-P3    作者:udacity    | 项目源码 | 文件源码
def main():
    parser = argparse.ArgumentParser(description='Create driving video.')
    parser.add_argument(
        'image_folder',
        type=str,
        default='',
        help='Path to image folder. The video will be created from these images.'
    )
    parser.add_argument(
        '--fps',
        type=int,
        default=60,
        help='FPS (Frames per second) setting for the video.')
    args = parser.parse_args()

    #convert file folder into list firltered for image file types
    image_list = sorted([os.path.join(args.image_folder, image_file)
                        for image_file in os.listdir(args.image_folder)])

    image_list = [image_file for image_file in image_list if os.path.splitext(image_file)[1][1:].lower() in IMAGE_EXT]

    #two methods of naming output video to handle varying environemnts
    video_file_1 = args.image_folder + '.mp4'
    video_file_2 = args.image_folder + 'output_video.mp4'

    print("Creating video {}, FPS={}".format(args.image_folder, args.fps))
    clip = ImageSequenceClip(image_list, fps=args.fps)

    try:
        clip.write_videofile(video_file_1)
    except:
        clip.write_videofile(video_file_2)
项目:Self-Driving-Car-ND-Predict-Steering-Angle-with-CV    作者:sjamthe    | 项目源码 | 文件源码
def makemovie(dirname, outfile):
    images = []
    filecnt = len(os.listdir(dirname))-1
    for cnt in range(1,filecnt):
        images.append(dirname+str(cnt)+'.jpg')

    clip = ImageSequenceClip(images,fps=30)
    clip.write_videofile(outfile)
项目:maml_rl    作者:cbfinn    | 项目源码 | 文件源码
def rollout(env, agent, max_path_length=np.inf, animated=False, speedup=1, save_video=True, video_filename='sim_out.mp4', reset_arg=None):
    observations = []
    actions = []
    rewards = []
    agent_infos = []
    env_infos = []
    images = []
    o = env.reset(reset_args=reset_arg)
    agent.reset()
    path_length = 0
    if animated:
        env.render()
    while path_length < max_path_length:
        a, agent_info = agent.get_action(o)
        next_o, r, d, env_info = env.step(a)
        observations.append(env.observation_space.flatten(o))
        rewards.append(r)
        actions.append(env.action_space.flatten(a))
        agent_infos.append(agent_info)
        env_infos.append(env_info)
        path_length += 1
        if d: # and not animated:  # TODO testing
            break
        o = next_o
        if animated:
            env.render()
            timestep = 0.05
            time.sleep(timestep / speedup)
            if save_video:
                from PIL import Image
                image = env.wrapped_env.wrapped_env.get_viewer().get_image()
                pil_image = Image.frombytes('RGB', (image[1], image[2]), image[0])
                images.append(np.flipud(np.array(pil_image)))

    if animated:
        if save_video and len(images) >= max_path_length:
            import moviepy.editor as mpy
            clip = mpy.ImageSequenceClip(images, fps=20*speedup)
            if video_filename[-3:] == 'gif':
                clip.write_gif(video_filename, fps=20*speedup)
            else:
                clip.write_videofile(video_filename, fps=20*speedup)
        #return

    return dict(
        observations=tensor_utils.stack_tensor_list(observations),
        actions=tensor_utils.stack_tensor_list(actions),
        rewards=tensor_utils.stack_tensor_list(rewards),
        agent_infos=tensor_utils.stack_tensor_dict_list(agent_infos),
        env_infos=tensor_utils.stack_tensor_dict_list(env_infos),
    )