-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo_splitting_cmdline.py
More file actions
57 lines (45 loc) · 1.74 KB
/
Copy pathvideo_splitting_cmdline.py
File metadata and controls
57 lines (45 loc) · 1.74 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#__copyright__ = "Copyright 2024, VISA Lab"
#__license__ = "MIT"
import os
import subprocess
import math
import boto3
# bucket information
input_bucket_name = '1225248297-input'
output_bucket_name = '1225248297-stage-1'
# s3 client
s3 = boto3.client('s3')
# function to upload files to bucket
def upload_directory(local_path, bucket_name):
for root, dirs, files in os.walk(local_path):
for file in files:
local_file_path = os.path.join(root, file)
s3_key = os.path.relpath(local_file_path, local_path)
s3_path = os.path.join(local_path.split('/')[-1], s3_key)
s3.upload_file(local_file_path, bucket_name, s3_path)
def video_splitting_cmdline(video_filename):
# Downloading a csv file
# from S3 bucket to local folder
local_filename = "/tmp/"+ video_filename
s3.download_file(
Filename=local_filename,
Bucket=input_bucket_name,
Key=video_filename
)
filename = os.path.basename(video_filename)
outdir = os.path.splitext(filename)[0]
outdir = os.path.join("/tmp",outdir)
output_dir = outdir
if not os.path.exists(outdir):
os.makedirs(outdir)
split_cmd = '/opt/bin/ffmpeg -ss 0 -r 1 -i ' +local_filename+ ' -vf fps=1 -start_number 0 -vframes 10 ' + outdir + "/" + 'output-%02d.jpg -y'
try:
subprocess.check_call(split_cmd, shell=True)
except subprocess.CalledProcessError as e:
print(e.returncode)
print(e.output)
fps_cmd = 'ffmpeg -i ' + local_filename + ' 2>&1 | sed -n "s/.*, \\(.*\\) fp.*/\\1/p"'
fps = subprocess.check_output(fps_cmd, shell=True).decode("utf-8").rstrip("\n")
fps = math.ceil(float(fps))
upload_directory(outdir, output_bucket_name)
return outdir