-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_format.py
58 lines (43 loc) · 1.66 KB
/
convert_format.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from functools import partial
from pathlib import Path
import ffmpeg
from choirless_lib import create_signed_url
def main(args):
notification = args.get('notification', {})
key = args.get('key', notification.get('object_name', ''))
src_bucket = args['bucket1']
dst_bucket = args['bucket2']
geo = args['geo']
host = args.get('endpoint', args.get('ENDPOINT'))
cos_hmac_keys = args['__bx_creds']['cloud-object-storage']['cos_hmac_keys']
cos_api_key = cos_hmac_keys['access_key_id']
cos_api_secret = cos_hmac_keys['secret_access_key']
get_input_url = partial(create_signed_url,
host,
'GET',
cos_api_key,
cos_api_secret,
geo,
src_bucket)
get_output_url = partial(create_signed_url,
host,
'PUT',
cos_api_key,
cos_api_secret,
geo,
dst_bucket)
output_key = str(Path(key).with_suffix('.wav'))
stream = ffmpeg.input(get_input_url(key),
seekable=0)
audio = stream.audio
audio = audio.filter('volumedetect')
pipeline = ffmpeg.output(audio,
get_output_url(output_key),
format='wav',
method='PUT',
seekable=0,
)
cmd = pipeline.compile()
print("ffmpeg command to run: ", cmd)
pipeline.run()
return {'status': 'ok'}