Browse Source

transcode

master
gsd 8 months ago
parent
commit
c963a21bbe
  1. 32
      backend/config_parser.py
  2. 1
      backend/nvr_core.py
  3. 10
      backend/nvr_types.py
  4. 2
      frontend/ang_dvrip/src/app/components/history/history.component.html

32
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

1
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

10
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"")

2
frontend/ang_dvrip/src/app/components/history/history.component.html

@ -4,7 +4,7 @@
<ng-container>
<mat-form-field>
<mat-label>Выбранный поток</mat-label>
<mat-select [(value)]="selected_stream">
<mat-select [(value)]="selected_stream" (valueChange)="getHistory()">
<mat-option [value]="0">Основной</mat-option>
<mat-option [value]="1">Дополнительный</mat-option>
</mat-select>

Loading…
Cancel
Save