lfolle commited on
Commit
dcf2dd9
1 Parent(s): df5f94d

Changed to ffmpeg

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. create_video.py +12 -6
  3. requirements.txt +1 -0
.gitignore CHANGED
@@ -3,3 +3,4 @@ __pycache__/
3
  dataset.tar
4
  *.json
5
  *.mp4
 
 
3
  dataset.tar
4
  *.json
5
  *.mp4
6
+ video/*.jpg
create_video.py CHANGED
@@ -1,6 +1,7 @@
1
  import numpy as np
2
  import cv2
3
  from PIL import Image
 
4
 
5
 
6
  def noise_process(numpy_image, steps=149):
@@ -29,10 +30,15 @@ def generate_video(numpy_image):
29
  image_lst = np.repeat(image_lst, copies, axis=0)
30
  image_lst = np.concatenate((image_lst, image_lst[:spill_over]), axis=0)
31
  image_lst = image_lst[::-1]
32
- fourcc = cv2.VideoWriter_fourcc(*'avc1')
33
- video = cv2.VideoWriter(save_path, fourcc, float(fps), (width, height))
34
- for frame_count in range(fps * sec):
35
- img = np.expand_dims(image_lst[frame_count], 2)
36
- video.write(img.astype(np.uint8))
37
- video.release()
 
 
 
 
 
38
  return save_path
 
1
  import numpy as np
2
  import cv2
3
  from PIL import Image
4
+ import ffmpeg
5
 
6
 
7
  def noise_process(numpy_image, steps=149):
 
30
  image_lst = np.repeat(image_lst, copies, axis=0)
31
  image_lst = np.concatenate((image_lst, image_lst[:spill_over]), axis=0)
32
  image_lst = image_lst[::-1]
33
+ for i, img in enumerate(image_lst):
34
+ Image.fromarray(img).save(f"video/{i}.jpg")
35
+
36
+ ffmpeg.input('video/*.jpg', pattern_type='glob', framerate=25).output(save_path).run()
37
+
38
+ # fourcc = cv2.VideoWriter_fourcc(*'avc1')
39
+ # video = cv2.VideoWriter(save_path, fourcc, float(fps), (width, height))
40
+ # for frame_count in range(fps * sec):
41
+ # img = np.expand_dims(image_lst[frame_count], 2)
42
+ # video.write(img.astype(np.uint8))
43
+ # video.release()
44
  return save_path
requirements.txt CHANGED
@@ -5,6 +5,7 @@ pandas
5
  torch
6
  ffprobe
7
  pytorch-gradcam
 
8
  Pillow
9
  tqdm
10
  opencv-python
 
5
  torch
6
  ffprobe
7
  pytorch-gradcam
8
+ ffmpeg-python
9
  Pillow
10
  tqdm
11
  opencv-python