김유현

Change video format

......@@ -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) + '.h264')
s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(target.vid_name) + '.mp4')
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) + '.h264' # S3 다운로드 링크 변환
download_url = S3_ACCESS_URL + str(request_id) + '.mp4' # S3 다운로드 링크 변환
if not download_url :
raise ObjectDoesNotExist
res = {
......
......@@ -5,7 +5,7 @@ import time
import datetime
import django
import sys
import json
import subprocess
sys.path.append('/home/pi/Desktop/smartdoorlock-backend')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'src.settings')
......@@ -49,10 +49,12 @@ def record() :
start_time = time.time()
vid_name = now.strftime('%Y%m%d-%H%M%S')
vid_path = path + '/' + vid_name + '.h264'
vid_path = path + '/' + vid_name
h264_vid_path = vid_path + '.h264'
mp4_vid_path = vid_path + '.h264'
thumbnail_path = path + '/' + vid_name + '.jpg'
camera.start_recording(output=vid_path)
camera.start_recording(output=h264_vid_path)
time.sleep(1)
camera.capture(thumbnail_path)
while GPIO.input(pir_pin) :
......@@ -60,12 +62,14 @@ def record() :
time.sleep(2)
camera.stop_recording()
camera.stop_preview()
result = subprocess.check_output("MP4Box -add {} {}".format(h264_vid_path, mp4_vid_path), shell=True)
print(result)
vid_time = time.strftime("%M:%S", time.gmtime(time.time()-start_time))
# s3 upload
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 = 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 = {}
......