|
|
@ -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 |
|
|
|