mkozak commited on
Commit
a7e2ea5
·
unverified ·
1 Parent(s): be918f3

concatenate files

Browse files
Files changed (2) hide show
  1. list.txt +2 -0
  2. main.py +10 -5
list.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ file '/tmp/genBase.mp3'
2
+ file '/tmp/quote.mp3'
main.py CHANGED
@@ -1,5 +1,6 @@
1
  from fastapi import FastAPI, UploadFile, HTTPException
2
  from ffmpeg import input, output, run
 
3
  import boto3
4
  import os
5
 
@@ -28,9 +29,12 @@ async def merge_audio(output_key: str):
28
  s3_gen_base_key = f'{s3_directory}/genBase.mp3'
29
  s3_quote_key = f'{s3_directory}/quote.mp3'
30
 
 
31
  try:
32
- s3_client.download_file(s3_bucket_name, s3_gen_base_key, gen_base_file)
33
- s3_client.download_file(s3_bucket_name, s3_quote_key, quote_file)
 
 
34
  except Exception as e:
35
  raise HTTPException(status_code=500, detail=f"Failed to download files from S3: {e}")
36
 
@@ -38,11 +42,12 @@ async def merge_audio(output_key: str):
38
  output_file = temp_dir + 'output.mp3'
39
 
40
  # Use python-ffmpeg to merge audio clips
41
- input_args = [input(gen_base_file), input(quote_file)]
42
- output_args = output(output_file, acodec='copy')
 
43
 
44
  try:
45
- run(*input_args, output_args, overwrite_output=True)
46
  except Exception as e:
47
  raise HTTPException(status_code=500, detail=f"FFmpeg Error: {e}")
48
 
 
1
  from fastapi import FastAPI, UploadFile, HTTPException
2
  from ffmpeg import input, output, run
3
+ import ffmpeg
4
  import boto3
5
  import os
6
 
 
29
  s3_gen_base_key = f'{s3_directory}/genBase.mp3'
30
  s3_quote_key = f'{s3_directory}/quote.mp3'
31
 
32
+ input_files = ['genBase.mp3', 'quote.mp3']
33
  try:
34
+ for input_file in input_files:
35
+ s3_object_key = f'{s3_directory}/{input_file}'
36
+ local_file = temp_dir + input_file
37
+ s3_client.download_file(s3_bucket_name, s3_object_key, local_file)
38
  except Exception as e:
39
  raise HTTPException(status_code=500, detail=f"Failed to download files from S3: {e}")
40
 
 
42
  output_file = temp_dir + 'output.mp3'
43
 
44
  # Use python-ffmpeg to merge audio clips
45
+ # input_file_paths = [temp_dir + input_file for input_file in input_files]
46
+ # input_args = [input(file_path) for file_path in input_file_paths]
47
+ input_file = 'list.txt'
48
 
49
  try:
50
+ ffmpeg.input(input_file, format='concat', safe=0).output(output_file, c='copy').run()
51
  except Exception as e:
52
  raise HTTPException(status_code=500, detail=f"FFmpeg Error: {e}")
53