최지우

비디오 녹화 시간 체크 관련 추가

1 -# Generated by Django 3.1.2 on 2020-11-13 10:30
2 -
3 -from django.db import migrations, models
4 -import django.utils.timezone
5 -
6 -
7 -class Migration(migrations.Migration):
8 -
9 - initial = True
10 -
11 - dependencies = [
12 - ]
13 -
14 - operations = [
15 - migrations.CreateModel(
16 - name='Device',
17 - fields=[
18 - ('rfid_id', models.CharField(max_length=255, primary_key=True, serialize=False)),
19 - ('created', models.DateTimeField(default=django.utils.timezone.now)),
20 - ],
21 - ),
22 - migrations.CreateModel(
23 - name='Door',
24 - fields=[
25 - ('door_id', models.CharField(max_length=255, primary_key=True, serialize=False)),
26 - ],
27 - ),
28 - migrations.CreateModel(
29 - name='History',
30 - fields=[
31 - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
32 - ('device_name', models.CharField(max_length=255)),
33 - ('ctrtime', models.DateTimeField(default=django.utils.timezone.now)),
34 - ],
35 - ),
36 - migrations.CreateModel(
37 - name='Lock',
38 - fields=[
39 - ('id', models.IntegerField(primary_key=True, serialize=False)),
40 - ('state', models.BooleanField(default=True)),
41 - ],
42 - ),
43 - migrations.CreateModel(
44 - name='Record',
45 - fields=[
46 - ('id', models.IntegerField(primary_key=True, serialize=False)),
47 - ('recording', models.BooleanField(default=True)),
48 - ],
49 - ),
50 - migrations.CreateModel(
51 - name='Video',
52 - fields=[
53 - ('vid_name', models.CharField(max_length=255, primary_key=True, serialize=False)),
54 - ('created', models.DateTimeField(default=django.utils.timezone.now)),
55 - ],
56 - ),
57 - ]
...@@ -13,6 +13,7 @@ class Device(models.Model) : ...@@ -13,6 +13,7 @@ class Device(models.Model) :
13 class Video(models.Model) : 13 class Video(models.Model) :
14 vid_name = models.CharField(max_length = 255, primary_key = True) 14 vid_name = models.CharField(max_length = 255, primary_key = True)
15 created = models.DateTimeField(default = timezone.now) 15 created = models.DateTimeField(default = timezone.now)
16 + vid_time = models.CharField(max_length = 255)
16 thumb = models.CharField(max_length = 255) 17 thumb = models.CharField(max_length = 255)
17 18
18 class Lock(models.Model) : 19 class Lock(models.Model) :
......
...@@ -34,10 +34,14 @@ def record() : ...@@ -34,10 +34,14 @@ def record() :
34 # take a video 34 # take a video
35 camera.resolution = [320, 240] 35 camera.resolution = [320, 240]
36 camera.start_preview() 36 camera.start_preview()
37 +
37 now = datetime.datetime.now() 38 now = datetime.datetime.now()
39 + start_time = time.time()
40 +
38 vid_name = now.strftime('%Y%m%d-%H%M%S') 41 vid_name = now.strftime('%Y%m%d-%H%M%S')
39 vid_path = path + '/' + vid_name + '.h264' 42 vid_path = path + '/' + vid_name + '.h264'
40 thumbnail_path = path + '/' + vid_name + '.jpg' 43 thumbnail_path = path + '/' + vid_name + '.jpg'
44 +
41 camera.start_recording(output=vid_path) 45 camera.start_recording(output=vid_path)
42 time.sleep(1) 46 time.sleep(1)
43 camera.capture(thumbnail_path) 47 camera.capture(thumbnail_path)
...@@ -47,6 +51,9 @@ def record() : ...@@ -47,6 +51,9 @@ def record() :
47 camera.stop_recording() 51 camera.stop_recording()
48 camera.stop_preview() 52 camera.stop_preview()
49 53
54 + rec_time = time.time() - start_time
55 + vid_time = rec_time.strftime("%H:%M:%S")
56 +
50 # s3 upload 57 # s3 upload
51 ''' 58 '''
52 s3 = boto3.client('s3', region_name = 'ap-northeast-2') 59 s3 = boto3.client('s3', region_name = 'ap-northeast-2')
...@@ -56,7 +63,8 @@ def record() : ...@@ -56,7 +63,8 @@ def record() :
56 uploadVideo = {} 63 uploadVideo = {}
57 uploadVideo['vid_name'] = vid_name 64 uploadVideo['vid_name'] = vid_name
58 uploadVideo['created'] = now 65 uploadVideo['created'] = now
59 - uploadVideo['thumb'] = 'http://' + S3_STORAGE_BUCKET_NAME + 's3.ap-northeast-2.amazonaws.com/' + vid_name + '_thumb' 66 + uploadVideo['vid_time'] = vid_time
67 + uploadVideo['thumb'] = S3_ACCESS_URL + vid_name + '_thumb'
60 serializer = VideoSerializer(data = uploadVideo) 68 serializer = VideoSerializer(data = uploadVideo)
61 serializer.save() 69 serializer.save()
62 ''' 70 '''
......
...@@ -64,7 +64,7 @@ class VideoDownload(APIView) : ...@@ -64,7 +64,7 @@ class VideoDownload(APIView) :
64 if not download_url : 64 if not download_url :
65 raise ObjectDoesNotExist 65 raise ObjectDoesNotExist
66 res = { 66 res = {
67 - 's3_link' : download_url 67 + 's3link' : download_url
68 } # 응답 코드에 보낼 데이터 68 } # 응답 코드에 보낼 데이터
69 return Response(res, status = status.HTTP_200_OK) 69 return Response(res, status = status.HTTP_200_OK)
70 except FieldDoesNotExist as error : 70 except FieldDoesNotExist as error :
......