KingNish commited on
Commit
53b43b7
·
verified ·
1 Parent(s): 06d6963

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -11
app.py CHANGED
@@ -27,21 +27,12 @@ def save_media_and_get_path(media, media_type):
27
  raise ValueError(f"No {media_type} provided.")
28
 
29
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
30
- filename = f"{media_type}_{timestamp}.{'png' if media_type == 'image' else 'mp4'}"
31
 
32
  if media_type == "image":
33
  media.save(filename)
34
  elif media_type == "video":
35
- # Using FFmpeg for faster video saving (optional)
36
- command = [
37
- "ffmpeg",
38
- "-i", media, # Input video path
39
- "-c:v", "libx264", # Use H.264 codec
40
- "-preset", "fast", # Optimize for speed
41
- "-crf", "23", # Control quality (lower value = higher quality)
42
- filename, # Output filename
43
- ]
44
- subprocess.run(command, check=True)
45
  return os.path.abspath(filename)
46
 
47
 
 
27
  raise ValueError(f"No {media_type} provided.")
28
 
29
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
30
+ filename = f"{media_type}_{timestamp}.{'png' if media_type == 'image' else 'webm'}"
31
 
32
  if media_type == "image":
33
  media.save(filename)
34
  elif media_type == "video":
35
+ VideoFileClip(media).write_videofile(filename, fps=8, audio=False)
 
 
 
 
 
 
 
 
 
36
  return os.path.abspath(filename)
37
 
38