Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김유현
2020-11-21 03:49:14 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d7ee8ac6b4ada4e03ab2836d5b8d1adca2377548
d7ee8ac6
1 parent
7589f5db
Refactoring and Change video format
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
36 deletions
api/views.py
videorecord.py
api/views.py
View file @
d7ee8ac
...
...
@@ -210,7 +210,7 @@ class VideoList(APIView) :
s3
=
session
.
client
(
's3'
)
target
=
Video
.
objects
.
get
(
vid_name
=
request_id
)
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
target
.
vid_name
)
+
'.
mp
4'
)
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
target
.
vid_name
)
+
'.
h26
4'
)
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
target
.
vid_name
)
+
'_thumb.jpg'
)
target
.
delete
()
return
Response
(
status
=
status
.
HTTP_200_OK
)
...
...
@@ -227,7 +227,7 @@ class VideoDownload(APIView) :
request_id
=
vid_name
if
request_id
==
'None'
:
raise
FieldDoesNotExist
download_url
=
S3_ACCESS_URL
+
str
(
request_id
)
+
'.
mp
4'
# S3 다운로드 링크 변환
download_url
=
S3_ACCESS_URL
+
str
(
request_id
)
+
'.
h26
4'
# S3 다운로드 링크 변환
if
not
download_url
:
raise
ObjectDoesNotExist
res
=
{
...
...
videorecord.py
View file @
d7ee8ac
...
...
@@ -21,17 +21,6 @@ from picamera import PiCamera
def
get_secret
():
file_path
=
"/home/pi/Desktop/smartdoorlock-backend/.aws_key.json"
if
os
.
path
.
exists
(
file_path
):
with
open
(
file_path
)
as
fp
:
secret_file
=
json
.
load
(
fp
)[
'aws'
]
access_key_id
=
secret_file
.
get
(
'access_key_id'
,
None
)
secret_access_key
=
secret_file
.
get
(
'secret_access_key'
,
None
)
return
(
access_key_id
,
secret_access_key
)
else
:
return
False
def
record
()
:
path
=
'/home/pi/recorded'
# save path
...
...
@@ -60,7 +49,7 @@ def record() :
start_time
=
time
.
time
()
vid_name
=
now
.
strftime
(
'
%
Y
%
m
%
d-
%
H
%
M
%
S'
)
vid_path
=
path
+
'/'
+
vid_name
+
'.
mp
4'
vid_path
=
path
+
'/'
+
vid_name
+
'.
h26
4'
thumbnail_path
=
path
+
'/'
+
vid_name
+
'.jpg'
camera
.
start_recording
(
output
=
vid_path
)
...
...
@@ -75,28 +64,21 @@ def record() :
vid_time
=
time
.
strftime
(
"
%
M:
%
S"
,
time
.
gmtime
(
time
.
time
()
-
start_time
))
# s3 upload
secret
=
get_secret
()
if
not
secret
:
print
(
vid_path
,
"upload failed"
)
print
(
"please make credential file"
)
exit
(
0
)
else
:
ACCESS_KEY
,
SECRET_KEY
=
secret
s3
=
boto3
.
client
(
's3'
,
region_name
=
'ap-northeast-2'
,
aws_access_key_id
=
ACCESS_KEY
,
aws_secret_access_key
=
SECRET_KEY
)
s3
.
upload_file
(
Filename
=
vid_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'.mp4'
)
s3
.
upload_file
(
Filename
=
thumbnail_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'_thumb.jpg'
)
uploadVideo
=
{}
uploadVideo
[
'vid_name'
]
=
vid_name
uploadVideo
[
'created'
]
=
now
uploadVideo
[
'vid_time'
]
=
vid_time
uploadVideo
[
'thumb'
]
=
S3_ACCESS_URL
+
vid_name
+
'_thumb.jpg'
serializer
=
VideoSerializer
(
data
=
uploadVideo
)
serializer
.
is_valid
()
serializer
.
save
()
print
(
vid_path
,
"upload success"
)
os
.
remove
(
vid_path
)
os
.
remove
(
thumbnail_path
)
s3
=
boto3
.
client
(
's3'
,
region_name
=
'ap-northeast-2'
,
aws_access_key_id
=
S3_ACCESS_KEY_ID
,
aws_secret_access_key
=
S3_SECRET_ACCESS_KEY
)
s3
.
upload_file
(
Filename
=
vid_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'.h264'
)
s3
.
upload_file
(
Filename
=
thumbnail_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'_thumb.jpg'
)
uploadVideo
=
{}
uploadVideo
[
'vid_name'
]
=
vid_name
uploadVideo
[
'created'
]
=
now
uploadVideo
[
'vid_time'
]
=
vid_time
uploadVideo
[
'thumb'
]
=
S3_ACCESS_URL
+
vid_name
+
'_thumb.jpg'
serializer
=
VideoSerializer
(
data
=
uploadVideo
)
serializer
.
is_valid
()
serializer
.
save
()
print
(
vid_path
,
"upload success"
)
os
.
remove
(
vid_path
)
os
.
remove
(
thumbnail_path
)
else
:
camera
.
stop_preview
()
except
KeyboardInterrupt
:
...
...
Please
register
or
login
to post a comment