Showing
2 changed files
with
18 additions
and
36 deletions
... | @@ -210,7 +210,7 @@ class VideoList(APIView) : | ... | @@ -210,7 +210,7 @@ class VideoList(APIView) : |
210 | s3 = session.client('s3') | 210 | s3 = session.client('s3') |
211 | 211 | ||
212 | target = Video.objects.get(vid_name = request_id) | 212 | target = Video.objects.get(vid_name = request_id) |
213 | - s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(target.vid_name) + '.mp4') | 213 | + s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(target.vid_name) + '.h264') |
214 | s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(target.vid_name) + '_thumb.jpg') | 214 | s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(target.vid_name) + '_thumb.jpg') |
215 | target.delete() | 215 | target.delete() |
216 | return Response(status = status.HTTP_200_OK) | 216 | return Response(status = status.HTTP_200_OK) |
... | @@ -227,7 +227,7 @@ class VideoDownload(APIView) : | ... | @@ -227,7 +227,7 @@ class VideoDownload(APIView) : |
227 | request_id = vid_name | 227 | request_id = vid_name |
228 | if request_id == 'None' : | 228 | if request_id == 'None' : |
229 | raise FieldDoesNotExist | 229 | raise FieldDoesNotExist |
230 | - download_url = S3_ACCESS_URL + str(request_id) + '.mp4' # S3 다운로드 링크 변환 | 230 | + download_url = S3_ACCESS_URL + str(request_id) + '.h264' # S3 다운로드 링크 변환 |
231 | if not download_url : | 231 | if not download_url : |
232 | raise ObjectDoesNotExist | 232 | raise ObjectDoesNotExist |
233 | res = { | 233 | res = { | ... | ... |
... | @@ -21,17 +21,6 @@ from picamera import PiCamera | ... | @@ -21,17 +21,6 @@ from picamera import PiCamera |
21 | 21 | ||
22 | 22 | ||
23 | 23 | ||
24 | -def get_secret(): | ||
25 | - file_path = "/home/pi/Desktop/smartdoorlock-backend/.aws_key.json" | ||
26 | - if os.path.exists(file_path): | ||
27 | - with open(file_path) as fp: | ||
28 | - secret_file = json.load(fp)['aws'] | ||
29 | - access_key_id = secret_file.get('access_key_id', None) | ||
30 | - secret_access_key = secret_file.get('secret_access_key', None) | ||
31 | - return (access_key_id, secret_access_key) | ||
32 | - else: | ||
33 | - return False | ||
34 | - | ||
35 | def record() : | 24 | def record() : |
36 | path = '/home/pi/recorded' # save path | 25 | path = '/home/pi/recorded' # save path |
37 | 26 | ||
... | @@ -60,7 +49,7 @@ def record() : | ... | @@ -60,7 +49,7 @@ def record() : |
60 | start_time = time.time() | 49 | start_time = time.time() |
61 | 50 | ||
62 | vid_name = now.strftime('%Y%m%d-%H%M%S') | 51 | vid_name = now.strftime('%Y%m%d-%H%M%S') |
63 | - vid_path = path + '/' + vid_name + '.mp4' | 52 | + vid_path = path + '/' + vid_name + '.h264' |
64 | thumbnail_path = path + '/' + vid_name + '.jpg' | 53 | thumbnail_path = path + '/' + vid_name + '.jpg' |
65 | 54 | ||
66 | camera.start_recording(output=vid_path) | 55 | camera.start_recording(output=vid_path) |
... | @@ -75,28 +64,21 @@ def record() : | ... | @@ -75,28 +64,21 @@ def record() : |
75 | vid_time = time.strftime("%M:%S", time.gmtime(time.time()-start_time)) | 64 | vid_time = time.strftime("%M:%S", time.gmtime(time.time()-start_time)) |
76 | 65 | ||
77 | # s3 upload | 66 | # s3 upload |
78 | - secret = get_secret() | 67 | + 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) |
79 | - if not secret: | 68 | + s3.upload_file(Filename = vid_path, Bucket = S3_STORAGE_BUCKET_NAME, Key = vid_name + '.h264') |
80 | - print(vid_path, "upload failed") | 69 | + s3.upload_file(Filename = thumbnail_path, Bucket = S3_STORAGE_BUCKET_NAME, Key = vid_name + '_thumb.jpg') |
81 | - print("please make credential file") | 70 | + |
82 | - exit(0) | 71 | + uploadVideo = {} |
83 | - else: | 72 | + uploadVideo['vid_name'] = vid_name |
84 | - ACCESS_KEY, SECRET_KEY = secret | 73 | + uploadVideo['created'] = now |
85 | - s3 = boto3.client('s3', region_name = 'ap-northeast-2', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY) | 74 | + uploadVideo['vid_time'] = vid_time |
86 | - s3.upload_file(Filename = vid_path, Bucket = S3_STORAGE_BUCKET_NAME, Key = vid_name + '.mp4') | 75 | + uploadVideo['thumb'] = S3_ACCESS_URL + vid_name + '_thumb.jpg' |
87 | - s3.upload_file(Filename = thumbnail_path, Bucket = S3_STORAGE_BUCKET_NAME, Key = vid_name + '_thumb.jpg') | 76 | + serializer = VideoSerializer(data = uploadVideo) |
88 | - | 77 | + serializer.is_valid() |
89 | - uploadVideo = {} | 78 | + serializer.save() |
90 | - uploadVideo['vid_name'] = vid_name | 79 | + print(vid_path, "upload success") |
91 | - uploadVideo['created'] = now | 80 | + os.remove(vid_path) |
92 | - uploadVideo['vid_time'] = vid_time | 81 | + os.remove(thumbnail_path) |
93 | - uploadVideo['thumb'] = S3_ACCESS_URL + vid_name + '_thumb.jpg' | ||
94 | - serializer = VideoSerializer(data = uploadVideo) | ||
95 | - serializer.is_valid() | ||
96 | - serializer.save() | ||
97 | - print(vid_path, "upload success") | ||
98 | - os.remove(vid_path) | ||
99 | - os.remove(thumbnail_path) | ||
100 | else: | 82 | else: |
101 | camera.stop_preview() | 83 | camera.stop_preview() |
102 | except KeyboardInterrupt: | 84 | except KeyboardInterrupt: | ... | ... |
-
Please register or login to post a comment