summaryrefslogtreecommitdiff
path: root/cli/app/search/video.py
blob: c5ef8ce6ae64c8378d8612afd938ae825fc8f0fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import shutil
import os
from subprocess import call

from app.settings import app_cfg

def export_video(fp_frames, fps=30):
  print("Exporting video...")
  cmd = [
    '/usr/bin/ffmpeg',
    '-hide_banner',
    '-y', # '-v', 'quiet',
    '-r', str(fps),
    '-i', os.path.join(app_cfg.DIR_OUTPUTS, fp_frames, 'frame_%04d.png'),
    '-pix_fmt', 'yuv420p',
    os.path.join(app_cfg.DIR_OUTPUTS, fp_frames + '.mp4')
  ]
  # print(' '.join(cmd))
  call(cmd)
  shutil.rmtree(os.path.join(app_cfg.DIR_OUTPUTS, fp_frames))

def export_video_final(fp_frames, fp_out, fps=25):
  if os.path.exists(fp_out):
    print("Video already exists: {}".format(fp_out))
    return None

  print("Exporting video...")
  cmd = [
    '/usr/bin/ffmpeg',
    '-hide_banner',
    '-y', # '-v', 'quiet',
    '-r', str(fps),
    '-i', os.path.join(app_cfg.DIR_OUTPUTS, fp_frames, 'frame_%05d.png'),
    '-c:v', 'libx264',
    '-preset', 'slow',
    '-crf', '19',
    '-vf', 'fps=25',
    '-pix_fmt', 'yuv420p',
    '-s', '512x512',
    fp_out
  ]
  # print(' '.join(cmd))
  call(cmd)
  return fp_out