Last active
July 3, 2020 06:47
-
-
Save npyoung/4745d153dba69a79a463972d28c98f63 to your computer and use it in GitHub Desktop.
Video creation and editing tools
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
import argparse as ap | |
from pathlib import Path | |
import ffmpeg | |
def compress(in_file): | |
out_file = in_file.parent / (in_file.stem + ' (1440p)' + in_file.suffix) | |
opts = { | |
'c:a': 'copy', | |
'c:v': 'libx265', | |
'crf': '24', | |
'preset': 'medium', | |
} | |
( | |
ffmpeg | |
.input(str(in_file)) | |
.filter('scale', -1, 1440) | |
.output(str(out_file), **opts) | |
.run() | |
) | |
def reencode(in_file, frame_rate): | |
out_file = in_file.parent / (in_file.stem + '_r' + in_file.suffix) | |
opts = { | |
'c:a': 'copy', | |
'c:v': 'libx264', | |
'map_metadata': '0' | |
} | |
( | |
ffmpeg | |
.input(str(in_file)) | |
.output(str(out_file), **opts) | |
.run() | |
) | |
if __name__ == '__main__': | |
parser = ap.ArgumentParser() | |
parser.add_argument('task', choices=['compress', 'reencode']) | |
parser.add_argument('-i', dest='in_file', type=str) | |
parser.add_argument('-r', dest='frame_rate', default=30.0) | |
args = parser.parse_args() | |
if args.task == "compress": | |
compress(Path(args.in_file)) | |
elif args.task == "reencode": | |
reencode(Path(args.in_file), frame_rate=args.frame_rate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment