Initial
This commit is contained in:
89
Utils.py
Normal file
89
Utils.py
Normal file
@@ -0,0 +1,89 @@
|
||||
from StreamDesc import StreamDesc
|
||||
import subprocess
|
||||
|
||||
# ffprobe_a = r"C:\Users\Thaloria\Downloads\ffmpeg-4.4-full_build\bin\ffprobe.exe -i S01e01.mkv -show_entries stream=index:stream_tags=language -select_streams a -v 0 -of compact=p=0:nk=1"
|
||||
# ffprobe_s = r"C:\Users\Thaloria\Downloads\ffmpeg-4.4-full_build\bin\ffprobe.exe -i S01e01.mkv -show_entries stream=index:stream_tags=language -select_streams s -v 0 -of compact=p=0:nk=1"
|
||||
# -i "E:\tmp\S01e01.mkv" -i "S01e01_1.88x_1920x1080_dtvs-2.mp4" -map 1:0 -map 0:1 -map 0:2 -map 0:4 -map 0:6 -map 0:11 -c:v:0 copy -c:s:0 copy -c:s:1 copy -c:s:2 copy -c:a:0 aac -b:a:0 384k -c:a:1 aac -b:a:1 384k -vn -y "E:\tmp\out.mp4"
|
||||
|
||||
FFEXE_STATIC = r"C:\Users\Thaloria\Downloads\ffmpeg-4.4-full_build\bin\ffmpeg.exe"
|
||||
FFPROBE_STATIC = r"C:\Users\Thaloria\Downloads\ffmpeg-4.4-full_build\bin\ffprobe.exe"
|
||||
|
||||
|
||||
def stream_selector(input_file_path, input_no):
|
||||
cmd_a = FFPROBE_STATIC + " -i " + input_file_path + " -show_entries stream=index:stream_tags=language -select_streams a -v 0 -of compact=p=0:nk=1"
|
||||
output = subprocess.check_output(cmd_a, shell=True)
|
||||
str_out = str(output)
|
||||
list_out = format_output(str_out)
|
||||
|
||||
desc_list = []
|
||||
|
||||
for stream_item in list_out:
|
||||
if 'de' in stream_item or 'en' in stream_item:
|
||||
desc = StreamDesc(stream_item, "a", input_no)
|
||||
desc_list.append(desc)
|
||||
|
||||
cmd_s = FFPROBE_STATIC + " -i " + input_file_path + " -show_entries stream=index:stream_tags=language -select_streams s -v 0 -of compact=p=0:nk=1"
|
||||
output = subprocess.check_output(cmd_s, shell=True)
|
||||
str_out = str(output)
|
||||
list_out = format_output(str_out)
|
||||
|
||||
for stream_item in list_out:
|
||||
if 'de' in stream_item or 'en' in stream_item:
|
||||
desc = StreamDesc(stream_item, "s", input_no)
|
||||
desc_list.append(desc)
|
||||
|
||||
return desc_list
|
||||
|
||||
|
||||
def select_video_stream(i_streams, in_stream_no):
|
||||
desc = StreamDesc("0|de", "v", in_stream_no)
|
||||
cp_str = i_streams
|
||||
cp_str.append(desc)
|
||||
return cp_str
|
||||
|
||||
|
||||
def format_output(data):
|
||||
if data.startswith(r"b'"):
|
||||
data = data[2:]
|
||||
new_list = data.split(r"\r\n")
|
||||
|
||||
try:
|
||||
while True:
|
||||
# new_list.remove() ("",)
|
||||
new_list.remove('\x0c')
|
||||
except ValueError:
|
||||
pass
|
||||
return new_list
|
||||
|
||||
|
||||
def add_input(line, input_path):
|
||||
line1 = line + " -i " + input_path
|
||||
return line1
|
||||
|
||||
|
||||
def add_stream_selection(line, stream_descs):
|
||||
out_line = line
|
||||
for stream in stream_descs:
|
||||
out_line = out_line + " -map " + str(stream.stream_input_no) + ":" + str(stream.stream_no)
|
||||
|
||||
v_no = 0
|
||||
a_no = 0
|
||||
s_no = 0
|
||||
for stream in stream_descs:
|
||||
if "v" == stream.stream_type:
|
||||
out_line = out_line + " -c:" + stream.stream_type + ":" + str(v_no) + " copy"
|
||||
elif "s" == stream.stream_type:
|
||||
out_line = out_line + " -c:" + stream.stream_type + ":" + str(s_no) + " copy"
|
||||
out_line = out_line + " -metadata:s:s:" + str(s_no) + " language=" + stream.stream_lang
|
||||
s_no = s_no + 1
|
||||
elif "a" == stream.stream_type:
|
||||
out_line = out_line + " -c:" + stream.stream_type + ":" + str(a_no) + " aac -b:a:" + str(a_no) + " 384k"
|
||||
# -metadata:s:a:0 title="One" -metadata:s:a:1 title="Two" -metadata:s:a:0 language=eng
|
||||
out_line = out_line + " -metadata:s:a:" + str(a_no) + " language=" + stream.stream_lang
|
||||
a_no = a_no + 1
|
||||
return out_line
|
||||
|
||||
|
||||
def add_output(line, out_path):
|
||||
line1 = line + " -y " + out_path
|
||||
return line1
|
||||
Reference in New Issue
Block a user