forked from Honghe/demo_bodypix_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_jpgs_to_mp4.py
26 lines (22 loc) · 830 Bytes
/
4_jpgs_to_mp4.py
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
# -*- coding: utf-8 -*-
import logging
import os
import subprocess
import sys
def main(root_dir):
mp4_file = os.path.join(root_dir, 'masked.mp4')
jpgs_dir = os.path.join(root_dir, 'masked_jpgs')
os.makedirs(jpgs_dir, exist_ok=True)
args = ['ffmpeg', '-y', '-i', '{}/%4d.jpg'.format(jpgs_dir), '-vcodec', 'libx264', '-r', '25', mp4_file]
print(' '.join(args))
process = subprocess.Popen(
args, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
_, stderr = process.communicate()
if process.returncode != 0:
raise Exception('ffmpeg return error.')
if __name__ == '__main__':
if len(sys.argv) <= 1:
logging.error('Need run with: {} <dir>'.format(os.path.basename(sys.argv[0])))
else:
root_dir = os.path.abspath(sys.argv[1])
main(root_dir)