Browse Source

fix transcode

master
gsd 8 months ago
parent
commit
9e1be342fc
  1. 46
      backend/config_parser.py

46
backend/config_parser.py

@ -134,20 +134,21 @@ class TranscodeTools:
return False return False
async def h264toavi(self, source_file, delete_source_file = False): async def h264toavi(self, source_file, delete_source_file = False):
exec_string = "" exec_string = []
exec_cmd = ""
if platform.system() == "Windows": if platform.system() == "Windows":
exec_string += "" exec_cmd = f"{self.python_win32}"
elif platform.system() == "Linux": elif platform.system() == "Linux":
exec_string += "wine " exec_cmd = "wine"
else: exec_string.append(self.python_win32)
raise Exception("Unknown platform to transcode") raise Exception("Unknown platform to transcode")
exec_string += str(self.python_win32) + " " exec_string.append(self.converter_script)
exec_string += str(self.converter_script) + " " exec_string.append(source_file)
exec_string += str(source_file)
print("execute", exec_string) print("execute", exec_cmd, exec_string)
proc = await asyncio.create_subprocess_exec(exec_string) proc = await asyncio.create_subprocess_exec(exec_cmd, *exec_string)
await proc.wait() await proc.communicate()
if delete_source_file: if delete_source_file:
os.remove(source_file) os.remove(source_file)
@ -157,10 +158,10 @@ class TranscodeTools:
raise Exception("AVI not be created") raise Exception("AVI not be created")
async def avitomp4(self, source_file, delete_source_file = False): async def avitomp4(self, source_file, delete_source_file = False):
exec_string = f"ffmpeg -y -i {source_file} {source_file}.mp4" exec_string = ["-y", "-i", source_file, f"{source_file}.mp4"]
print("execute", exec_string) print("execute", exec_string)
proc = await asyncio.create_subprocess_exec(exec_string) proc = await asyncio.create_subprocess_exec("ffmpeg", *exec_string)
await proc.wait() await proc.communicate()
if delete_source_file: if delete_source_file:
os.remove(source_file) os.remove(source_file)
@ -196,6 +197,16 @@ class TranscodeTools:
self.statuses[status.b64].done = True self.statuses[status.b64].done = True
self.statuses[status.b64].outSize = os.path.getsize(mp4_file) self.statuses[status.b64].outSize = os.path.getsize(mp4_file)
async def transcode_test(self, raw_file):
avi_file = await self.h264toavi(raw_file)
mp4_file = await self.avitomp4(avi_file)
def h264toavi_test(self, raw_file):
loop = asyncio.get_event_loop()
tasks = [loop.create_task(self.transcode_test(raw_file))]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()
class Config: class Config:
def __init__(self, config_name = "config.json", args = None) -> None: def __init__(self, config_name = "config.json", args = None) -> None:
raw = load_config(config_name) raw = load_config(config_name)
@ -231,8 +242,11 @@ if __name__ == "__main__":
import argparse import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--no-hide-check", action="store_true") parser.add_argument("--no-hide-check", action="store_true")
parser.add_argument("--test-h264toavi", type=str)
args = parser.parse_args() args = parser.parse_args()
config = Config(args = args)
if args.no_hide_check: if args.test_h264toavi:
Config(args = args) config.transcode_tools.h264toavi_test(args.test_h264toavi)
sys.exit(0)
sys.exit(0) sys.exit(0)
Loading…
Cancel
Save