just changing stuff

This commit is contained in:
Elghinnarisa
2023-03-26 18:31:49 +02:00
parent f8ccf44a92
commit 790fd3538e
8 changed files with 242 additions and 18 deletions

2
.gitignore vendored
View File

@@ -13,3 +13,5 @@ input.txt
.gitignore
*.mkv
long_path_test.py
\__pycache__
log.txt

View File

@@ -0,0 +1,38 @@
import subprocess
import sys
from pathlib import Path
import os
output_folder_name = "/bulk_convert_out/"
droppedFile = sys.argv[1]
droppedName = Path(droppedFile).name
skipto = ""
duration = ""
print(droppedName)
#get path of script location and remove the tail
head_tail = os.path.split(sys.argv[0])
output_path = head_tail[0]
del sys.argv[0]
#check if output folder exists, otherwise create it
isExist = os.path.exists(output_path+output_folder_name)
if not isExist:
os.makedirs(output_path+output_folder_name)
for file in sys.argv:
basename = os.path.basename(file)
print(file)
# opus audio - might not work for surround -
args = 'ffmpeg.exe -i "{file}" -map 0:v -c:v copy -map 0:a:0 -c:a libopus -b:a 192 -map 0:a -c:a libopus -b:a 192k -map 0:s -c:s copy -f matroska "{output_path}{output_folder_name}{basename}"'.format(file=file, output_path=output_path, output_folder_name=output_folder_name, basename=basename)
#arg_list = "".join(map(str, arguments))
print(args)
#print(each)
subprocess.run(args)
k=input("press close to exit")

44
core_count_test 2.py Normal file
View File

@@ -0,0 +1,44 @@
import subprocess
import sys
from pathlib import Path
import os
output_folder_name ="/bulk_convert_out/"
droppedFile = sys.argv[1]
droppedName = Path(droppedFile).name
skipto = ""
duration = ""
print(droppedName)
#get path of script location and remove the tail
head_tail = os.path.split(sys.argv[0])
output_path = head_tail[0]
#skip first part of sys.argv since it points to script location
arguments = sys.argv[1:]
#check if output folder exists, otherwise create it
isExist = os.path.exists(output_path+output_folder_name)
if not isExist:
os.makedirs(output_path+output_folder_name)
i=1
x=5
while i < x:
for file in arguments:
basename = os.path.basename(file)
print(file)
args = 'ffmpeg.exe -i "{file}" -map 0:v -c:v libx265 -preset slow -crf 20 -x265-params "level=51:no-sao=1:bframes=8:psy-rd=1.5:psy-rdoq=5:aq-mode=3:ref=6" -pix_fmt yuv420p10le -map 0:a -c:a libopus -b:a 192k -map 0:s -c:s copy -f matroska "{output_path}{output_folder_name}{basename}"'.format(file=file, output_path=output_path, output_folder_name=output_folder_name, basename=basename)
print(args)
subprocess.run(args, returncode=0)
print(subprocess.CompletedProcess)
i=i+1
k=input("press close to exit")

46
core_count_test.py Normal file
View File

@@ -0,0 +1,46 @@
import subprocess
import sys
from pathlib import Path
import os
import psutil
output_folder_name ="/bulk_convert_out/"
droppedFile = sys.argv[1]
droppedName = Path(droppedFile).name
skipto = ""
duration = ""
print(droppedName)
#get path of script location and remove the tail
head_tail = os.path.split(sys.argv[0])
output_path = head_tail[0]
#skip first part of sys.argv since it points to script location
arguments = sys.argv[1:]
#check if output folder exists, otherwise create it
isExist = os.path.exists(output_path+output_folder_name)
if not isExist:
os.makedirs(output_path+output_folder_name)
def run_ffmpeg(file):
basename = os.path.basename(file)
print(file)
args = 'ffmpeg.exe -i "{file}" -map 0:v -c:v libx265 -preset slow -crf 20 -x265-params "level=51:no-sao=1:bframes=8:psy-rd=1.5:psy-rdoq=5:aq-mode=3:ref=6" -pix_fmt yuv420p10le -map 0:a -c:a libopus -b:a 192k -map 0:s -c:s copy -f matroska "{output_path}{output_folder_name}{basename}"'.format(file=file, output_path=output_path, output_folder_name=output_folder_name, basename=basename)
print(args)
psutil.Process.cpu_affinity([0,1])
psutil.Popen(args)
for file in arguments:
run_ffmpeg(file)
k=input("press close to exit")

89
core_count_test_2.py Normal file
View File

@@ -0,0 +1,89 @@
from multiprocessing.connection import wait
import subprocess
import sys
from pathlib import Path
import os
from time import sleep
from threading import Thread
import threading
output_folder_name ="/bulk_convert_out/"
#droppedFile = sys.argv[1]
#droppedName = Path(droppedFile).name
skipto = ""
duration = ""
#print(droppedName)
droppedFile= ['test.mkv0out.mkv', "test.mkv1out.mkv","test.mkv2out.mkv","test.mkv3out.mkv","test.mkv4out.mkv","test.mkv5out.mkv"]
#get path of script location and remove the tail
head_tail = os.path.split(sys.argv[0])
output_path = head_tail[0]
#skip first part of sys.argv since it points to script location
#arguments = sys.argv[1:]
arguments = droppedFile
#check if output folder exists, otherwise create it
isExist = os.path.exists(output_path+output_folder_name)
if not isExist:
os.makedirs(output_path+output_folder_name)
x=3
i=0
org_count = len(arguments)
class CustomThread(Thread):
# constructor
def __init__(self):
# execute the base constructor
Thread.__init__(self)
# set a default value
self.ret = None
def run(self):
#sleep(1)
global i
file=arguments.pop(0)
basename = os.path.basename(file)
print(file)
args = 'ffmpeg.exe -i "{file}" -map 0:v -c:v libx265 -preset veryfast -crf 22 -map 0:a -f matroska "{output_path}{output_folder_name}{basename}"'.format(file=file, output_path=output_path, output_folder_name=output_folder_name, basename=basename)
print(args)
results = subprocess.Popen(args, stdout=subprocess.PIPE)
streeamdata = results.communicate()[0]
if results.returncode == 0:
self.ret = 0
print(self.ret)
i=i-1
while arguments != False:
if i < x:
global self
#streamdata= results.communicate()[0]
if bool(arguments) != False:
t1 = CustomThread()
t1.start()
if bool(arguments) == False:
t1.join()
print("Completed Successfully")
exit()
print("incrementing i in loop")
i=i+1
else:
current_threads = threading.active_count()-1
current_left = len(arguments)
current_count = current_threads-current_left
print("Finished ",current_count,"out of ", org_count)
f = open("log.txt", "a")
f.write("entering false \n")
f.close()
sleep(1)
print("continuing")

View File

@@ -17,13 +17,14 @@ output_path = head_tail[0]
#skip first part of sys.argv since it points to script location
arguments = sys.argv[1:]
number_of_ss=int(input("Number of ss: "))
print(number_of_ss)
#check if output folder exists, otherwise create it
isExist = os.path.exists(output_path+output_folder_name)
if not isExist:
os.makedirs(output_path+output_folder_name)
number_of_ss=int(input("Number of ss: "))
print(number_of_ss)
#run ffprobe to get duration of input file, then get appropriate timestamps out of it
for i, file in enumerate(arguments):

View File

@@ -11,28 +11,22 @@ files_processed = []
droppedFile = sys.argv[1]
droppedName = Path(droppedFile).name
originalfiles = sys.orig_argv[2:]
# To fix I need to create symlinks to files with long paths and use the links instead. And then remove said symlinks once
audio_list = []
sub_list = []
#droppedFile= ['X:\\test\\longpathtest\\longerpathlongerpathlongerpathlongerpathlongerpathlongerpathlongerpath\\longpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpath\\fourteen\\[Kira-Fansub]_Choujuushin Gravion_Episode 06_(BD 1280x960 h264 JP AAC EN AAC) [E7D92968].mkv', '', ' X:\\test\\longpathtest\\longerpathlongerpathlongerpathlongerpathlongerpathlongerpathlongerpath\\longpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpathlongpath\\fourteen\\[Kira-Fansub]_Choujuushin Gravion_Episode 09_(BD 1280x960 h264 JP AAC EN AAC) [A2727604].mkv']
#originalfiles = droppedFile
print(droppedFile)
print()
print()
print("printing original: ", originalfiles)
joined = (' '.join(originalfiles))
print("printing joined: ", joined)
re.sub (' +', ' ', joined)
print("duble spaces removed? :", joined)
listed = re.split(r'([A-Z]:.+?)(?=[A-Z]:)', joined)
listed = re.split(r'(.+?mkv)', joined)
listed = list(filter(None, listed))
listed = [i.lstrip() for i in listed]
print("printing listed: ", listed)
#get path of script location and remove the tail
@@ -44,8 +38,6 @@ isExist = os.path.exists(output_path+output_folder_name)
if not isExist:
os.makedirs(output_path+output_folder_name)
#droppedFile = "test.mkv"
for i, file in enumerate(listed):
arg_list = '.\\ffprobe.exe -i "{file}"'.format(file=file)
@@ -54,16 +46,29 @@ for i, file in enumerate(listed):
cmd = subprocess.Popen(["powershell.exe", arg_list], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='UTF-8')
subprocess_err = cmd.communicate()[1]
print(subprocess_err)
print("file", i+1,":", Path(file).name)
for r, match in enumerate(regex_audio.finditer(subprocess_err)):
print("Audio Track", r,": ", match.group(0))
audio_list.append(match.group(0))
for r, match in enumerate(regex_subtitle.finditer(subprocess_err)):
print("Subtitle Track", r,": ", match.group(0))
sub_list.append(match.group(0))
print('\n')
print("Tally for audio tracks: ", "\n")
my_dict = {i:audio_list.count(i) for i in audio_list}
for key, value in my_dict.items():
print(key, ' : ', value)
print()
print("Tally for subtitle tracks tracks: ", "\n")
my_dict = {i:sub_list.count(i) for i in sub_list}
for key, value in my_dict.items():
print(key, ' : ', value)
x = (int(x) for x in input ("Enter audio tracks to keep: ").split())
audio_track = "".join(" -map 0:a:{}".format(y) for y in x)
@@ -73,7 +78,6 @@ z = (int(z) for z in input ("Enter subtitle tracks to keep: ").split())
subtitle_track = "".join(" -map 0:s:{}".format(y) for y in z)
for file in listed:
basename = os.path.basename(file)
arg_list = 'ffmpeg.exe -i "{file}" -map 0:v {audio_track} {subtitle_track} -c copy "{output_path}{output_folder_name}{basename}"'.format(file=file, audio_track=audio_track, subtitle_track=subtitle_track, output_path=output_path, output_folder_name=output_folder_name, basename=basename)

View File

@@ -54,7 +54,7 @@ audio_track = "".join(" -map 0:a:{}".format(y) for y in x)
z = (int(z) for z in input ("Enter subtitle tracks to keep: ").split())
subtitle_track = "".join(" -map 0:s:{}".format(y) for y in z)
for file in sys.argv:
for file in arguments:
basename = os.path.basename(file)