Spaces:
Sleeping
Sleeping
Saqib commited on
Update modules/app.py
Browse files- modules/app.py +11 -11
modules/app.py
CHANGED
|
@@ -98,20 +98,20 @@ async def add_audio_to_image(input_data: AudioImageInput):
|
|
| 98 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
|
| 99 |
|
| 100 |
def concatenate_video_audio_clips(clip_names, output_filename):
|
| 101 |
-
|
| 102 |
-
|
| 103 |
|
| 104 |
-
for name in clip_names:
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
concat_audio = ffmpeg.concat(*audio_streams, v=0, a=1)
|
| 112 |
|
| 113 |
-
#
|
| 114 |
-
ffmpeg.output(
|
| 115 |
|
| 116 |
return output_filename
|
| 117 |
|
|
|
|
| 98 |
raise HTTPException(status_code=500, detail=f"An unexpected error occurred: {str(e)}")
|
| 99 |
|
| 100 |
def concatenate_video_audio_clips(clip_names, output_filename):
|
| 101 |
+
inputs = []
|
| 102 |
+
filter_complex = []
|
| 103 |
|
| 104 |
+
for i, name in enumerate(clip_names):
|
| 105 |
+
# For each clip, create separate inputs for video and audio
|
| 106 |
+
inputs.append(ffmpeg.input(name))
|
| 107 |
+
# Create filter_complex entries for concatenating without losing sync
|
| 108 |
+
filter_complex.append(f"[{i}:v][{i}:a]")
|
| 109 |
|
| 110 |
+
# Generate the filter_complex string for concatenating all clips together
|
| 111 |
+
filter_complex_string = "".join(f"{x}concat=n={len(clip_names)}:v=1:a=1[v][a];" for x in filter_complex)[:-1]
|
|
|
|
| 112 |
|
| 113 |
+
# Execute ffmpeg command with complex filter
|
| 114 |
+
ffmpeg.output(inputs, output_filename, vcodec='libx264', acodec='aac', **{'filter_complex': filter_complex_string}).run()
|
| 115 |
|
| 116 |
return output_filename
|
| 117 |
|