test-rtechs commited on
Commit
dcffef5
·
verified ·
1 Parent(s): f209a53

Update app_rvc.py

Browse files
Files changed (1) hide show
  1. app_rvc.py +12 -11
app_rvc.py CHANGED
@@ -296,8 +296,15 @@ def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_ti
296
  info = ydl.extract_info(url, download=True)
297
  filename = ydl.prepare_filename(info)
298
 
299
- # Load the video and adjust speed
300
  video = VideoFileClip(filename)
 
 
 
 
 
 
 
301
 
302
  # Trim the video if start_time and end_time are provided
303
  if start_time is not None and end_time is not None:
@@ -305,22 +312,16 @@ def download_and_adjust_youtube_video(url, speed_factor, start_time=None, end_ti
305
 
306
  # Adjust speed
307
  adjusted_video = video.speedx(speed_factor)
 
 
 
308
 
309
  # Generate output filename
310
  output_filename = f"downloaded/{os.path.splitext(os.path.basename(filename))[0]}_speed{speed_factor}.mp4"
311
 
312
- # Get the original fps, or use a default value if it's None
313
- fps = video.fps
314
- if fps is None or fps <= 0:
315
- fps = 30 # Default to 30 fps if the original fps is not available or invalid
316
- logger.warning(f"Original video FPS not detected or invalid. Using default value of {fps}")
317
-
318
- # Ensure fps is a float
319
- fps = float(fps)
320
-
321
  # Write the adjusted video
322
  try:
323
- adjusted_video.write_videofile(output_filename, fps=fps)
324
  except Exception as e:
325
  logger.error(f"Error writing video file: {str(e)}")
326
  raise
 
296
  info = ydl.extract_info(url, download=True)
297
  filename = ydl.prepare_filename(info)
298
 
299
+ # Load the video
300
  video = VideoFileClip(filename)
301
+ logger.debug(f"Original video FPS: {video.fps}")
302
+ logger.debug(f"Original video duration: {video.duration}")
303
+
304
+ # Set a default fps if it's None
305
+ if video.fps is None:
306
+ video.fps = 30.0
307
+ logger.warning(f"Original video FPS is None. Setting to default: {video.fps}")
308
 
309
  # Trim the video if start_time and end_time are provided
310
  if start_time is not None and end_time is not None:
 
312
 
313
  # Adjust speed
314
  adjusted_video = video.speedx(speed_factor)
315
+ adjusted_video.fps = video.fps # Ensure the adjusted video has the same fps
316
+ logger.debug(f"Adjusted video FPS: {adjusted_video.fps}")
317
+ logger.debug(f"Adjusted video duration: {adjusted_video.duration}")
318
 
319
  # Generate output filename
320
  output_filename = f"downloaded/{os.path.splitext(os.path.basename(filename))[0]}_speed{speed_factor}.mp4"
321
 
 
 
 
 
 
 
 
 
 
322
  # Write the adjusted video
323
  try:
324
+ adjusted_video.write_videofile(output_filename, fps=adjusted_video.fps)
325
  except Exception as e:
326
  logger.error(f"Error writing video file: {str(e)}")
327
  raise