Updated plexoptimise to handle multiple files, output info to stderr so
cmdlines can be piped into script.
This commit is contained in:
parent
b2322287a9
commit
b1401ac41b
@ -71,15 +71,15 @@ def add_audio_params(params, out_idx, stream):
|
|||||||
params["filter_complex"].append("[0:{}]{}".format(stream["index"], STEREO))
|
params["filter_complex"].append("[0:{}]{}".format(stream["index"], STEREO))
|
||||||
lang = stream["tags"]["language"]
|
lang = stream["tags"]["language"]
|
||||||
if lang in ["und"]:
|
if lang in ["und"]:
|
||||||
print("Language fallback from \"{}\" to \"{}\".".format(lang, DEFAULT_LANGUAGE))
|
print("Language fallback from \"{}\" to \"{}\".".format(lang, DEFAULT_LANGUAGE), file=sys.stderr)
|
||||||
lang = DEFAULT_LANGUAGE
|
lang = DEFAULT_LANGUAGE
|
||||||
params["metadata:s:{}".format(out_idx)] = "language={}".format(lang)
|
params["metadata:s:{}".format(out_idx)] = "language={}".format(lang)
|
||||||
|
|
||||||
def add_sub_params(params, out_idx, stream):
|
def add_sub_params(params, out_idx, stream):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def build_ffmpeg_cmd(params):
|
def build_ffmpeg_cmd(filename, params):
|
||||||
cmd = ["nice", "ffmpeg", "-i", "\"{}\"".format(FILENAME)]
|
cmd = ["nice", "ffmpeg", "-i", "\"{}\"".format(filename)]
|
||||||
for p, v in params.items():
|
for p, v in params.items():
|
||||||
if p == "map":
|
if p == "map":
|
||||||
for s in v:
|
for s in v:
|
||||||
@ -91,12 +91,11 @@ def build_ffmpeg_cmd(params):
|
|||||||
cmd.append("\"{}\"".format(";".join(v)))
|
cmd.append("\"{}\"".format(";".join(v)))
|
||||||
else:
|
else:
|
||||||
cmd.append(v)
|
cmd.append(v)
|
||||||
cmd.append("\"{}.mkv\"".format(FILENAME))
|
cmd.append("\"{}.mkv\"".format(filename))
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
FILENAME = sys.argv[1]
|
def get_optimise_cmdline(filename):
|
||||||
|
data = ffprobe(filename)
|
||||||
data = ffprobe(FILENAME)
|
|
||||||
#pprint(data)
|
#pprint(data)
|
||||||
|
|
||||||
video_streams = []
|
video_streams = []
|
||||||
@ -118,7 +117,7 @@ for s in data["streams"]:
|
|||||||
s["width"],
|
s["width"],
|
||||||
s["height"],
|
s["height"],
|
||||||
"p" if "field_order" not in s or s["field_order"] == "progressive" else "i"
|
"p" if "field_order" not in s or s["field_order"] == "progressive" else "i"
|
||||||
))
|
), file=sys.stderr)
|
||||||
elif codec == "audio":
|
elif codec == "audio":
|
||||||
audio_streams.append(s)
|
audio_streams.append(s)
|
||||||
print("Input #{}: Audio {} {}ch {} ({})".format(
|
print("Input #{}: Audio {} {}ch {} ({})".format(
|
||||||
@ -127,14 +126,14 @@ for s in data["streams"]:
|
|||||||
s["channels"],
|
s["channels"],
|
||||||
s["channel_layout"],
|
s["channel_layout"],
|
||||||
s["tags"]["language"]
|
s["tags"]["language"]
|
||||||
))
|
), file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
other_streams.append(s)
|
other_streams.append(s)
|
||||||
print("Input #{}: Data {} {}".format(
|
print("Input #{}: Data {} {}".format(
|
||||||
s["index"],
|
s["index"],
|
||||||
s["codec_type"],
|
s["codec_type"],
|
||||||
s["codec_tag_string"]
|
s["codec_tag_string"]
|
||||||
))
|
), file=sys.stderr)
|
||||||
|
|
||||||
# Make sure first audio is FIRST_LANGUAGE
|
# Make sure first audio is FIRST_LANGUAGE
|
||||||
if audio_streams[0]["tags"]["language"] != FIRST_LANGUAGE:
|
if audio_streams[0]["tags"]["language"] != FIRST_LANGUAGE:
|
||||||
@ -160,9 +159,12 @@ for i, s in enumerate(output_streams):
|
|||||||
elif codec == "subtitle":
|
elif codec == "subtitle":
|
||||||
add_sub_params(params, i, s)
|
add_sub_params(params, i, s)
|
||||||
else:
|
else:
|
||||||
print("Unknown codec_type: {}".format(codec))
|
print("Unknown codec_type: {}".format(codec), file=sys.stderr)
|
||||||
|
|
||||||
cmd = build_ffmpeg_cmd(params)
|
cmd = build_ffmpeg_cmd(filename, params)
|
||||||
|
|
||||||
#pprint(output_streams)
|
#pprint(output_streams)
|
||||||
print(" ".join(cmd))
|
return " ".join(cmd)
|
||||||
|
|
||||||
|
for f in sys.argv[1:]:
|
||||||
|
print(get_optimise_cmdline(f))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user