AnsenH's picture
chore: move video utils to util functions
72851a0
raw
history blame
875 Bytes
from moviepy.config import get_setting
from moviepy.tools import subprocess_call
import os
def ffmpeg_extract_subclip(filename, t1, t2, targetname=None):
""" Makes a new video file playing video file ``filename`` between
the times ``t1`` and ``t2``. """
name, ext = os.path.splitext(filename)
if not targetname:
T1, T2 = [int(1000*t) for t in [t1, t2]]
targetname = "%sSUB%d_%d.%s" % (name, T1, T2, ext)
cmd = [get_setting("FFMPEG_BINARY"),"-y",
"-i", filename,
"-ss", "%0.4f"%t1,
"-t", "%0.4f"%(t2-t1),
"-vf",
"scale=320:-2",
targetname
]
print(f'== cmd: {cmd}')
subprocess_call(cmd)
def trim_video(video_path, start, end, output_file='result.mp4'):
ffmpeg_extract_subclip(video_path, start, end, targetname=output_file)
return output_file