Browse Source

pre alpha 3 / image support

master
gsd 8 months ago
parent
commit
43a88f8377
  1. 8
      backend/config_parser.py
  2. 7
      backend/server.py
  3. 2
      frontend/ang_dvrip/src/app/app.component.html
  4. 8
      frontend/ang_dvrip/src/app/app.component.ts
  5. 2
      frontend/ang_dvrip/src/app/components/about/about.component.html
  6. 7
      frontend/ang_dvrip/src/app/components/about/about.component.ts

8
backend/config_parser.py

@ -178,6 +178,14 @@ class TranscodeTools:
async def processing(self, status: TranscodeStatus, file:File, nvr: NVR, reCreate:bool = False): async def processing(self, status: TranscodeStatus, file:File, nvr: NVR, reCreate:bool = False):
raw_file = os.path.join(self.transcode_directory, status.uuid + ".h264") raw_file = os.path.join(self.transcode_directory, status.uuid + ".h264")
mp4_file = os.path.join(self.transcode_directory, status.uuid + ".h264.avi.mp4")
if os.path.exists(mp4_file) and os.path.getsize(mp4_file) != 0:
nvr.logout()
self.statuses[status.b64].outFile = mp4_file
self.statuses[status.b64].done = True
self.statuses[status.b64].outSize = os.path.getsize(mp4_file)
return
if not os.path.exists(raw_file) or os.path.getsize(raw_file) != file.size: if not os.path.exists(raw_file) or os.path.getsize(raw_file) != file.size:
print("save raw file to", raw_file) print("save raw file to", raw_file)
async with aiofiles.open(raw_file, "wb") as raw: async with aiofiles.open(raw_file, "wb") as raw:

7
backend/server.py

@ -63,10 +63,9 @@ class Server:
try: try:
nvr:NVR = self.config.getRecorder(recorder_index).nvr nvr:NVR = self.config.getRecorder(recorder_index).nvr
await nvr.login() await nvr.login()
async def image(): data = await nvr.client.snapshot(channel)
async for b in await nvr.client.snapshot(channel):
yield b return Response(content=bytes(data), media_type="image/jpg")
return StreamingResponse(image(), media_type="image/jpg")
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
response.status_code = 400 response.status_code = 400

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

@ -5,7 +5,7 @@
<span class="spacer"></span> <span class="spacer"></span>
<ng-container *ngIf="!loading"> <ng-container *ngIf="!loading">
<mat-form-field *ngIf="availble_channels.length>0"> <mat-form-field *ngIf="availble_channels.length>0">
<mat-select [(value)]="selected_channel"> <mat-select [(value)]="selected_channel" (valueChange)="goToRoot()">
<mat-option *ngFor="let r of availble_channels" [value]="availble_channels.indexOf(r)">{{r}}</mat-option> <mat-option *ngFor="let r of availble_channels" [value]="availble_channels.indexOf(r)">{{r}}</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>

8
frontend/ang_dvrip/src/app/app.component.ts

@ -1,6 +1,7 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {ApiService} from "./services/ApiService"; import {ApiService} from "./services/ApiService";
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {ActivatedRoute, Router} from "@angular/router";
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -19,7 +20,8 @@ export class AppComponent implements OnInit {
} }
constructor(private api:ApiService, constructor(private api:ApiService,
private http: HttpClient) { private http: HttpClient,
private router:Router) {
} }
getRecorders() { getRecorders() {
@ -41,4 +43,8 @@ export class AppComponent implements OnInit {
this.loading = false; this.loading = false;
}) })
} }
goToRoot() {
this.router.navigate(["/"])
}
} }

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

@ -1 +1 @@
<p>about works!</p> <img style="width: 100%" [src]="'/api/snapshot/' + recorder_index + '/' + channel_index">

7
frontend/ang_dvrip/src/app/components/about/about.component.ts

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";
@Component({ @Component({
selector: 'app-about', selector: 'app-about',
@ -6,10 +7,14 @@ import { Component, OnInit } from '@angular/core';
styleUrls: ['./about.component.css'] styleUrls: ['./about.component.css']
}) })
export class AboutComponent implements OnInit { export class AboutComponent implements OnInit {
recorder_index: number = 0;
channel_index: number = 0;
constructor() { } constructor(private route:ActivatedRoute) {}
ngOnInit(): void { ngOnInit(): void {
this.recorder_index = Number.parseInt(<string>this.route.snapshot.paramMap.get('recorderId'));
this.channel_index = Number.parseInt(<string>this.route.snapshot.paramMap.get('channelId'));
} }
} }

Loading…
Cancel
Save