Saqib commited on
Commit
512d231
1 Parent(s): 38db37d

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +17 -12
modules/app.py CHANGED
@@ -104,24 +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 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
 
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
+ # Get the resolution of the first video
110
+ probe = ffmpeg.probe(temp_video_paths[0])
111
+ video_info = next(stream for stream in probe['streams'] if stream['codec_type'] == 'video')
112
+ width = video_info['width']
113
+ height = video_info['height']
114
 
115
+ # Process videos: separate audio and video, then resize videos
116
+ video_and_audio_files = []
117
  for path in temp_video_paths:
118
+ video = ffmpeg.input(path).video.filter('scale', width, height)
119
  audio = ffmpeg.input(path).audio
120
+ video_and_audio_files.extend([video, audio])
121
+
122
+ # Concatenate all videos and audios
123
+ joined = ffmpeg.concat(*video_and_audio_files, v=1, a=1).node
124
 
125
+ # Generate a unique filename for the output
126
+ output_filename = f"{uuid.uuid4()}.mp4"
127
+ output_path = os.path.join(OUTPUT_DIR, output_filename)
128
 
129
+ # Merge video and audio into the output file
130
  ffmpeg.output(joined[0], joined[1], output_path, vcodec='libx264', acodec='aac').run()
131
 
132
  # Clean up temporary files