Saqib commited on
Commit
49f4a8c
1 Parent(s): e95feae

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +16 -9
modules/app.py CHANGED
@@ -104,22 +104,29 @@ async def concatenate_videos(input_data: VideosInput):
104
 
105
  # Download videos to temporary files
106
  for video_url in input_data.video_urls:
107
- temp_video_paths.append(await download_file(str(video_url), ".mp4"))
108
 
109
- # Generate a unique filename
110
  output_filename = f"{uuid.uuid4()}.mp4"
111
  output_path = os.path.join(OUTPUT_DIR, output_filename)
112
 
113
- # Concatenate video clips using ffmpeg
114
- inputs = [ffmpeg.input(path) for path in temp_video_paths]
115
- concat_input = ffmpeg.concat(*inputs, v=1, a=1).node
116
- video = concat_input[0]
117
- audio = concat_input[1]
118
- ffmpeg.output(video, audio, output_path, vcodec='libx264', acodec='aac').run()
 
 
 
 
 
 
 
119
 
120
  # Clean up temporary files
121
  for path in temp_video_paths:
122
- os.unlink(path)
123
 
124
  # Return the URL path to the output file
125
  return f"/output/{output_filename}"
 
104
 
105
  # Download videos to temporary files
106
  for video_url in input_data.video_urls:
107
+ temp_video_paths.append(await download_file(video_url, ".mp4"))
108
 
109
+ # Generate a unique filename for the output
110
  output_filename = f"{uuid.uuid4()}.mp4"
111
  output_path = os.path.join(OUTPUT_DIR, output_filename)
112
 
113
+ # Separate video and audio streams
114
+ video_and_audio_streams = []
115
+ for path in temp_video_paths:
116
+ video = ffmpeg.input(path).video
117
+ audio = ffmpeg.input(path).audio
118
+ video_and_audio_streams.append(video)
119
+ video_and_audio_streams.append(audio)
120
+
121
+ # Concatenate video and audio streams
122
+ joined = ffmpeg.concat(*video_and_audio_streams, v=1, a=1).node
123
+
124
+ # Merge video and audio
125
+ ffmpeg.output(joined[0], joined[1], output_path, vcodec='libx264', acodec='aac').run()
126
 
127
  # Clean up temporary files
128
  for path in temp_video_paths:
129
+ os.remove(path)
130
 
131
  # Return the URL path to the output file
132
  return f"/output/{output_filename}"