Spaces:
Sleeping
Sleeping
codecs
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from gradio_client import Client, handle_file
|
|
| 6 |
from mutagen.mp3 import MP3
|
| 7 |
from pydub import AudioSegment
|
| 8 |
from PIL import Image
|
|
|
|
| 9 |
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
| 10 |
from scripts.inference import inference_process
|
| 11 |
import argparse
|
|
@@ -97,6 +98,19 @@ def check_and_convert_webp_to_png(input_path, output_path):
|
|
| 97 |
def clear_audio_elms():
|
| 98 |
return gr.update(value=None, visible=False)
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
#######################################################
|
| 101 |
# Gradio APIs for optional image and voice generation #
|
| 102 |
#######################################################
|
|
@@ -210,8 +224,13 @@ def generate_talking_portrait(portrait, voice, progress=gr.Progress(track_tqdm=T
|
|
| 210 |
|
| 211 |
# Call hallo
|
| 212 |
talking_portrait_vid = run_hallo(portrait, ready_audio)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
-
return
|
| 215 |
|
| 216 |
|
| 217 |
css = '''
|
|
|
|
| 6 |
from mutagen.mp3 import MP3
|
| 7 |
from pydub import AudioSegment
|
| 8 |
from PIL import Image
|
| 9 |
+
import ffmpeg
|
| 10 |
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
| 11 |
from scripts.inference import inference_process
|
| 12 |
import argparse
|
|
|
|
| 98 |
def clear_audio_elms():
|
| 99 |
return gr.update(value=None, visible=False)
|
| 100 |
|
| 101 |
+
def change_video_codec(input_file, output_file, codec='libx264', audio_codec='aac'):
|
| 102 |
+
try:
|
| 103 |
+
(
|
| 104 |
+
ffmpeg
|
| 105 |
+
.input(input_file)
|
| 106 |
+
.output(output_file, vcodec=codec, acodec=audio_codec)
|
| 107 |
+
.run(overwrite_output=True)
|
| 108 |
+
)
|
| 109 |
+
print(f'Successfully changed codec of {input_file} and saved as {output_file}')
|
| 110 |
+
except ffmpeg.Error as e:
|
| 111 |
+
print(f'Error occurred: {e.stderr.decode()}')
|
| 112 |
+
|
| 113 |
+
|
| 114 |
#######################################################
|
| 115 |
# Gradio APIs for optional image and voice generation #
|
| 116 |
#######################################################
|
|
|
|
| 224 |
|
| 225 |
# Call hallo
|
| 226 |
talking_portrait_vid = run_hallo(portrait, ready_audio)
|
| 227 |
+
|
| 228 |
+
# Convert video to readable format
|
| 229 |
+
|
| 230 |
+
final_output_file = f"converted_{talking_portrait_vid}"
|
| 231 |
+
change_video_codec(talking_portrait_vid, output_file)
|
| 232 |
|
| 233 |
+
return final_output_file
|
| 234 |
|
| 235 |
|
| 236 |
css = '''
|