-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend_bucket_s3.py
42 lines (33 loc) · 1.42 KB
/
send_bucket_s3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import subprocess
import boto3
import ffmpeg
from botocore.exceptions import NoCredentialsError
SECRET_KEY = 'ULGn7r0Yy/SvHBK0TPPOXyjSOALZv7T1gP3vY3Ir' # saul
ACCESS_KEY = 'AKIA547RNSAVXOJWAYHC'
BUCKET = "helmet-detection-data"
SOURCE_FILE = "./videos"
# SECRET_KEY = 'tPV7sNZ0x8DRpX8eH/xzHnKkkrCgyDGnUquK9Hu9' # erick
# ACCESS_KEY = 'AKIA4DDPPWB4TC332FTC'
# BUCKET = "ucemineriabucket"
def upload_to_aws(local_file, s3_file, speed):
s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY)
try:
ffmpeg.input(f'{SOURCE_FILE}/{local_file}').setpts(f'{speed}*PTS').output(f'{SOURCE_FILE}/f{local_file}').run()
s3.upload_file(f'{SOURCE_FILE}/f{local_file}', BUCKET, s3_file, ExtraArgs={'ContentType': "video/mp4"})
print("Video enviado a s3::%s" % s3_file)
os.remove(f'{SOURCE_FILE}/{local_file}')
os.remove(f'{SOURCE_FILE}/f{local_file}')
return True
except FileNotFoundError:
print("The file was not found s3::%s" % s3_file)
return False
except NoCredentialsError:
print("Credentials not available")
return False
# def upload_to_one_drive(local_file, s3_file):
# if __name__ == '__main__':
# subprocess.run(['ffmpeg', '-i', './videos/as2844111.mp4', './videos/fas2844111.mp4'])
# upload_to_aws("./videos/fas2844111.mp4", 'ffas2844111.mp4')
# os.remove(["dsf", "fsda"])