forked from CrypticSignal/video-quality-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_video.py
28 lines (20 loc) · 902 Bytes
/
encode_video.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
27
28
from ffmpeg_process_factory import EncodingArguments, FfmpegProcessFactory
from utils import Logger, Timer
log = Logger("encode_video.py")
def encode_video(video_path, args, crf, preset, output_path, message, duration):
arguments = EncodingArguments(video_path, args.video_encoder, output_path)
if args.video_encoder == "libaom-av1":
arguments.av1_cpu_used(str(args.av1_cpu_used))
arguments.crf(str(crf))
arguments.preset(preset)
video_filters = args.video_filters if args.video_filters else None
arguments.video_filters(video_filters)
factory = FfmpegProcessFactory()
process = factory.create_process(arguments, args)
log.info(f"Converting the video using {message}...")
timer = Timer()
timer.start()
process.run(video_path, duration)
time_taken = timer.stop(args.decimal_places)
log.info("Done!")
return factory, time_taken