Files
ffmpeg_collection/quality_test.py
2022-09-09 19:46:34 +02:00

58 lines
2.1 KiB
Python

import re
import subprocess
import sys
from pathlib import Path
import os
droppedFile = sys.argv[1]
droppedName = Path(droppedFile).name
skipto = " -ss "
#droppedFile = ["sam_overlord_bluraysource.mkv"]
lines = "-map 0:v -c:v libx265 -preset slow -crf 21 -x265-params level=51:no-sao:bframes=8:psy-rd=1.5:psy-rdoq=5:aq-mode=3:ref=6 -pix_fmt yuv420p10le -map 0:a -c:a copy -map 0:s -c:s copy"
#org_lineslines = " -map 0:v -c:v libx264 -crf 0 -map 0:a -c:a copy -map 0:s -c:s copy"
#-map 0:v -c:v libx265 -preset slow -crf 21 -x265-params level=51:no-sao:bframes=8:psy-rd=1.5:psy-rdoq=5:aq-mode=3:ref=6 -pix_fmt yuv420p10le -map 0:a -c:a copy -map 0:s -c:s copy -f
del sys.argv[0]
number_of_segments=int(input("Number of segments: "))
segment_length=int(input("How long should each segment be(seconds)? "))
for i, file in enumerate(sys.argv):
arg_list = 'ffprobe.exe -show_entries format=duration -i "{file}"'.format(file=file)
print(arg_list)
cmd = subprocess.Popen(arg_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='UTF-8')
subprocess_std = cmd.communicate()[0]
print("stdout printing: " , subprocess_std)
video_duration = [int(s) for s in re.findall(r"[0-9]+", subprocess_std)][0]
print("video_duration: ", video_duration, "s")
duration_percent = video_duration / 100
print(duration_percent)
time = duration_percent * 15
skip = ((duration_percent * 90) - (duration_percent* 20)) / (number_of_segments -1)
for i in range(0, number_of_segments):
args = 'ffmpeg.exe -i "{file}" -ss {time} -t {segment_length} {lines} -f matroska "{file}{i}out.mkv"'.format(time=skip*i+time, segment_length=segment_length, file=file, lines=lines, i=i)
#args = 'ffmpeg.exe -i "{file}" -ss {time} -t {segment_length} {org_lineslines} -f matroska "{file}{i}ORIGINAL_COMP.mkv"'.format(time=skip*i+time, segment_length=segment_length, file=file, org_lineslines=org_lineslines, i=i)
print(args)
run = subprocess.Popen(args)
print('\n')
input("press enter to exit")