Update app.py
Browse files
app.py
CHANGED
@@ -86,10 +86,13 @@ def extract_frames(video_path, output_folder, fps):
|
|
86 |
f'{output_folder}/frame_%04d.jpg'
|
87 |
]
|
88 |
try:
|
89 |
-
subprocess.run(command, check=True, capture_output=True, text=True)
|
|
|
|
|
90 |
except subprocess.CalledProcessError as e:
|
91 |
print(f"Error extracting frames: {e}")
|
92 |
-
print(f"FFmpeg
|
|
|
93 |
raise
|
94 |
|
95 |
import fractions
|
@@ -111,13 +114,45 @@ def extract_and_align_faces_from_video(video_path, aligned_faces_folder, desired
|
|
111 |
'-of', 'csv=p=0',
|
112 |
video_path
|
113 |
]
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
print(f"Total frames: {frame_count}, Original FPS: {original_fps}, Desired FPS: {desired_fps}")
|
122 |
|
123 |
embeddings_by_frame = {}
|
|
|
86 |
f'{output_folder}/frame_%04d.jpg'
|
87 |
]
|
88 |
try:
|
89 |
+
result = subprocess.run(command, check=True, capture_output=True, text=True)
|
90 |
+
print(f"FFmpeg stdout: {result.stdout}")
|
91 |
+
print(f"FFmpeg stderr: {result.stderr}")
|
92 |
except subprocess.CalledProcessError as e:
|
93 |
print(f"Error extracting frames: {e}")
|
94 |
+
print(f"FFmpeg stdout: {e.stdout}")
|
95 |
+
print(f"FFmpeg stderr: {e.stderr}")
|
96 |
raise
|
97 |
|
98 |
import fractions
|
|
|
114 |
'-of', 'csv=p=0',
|
115 |
video_path
|
116 |
]
|
117 |
+
try:
|
118 |
+
ffprobe_output = subprocess.check_output(ffprobe_command, universal_newlines=True).strip().split(',')
|
119 |
+
print(f"FFprobe output: {ffprobe_output}") # Debugging output
|
120 |
+
|
121 |
+
if len(ffprobe_output) != 2:
|
122 |
+
raise ValueError(f"Unexpected FFprobe output format: {ffprobe_output}")
|
123 |
+
|
124 |
+
frame_count = ffprobe_output[0]
|
125 |
+
frame_rate = ffprobe_output[1]
|
126 |
+
|
127 |
+
print(f"Frame count (raw): {frame_count}") # Debugging output
|
128 |
+
print(f"Frame rate (raw): {frame_rate}") # Debugging output
|
129 |
+
|
130 |
+
# Convert frame count to int
|
131 |
+
try:
|
132 |
+
frame_count = int(frame_count)
|
133 |
+
except ValueError:
|
134 |
+
print(f"Warning: Could not convert frame count '{frame_count}' to int. Using fallback method.")
|
135 |
+
frame_count = len([f for f in os.listdir(frames_folder) if f.endswith('.jpg')])
|
136 |
+
|
137 |
+
# Convert fractional frame rate to float
|
138 |
+
try:
|
139 |
+
frac = fractions.Fraction(frame_rate)
|
140 |
+
original_fps = float(frac.numerator) / float(frac.denominator)
|
141 |
+
except (ValueError, ZeroDivisionError):
|
142 |
+
print(f"Warning: Could not convert frame rate '{frame_rate}' to float. Using fallback method.")
|
143 |
+
# Fallback: Count frames and divide by video duration
|
144 |
+
frame_count = len([f for f in os.listdir(frames_folder) if f.endswith('.jpg')])
|
145 |
+
duration_command = ['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', video_path]
|
146 |
+
duration = float(subprocess.check_output(duration_command, universal_newlines=True).strip())
|
147 |
+
original_fps = frame_count / duration
|
148 |
+
|
149 |
+
except subprocess.CalledProcessError as e:
|
150 |
+
print(f"Error running FFprobe: {e}")
|
151 |
+
raise
|
152 |
+
except Exception as e:
|
153 |
+
print(f"Unexpected error processing video info: {e}")
|
154 |
+
raise
|
155 |
+
|
156 |
print(f"Total frames: {frame_count}, Original FPS: {original_fps}, Desired FPS: {desired_fps}")
|
157 |
|
158 |
embeddings_by_frame = {}
|