From c963a21bbec2056fda6a03cafbba188010bcc98e Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 10 Aug 2024 23:21:11 +0300 Subject: [PATCH] transcode --- backend/config_parser.py | 32 +++++++++++-------- backend/nvr_core.py | 1 + backend/nvr_types.py | 10 ++++-- .../components/history/history.component.html | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/backend/config_parser.py b/backend/config_parser.py index 38892dd..f91a492 100644 --- a/backend/config_parser.py +++ b/backend/config_parser.py @@ -46,7 +46,7 @@ class Recorder: class TranscodeStatus: def __init__(self, b64) -> None: self.b64 = b64 - self.uuid = str(uuid.uuid4) + self.uuid = str(uuid.uuid4()) self.h264 = 0 self.downloaded_h264_bytes = 0 self.total_h264_bytes = 0 @@ -142,9 +142,11 @@ class TranscodeTools: else: raise Exception("Unknown platform to transcode") + exec_string += str(self.python_win32) + " " exec_string += str(self.converter_script) + " " exec_string += str(source_file) - proc = await asyncio.create_subprocess_exec(exec_string.split()) + print("execute", exec_string) + proc = await asyncio.create_subprocess_exec(exec_string) await proc.wait() if delete_source_file: @@ -156,7 +158,8 @@ class TranscodeTools: async def avitomp4(self, source_file, delete_source_file = False): exec_string = f"ffmpeg -y -i {source_file} {source_file}.mp4" - proc = await asyncio.create_subprocess_exec(exec_string.split()) + print("execute", exec_string) + proc = await asyncio.create_subprocess_exec(exec_string) await proc.wait() if delete_source_file: @@ -171,24 +174,27 @@ class TranscodeTools: async def processing(self, status: TranscodeStatus, file:File, nvr: NVR): raw_file = os.path.join(self.transcode_directory, status.uuid + ".h264") + print("save raw file to", raw_file) async with aiofiles.open(raw_file, "wb") as raw: - self.statuses[status.uuid].total_h264_bytes = file.size + self.statuses[status.b64].total_h264_bytes = file.size async for chunk in nvr.stream_file(file): - self.statuses[status.uuid].downloaded_h264_bytes += len(chunk) + self.statuses[status.b64].downloaded_h264_bytes += len(chunk) await raw.write(chunk) + print("raw file is downloaded") + print("logout from nvr, he is not more needed") nvr.logout() - self.statuses[status.uuid].avi = 0 + self.statuses[status.b64].avi = 0 avi_file = await self.h264toavi(raw_file) - self.statuses[status.uuid].avi = 100 + self.statuses[status.b64].avi = 100 - self.statuses[status.uuid].mp4 = 0 + self.statuses[status.b64].mp4 = 0 mp4_file = await self.avitomp4(avi_file) - self.statuses[status.uuid].mp4 = 100 + self.statuses[status.b64].mp4 = 100 - self.statuses[status.uuid].outFile = mp4_file - self.statuses[status.uuid].done = True - self.statuses[status.uuid].outSize = os.path.getsize(mp4_file) + self.statuses[status.b64].outFile = mp4_file + self.statuses[status.b64].done = True + self.statuses[status.b64].outSize = os.path.getsize(mp4_file) class Config: def __init__(self, config_name = "config.json", args = None) -> None: @@ -219,7 +225,7 @@ class Config: def check_transcode_tools(self, hide_check): tools_dir = os.path.join(app_dir(), "MiskaRisa264") - return TranscodeTools(tools_dir, self.check_transcode_directory, hide_check) + return TranscodeTools(tools_dir, self.check_transcode_directory(), hide_check) if __name__ == "__main__": import argparse diff --git a/backend/nvr_core.py b/backend/nvr_core.py index 8609588..f09b09b 100644 --- a/backend/nvr_core.py +++ b/backend/nvr_core.py @@ -51,6 +51,7 @@ class NVR: else: async for chunk in file.get_file_stream(self.client, len_data): if (chunk == None): + print("end of file") break yield chunk diff --git a/backend/nvr_types.py b/backend/nvr_types.py index e666d8e..3dbbc87 100644 --- a/backend/nvr_types.py +++ b/backend/nvr_types.py @@ -145,9 +145,12 @@ class File: break yield bytes(await client.receive_with_timeout(len_data)) - - if client and client.busy: - await client.busy.release() + try: + if client and client.busy: + await client.busy.release() + except: + pass + await client.send( 1420, { @@ -166,6 +169,7 @@ class File: "EndTime": self.end.strftime(NVR_DATETIME_FORMAT), }, }, + wait_response=False ) yield bytes(b"") diff --git a/frontend/ang_dvrip/src/app/components/history/history.component.html b/frontend/ang_dvrip/src/app/components/history/history.component.html index 04e323a..bf76863 100644 --- a/frontend/ang_dvrip/src/app/components/history/history.component.html +++ b/frontend/ang_dvrip/src/app/components/history/history.component.html @@ -4,7 +4,7 @@ Выбранный поток - + Основной Дополнительный