최지우

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

# Generated by Django 3.1.2 on 2020-11-13 10:30
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Device',
fields=[
('rfid_id', models.CharField(max_length=255, primary_key=True, serialize=False)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
],
),
migrations.CreateModel(
name='Door',
fields=[
('door_id', models.CharField(max_length=255, primary_key=True, serialize=False)),
],
),
migrations.CreateModel(
name='History',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('device_name', models.CharField(max_length=255)),
('ctrtime', models.DateTimeField(default=django.utils.timezone.now)),
],
),
migrations.CreateModel(
name='Lock',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
('state', models.BooleanField(default=True)),
],
),
migrations.CreateModel(
name='Record',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
('recording', models.BooleanField(default=True)),
],
),
migrations.CreateModel(
name='Video',
fields=[
('vid_name', models.CharField(max_length=255, primary_key=True, serialize=False)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
],
),
]
......@@ -13,6 +13,7 @@ class Device(models.Model) :
class Video(models.Model) :
vid_name = models.CharField(max_length = 255, primary_key = True)
created = models.DateTimeField(default = timezone.now)
vid_time = models.CharField(max_length = 255)
thumb = models.CharField(max_length = 255)
class Lock(models.Model) :
......
......@@ -34,10 +34,14 @@ def record() :
# take a video
camera.resolution = [320, 240]
camera.start_preview()
now = datetime.datetime.now()
start_time = time.time()
vid_name = now.strftime('%Y%m%d-%H%M%S')
vid_path = path + '/' + vid_name + '.h264'
thumbnail_path = path + '/' + vid_name + '.jpg'
camera.start_recording(output=vid_path)
time.sleep(1)
camera.capture(thumbnail_path)
......@@ -47,6 +51,9 @@ def record() :
camera.stop_recording()
camera.stop_preview()
rec_time = time.time() - start_time
vid_time = rec_time.strftime("%H:%M:%S")
# s3 upload
'''
s3 = boto3.client('s3', region_name = 'ap-northeast-2')
......@@ -56,7 +63,8 @@ def record() :
uploadVideo = {}
uploadVideo['vid_name'] = vid_name
uploadVideo['created'] = now
uploadVideo['thumb'] = 'http://' + S3_STORAGE_BUCKET_NAME + 's3.ap-northeast-2.amazonaws.com/' + vid_name + '_thumb'
uploadVideo['vid_time'] = vid_time
uploadVideo['thumb'] = S3_ACCESS_URL + vid_name + '_thumb'
serializer = VideoSerializer(data = uploadVideo)
serializer.save()
'''
......
......@@ -64,7 +64,7 @@ class VideoDownload(APIView) :
if not download_url :
raise ObjectDoesNotExist
res = {
's3_link' : download_url
's3link' : download_url
} # 응답 코드에 보낼 데이터
return Response(res, status = status.HTTP_200_OK)
except FieldDoesNotExist as error :
......