MCPcopy Create free account
hub / github.com/YvanYin/DrivingWorld / create_mp4

Function create_mp4

utils/testing_utils.py:27–44  ·  view source on GitHub ↗
(args, imgs, video_save_path, border_size = 10, fps=2)

Source from the content-addressed store, hash-verified

25 video_writer.release()
26
27def create_mp4(args, imgs, video_save_path, border_size = 10, fps=2):
28 condition_frames = args.condition_frames
29 print("save fps as ", fps)
30
31 if not os.path.exists(video_save_path):
32 os.makedirs(video_save_path)
33 _, _, h, w = imgs[0].shape
34
35 # video_writer = cv2.VideoWriter(os.path.join(video_save_path, 'video.mp4'), fourcc, fps, (w+2*border_size, h+2*border_size))
36 with imageio.get_writer(os.path.join(video_save_path, 'video.mp4'), mode='I', fps=fps) as writer:
37 for j, image_file in enumerate(imgs):
38 img = (image_file[0].permute(1, 2, 0).cpu().numpy() * 255).astype('uint8')[:,:,::-1]
39 if j < condition_frames:
40 bordered_img = add_border(img, border_size=border_size)
41 else:
42 bordered_img = add_border(img, border_size=border_size, value=[0, 0, 255])
43 # cv2.imwrite(os.path.join(video_save_path, '%d.png'%(j)), bordered_img)
44 writer.append_data(bordered_img[:, :, ::-1])
45
46
47def create_gif(args, imgs, video_save_path, border_size = 10, fps=2):

Callers

nothing calls this directly

Calls 1

add_borderFunction · 0.85

Tested by

no test coverage detected