Allow a chain of encoder/decoder commands

This commit is contained in:
Fierelier 2024-01-23 23:59:04 +01:00
parent c0a36b294b
commit f3b9495186
4 changed files with 43 additions and 54 deletions

View File

@ -49,16 +49,14 @@ def main():
for key in config["args"]:
os.environ["fstream_arg_" + key] = str(config["args"][key])
length = len(config["encoder"])
index = 0
while index < length:
if "values" in config:
for key in config["values"]:
config["encoder"][index] = config["encoder"][index].replace("$val:" +key+ "$",str(config["values"][key]))
for key in os.environ:
config["encoder"][index] = config["encoder"][index].replace("$env:" +key+ "$",os.environ[key])
index += 1
for encoder in config["encoder"]:
for i in range(len(encoder)):
if "values" in config:
for key in config["values"]:
encoder[i] = encoder[i].replace("$val:" +key+ "$",str(config["values"][key]))
for key in os.environ:
encoder[i] = encoder[i].replace("$env:" +key+ "$",os.environ[key])
ssl = False
if "ssl" in config and "enabled" in config["ssl"] and config["ssl"]["enabled"] != False:
@ -90,24 +88,18 @@ def main():
del os.environ["fstream_arg_user_password"]
del os.environ["fstream_ssl"]
procClient = subprocess.Popen([
sys.executable,
p(sp,"fstream.py"),
addressStr(address),
"broadcast"
],stdin=subprocess.PIPE)
cmds = []
for encoder in config["encoder"]: cmds.append(encoder)
if aes == True: cmds.append([sys.executable,p(sp,"util","fstream-util-aes_to_pipe.py")])
cmds.append([sys.executable,p(sp,"fstream.py"),addressStr(address),"broadcast"])
if aes == True:
procEncoder = subprocess.Popen(config["encoder"],stdout=subprocess.PIPE)
procAes = subprocess.Popen([
sys.executable,
p(sp,"util","fstream-util-pipe_to_aes.py"),
addressStr(address),
"broadcast"
],stdin=procEncoder.stdout,stdout=procClient.stdin)
else:
procEncoder = subprocess.Popen(config["encoder"],stdout=procClient.stdin)
procs = []
procs.append(subprocess.Popen(cmds[0],stdout=subprocess.PIPE))
for i in range(1,len(cmds) - 1):
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
procEncoder.wait()
for proc in reversed(procs):
proc.wait()
main()

View File

@ -16,6 +16,7 @@ values.framerate = 30
values.bitrate = "1M"
values.resolution = 480
encoder = [
[
"ffmpeg",
# INPUT
"-strict","experimental","-avioflags","direct","-thread_queue_size","1","-hwaccel","auto","-probesize","32","-fflags","nobuffer","-flags","low_delay","-flags2","fast", # delay hack
@ -35,3 +36,4 @@ encoder = [
"-flags2","fast","-muxdelay","0","-muxpreload","0","-max_delay","0","-flush_packets","1", # delay hack
"-"
]
]

View File

@ -10,7 +10,9 @@ args.bufsize = 4096
# Decoder values
decoder = [
[
"ffplay",
"-avioflags","direct","-strict","experimental","-analyzeduration","0","-sync","ext","-probesize","32","-fflags","nobuffer","-flags","low_delay","-max_delay","0","-max_probe_packets","0","-x264opts","intra-refresh=1","-fflags","discardcorrupt","-vf","setpts=0", # delay hack
"-"
]
]

View File

@ -49,16 +49,14 @@ def main():
for key in config["args"]:
os.environ["fstream_arg_" + key] = str(config["args"][key])
length = len(config["decoder"])
index = 0
while index < length:
if "values" in config:
for key in config["values"]:
config["decoder"][index] = config["decoder"][index].replace("$val:" +key+ "$",str(config["values"][key]))
for key in os.environ:
config["decoder"][index] = config["decoder"][index].replace("$env:" +key+ "$",os.environ[key])
index += 1
for decoder in config["decoder"]:
for i in range(len(decoder)):
if "values" in config:
for key in config["values"]:
decoder[i] = decoder[i].replace("$val:" +key+ "$",str(config["values"][key]))
for key in os.environ:
decoder[i] = decoder[i].replace("$env:" +key+ "$",os.environ[key])
aes = False
if "aespass" in config:
@ -72,24 +70,19 @@ def main():
address = config["address"].rsplit(":",1)
address[1] = int(address[1])
procClient = subprocess.Popen([
sys.executable,
p(sp,"fstream.py"),
addressStr(address),
"watch"
],stdout=subprocess.PIPE)
cmds = []
cmds.append([sys.executable,p(sp,"fstream.py"),addressStr(address),"watch"])
if aes == True: cmds.append([sys.executable,p(sp,"util","fstream-util-aes_to_pipe.py")])
for decoder in config["decoder"]: cmds.append(decoder)
for cmd in cmds: print(cmd)
if aes == True:
procDecoder = subprocess.Popen(config["decoder"],stdin=subprocess.PIPE)
procAes = subprocess.Popen([
sys.executable,
p(sp,"util","fstream-util-aes_to_pipe.py"),
addressStr(address),
"watch"
],stdin=procClient.stdout,stdout=procDecoder.stdin)
else:
procDecoder = subprocess.Popen(config["encoder"],stdin=procClient.stdout)
procs = []
procs.append(subprocess.Popen(cmds[0],stdout=subprocess.PIPE))
for i in range(1,len(cmds) - 1):
procs.append(subprocess.Popen(cmds[i],stdin=procs[i - 1].stdout,stdout=subprocess.PIPE))
procs.append(subprocess.Popen(cmds[-1],stdin=procs[-1].stdout))
procDecoder.wait()
for proc in reversed(procs):
proc.wait()
main()