Spaces:
Configuration error
Configuration error
Update app_rvc.py
Browse files- app_rvc.py +23 -25
app_rvc.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
import logging
|
4 |
os.system("pip install -q piper-tts==1.2.0")
|
5 |
os.system("pip install -q -r requirements_xtts.txt")
|
@@ -128,7 +129,6 @@ directories = [
|
|
128 |
if not os.path.exists(directory)
|
129 |
]
|
130 |
|
131 |
-
logging.basicConfig(level=logging.DEBUG)
|
132 |
logger = logging.getLogger(__name__)
|
133 |
|
134 |
class TTS_Info:
|
@@ -284,7 +284,7 @@ def check_openai_api_key():
|
|
284 |
"translation process in Advanced settings."
|
285 |
)
|
286 |
|
287 |
-
def download_and_adjust_youtube_video(url
|
288 |
# Create the 'downloaded' folder if it doesn't exist
|
289 |
os.makedirs("downloaded", exist_ok=True)
|
290 |
|
@@ -299,35 +299,33 @@ def download_and_adjust_youtube_video(url: str, speed_factor: float, start_time:
|
|
299 |
info = ydl.extract_info(url, download=True)
|
300 |
filename = ydl.prepare_filename(info)
|
301 |
|
302 |
-
|
303 |
-
try:
|
304 |
-
with VideoFileClip(filename) as video:
|
305 |
-
logger.debug(f"Original video FPS: {video.fps}")
|
306 |
-
logger.debug(f"Original video duration: {video.duration}")
|
307 |
|
308 |
-
|
309 |
-
|
310 |
-
video = video.set_fps(30.0)
|
311 |
-
logger.warning(f"Original video FPS is None. Setting to default: {video.fps}")
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
video = video.subclip(start_time, end_time)
|
316 |
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
logger.debug(f"Adjusted video FPS: {adjusted_video.fps}")
|
321 |
-
logger.debug(f"Adjusted video duration: {adjusted_video.duration}")
|
322 |
|
323 |
-
|
324 |
-
|
|
|
325 |
|
326 |
-
|
327 |
-
|
328 |
|
329 |
-
|
330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
raise
|
332 |
|
333 |
return output_filename
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
import subprocess
|
4 |
import logging
|
5 |
os.system("pip install -q piper-tts==1.2.0")
|
6 |
os.system("pip install -q -r requirements_xtts.txt")
|
|
|
129 |
if not os.path.exists(directory)
|
130 |
]
|
131 |
|
|
|
132 |
logger = logging.getLogger(__name__)
|
133 |
|
134 |
class TTS_Info:
|
|
|
284 |
"translation process in Advanced settings."
|
285 |
)
|
286 |
|
287 |
+
def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_time=None):
|
288 |
# Create the 'downloaded' folder if it doesn't exist
|
289 |
os.makedirs("downloaded", exist_ok=True)
|
290 |
|
|
|
299 |
info = ydl.extract_info(url, download=True)
|
300 |
filename = ydl.prepare_filename(info)
|
301 |
|
302 |
+
logger.info(f"Downloaded video: {filename}")
|
|
|
|
|
|
|
|
|
303 |
|
304 |
+
# Generate output filename
|
305 |
+
output_filename = f"downloaded/{os.path.splitext(os.path.basename(filename))[0]}_speed{speed_factor}.mp4"
|
|
|
|
|
306 |
|
307 |
+
# Prepare FFmpeg command
|
308 |
+
ffmpeg_cmd = ['ffmpeg', '-i', filename]
|
|
|
309 |
|
310 |
+
# Add trim options if start_time and end_time are provided
|
311 |
+
if start_time is not None and end_time is not None:
|
312 |
+
ffmpeg_cmd.extend(['-ss', str(start_time), '-to', str(end_time)])
|
|
|
|
|
313 |
|
314 |
+
# Add speed adjustment
|
315 |
+
filter_complex = f"[0:v]setpts={1/speed_factor}*PTS[v];[0:a]atempo={speed_factor}[a]"
|
316 |
+
ffmpeg_cmd.extend(['-filter_complex', filter_complex, '-map', '[v]', '-map', '[a]'])
|
317 |
|
318 |
+
# Output options
|
319 |
+
ffmpeg_cmd.extend(['-c:v', 'libx264', '-c:a', 'aac', '-y', output_filename])
|
320 |
|
321 |
+
# Run FFmpeg command
|
322 |
+
try:
|
323 |
+
logger.info(f"Running FFmpeg command: {' '.join(ffmpeg_cmd)}")
|
324 |
+
subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
|
325 |
+
logger.info(f"Video processing completed: {output_filename}")
|
326 |
+
except subprocess.CalledProcessError as e:
|
327 |
+
logger.error(f"Error processing video: {e}")
|
328 |
+
logger.error(f"FFmpeg stderr: {e.stderr}")
|
329 |
raise
|
330 |
|
331 |
return output_filename
|