Spaces:
Running
on
Zero
Running
on
Zero
Update infer.py
Browse files
infer.py
CHANGED
|
@@ -36,9 +36,14 @@ def infer_video(video_filepath: str, size_modifier: int) -> str:
|
|
| 36 |
vid_output = tmpfile.name
|
| 37 |
tmpfile.close()
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
vid_writer = cv.VideoWriter(
|
| 44 |
vid_output,
|
|
@@ -66,12 +71,13 @@ def infer_video(video_filepath: str, size_modifier: int) -> str:
|
|
| 66 |
|
| 67 |
vid_writer.release()
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
print(f"Video file : {video_filepath}")
|
| 76 |
|
| 77 |
-
return vid_output.replace(".mp4", "_upscaled.mp4")
|
|
|
|
| 36 |
vid_output = tmpfile.name
|
| 37 |
tmpfile.close()
|
| 38 |
|
| 39 |
+
# Check if the input video has an audio stream
|
| 40 |
+
probe = ffmpeg.probe(video_filepath)
|
| 41 |
+
has_audio = any(stream['codec_type'] == 'audio' for stream in probe['streams'])
|
| 42 |
+
|
| 43 |
+
if has_audio:
|
| 44 |
+
# Extract audio from the input video
|
| 45 |
+
audio_file = video_filepath.replace(".mp4", ".wav")
|
| 46 |
+
ffmpeg.input(video_filepath).output(audio_file, format='wav', ac=1).run(overwrite_output=True)
|
| 47 |
|
| 48 |
vid_writer = cv.VideoWriter(
|
| 49 |
vid_output,
|
|
|
|
| 71 |
|
| 72 |
vid_writer.release()
|
| 73 |
|
| 74 |
+
if has_audio:
|
| 75 |
+
# Re-encode the video with the modified audio
|
| 76 |
+
ffmpeg.input(vid_output).output(video_filepath.replace(".mp4", "_upscaled.mp4"), vcodec='libx264', acodec='aac', audio_bitrate='320k').run(overwrite_output=True)
|
| 77 |
|
| 78 |
+
# Replace the original audio with the upscaled audio
|
| 79 |
+
ffmpeg.input(audio_file).output(video_filepath.replace(".mp4", "_upscaled.mp4"), acodec='aac', audio_bitrate='320k').run(overwrite_output=True)
|
| 80 |
|
| 81 |
print(f"Video file : {video_filepath}")
|
| 82 |
|
| 83 |
+
return vid_output.replace(".mp4", "_upscaled.mp4") if has_audio else vid_output
|