Last active
March 21, 2021 15:10
-
-
Save vvzen/5bd45e6968374c4f69f87f264f62afe5 to your computer and use it in GitHub Desktop.
create a series of FFMPEG commands to 1) trim video/audio from a source 2) add audio/video fade in, fade out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import os | |
current_dir = os.path.dirname(os.path.realpath(__file__)) | |
source = 'my_ProRes.mov' | |
ffmpeg_command_template = ( 'ffmpeg \\\n' | |
'-loop 1 -r {fps} -t 5 -i black.jpg \\\n' | |
'-ss {start} -r {fps} \\\n' | |
'-i $SOURCE -t 00:00:{duration}.000 \\\n' | |
'-vcodec libx264 -pix_fmt yuv420p \\\n' | |
'-movflags +faststart -preset slower \\\n' | |
'-color_primaries bt709 -color_trc bt709 -colorspace bt709 \\\n' | |
'-tune animation \\\n' | |
'-filter_complex \\\n' | |
'"[1]fade=t=in:st=0:d=2,fade=t=out:st={dissolve_start}:d={dissolve_length}" \\\n' | |
'-filter_complex \\\n' | |
'"afade=in:st=0:d=2,afade=out:st={dissolve_start}:d={dissolve_length}" \\\n' | |
'-y \\\n' | |
'minicuts/{name}.mp4' | |
) | |
def main(): | |
with open(os.path.join(current_dir, "cut_list.txt"), "r") as f: | |
lines = f.readlines() | |
dissolve_length = 2 | |
commands = [] | |
for i, line in enumerate(lines): | |
if "#" in line: | |
continue | |
name, start, duration = line.replace("\n", "").split(",") | |
num = str(i + 1).zfill(2) | |
dissolve_start = int(duration) - dissolve_length | |
commands.append(f"echo 'encoding cut {num}..'") | |
commands.append( | |
ffmpeg_command_template.format(start=start, | |
duration=duration, | |
dissolve_start=dissolve_start, | |
dissolve_length=dissolve_length, | |
fps=25, | |
name=name)) | |
with open(os.path.join(current_dir, "ffmpeg_cut.sh"), "w") as f: | |
f.write("#!/bin/bash\n") | |
f.write(f"export SOURCE={source}\n") | |
f.write("\n".join(commands)) | |
f.write("\n") | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
longcut01,00:00:35.000,47 | |
longcut02,00:02:06.000,25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment