Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import cv2
|
4 |
import os
|
@@ -7,9 +6,17 @@ from PIL import Image, ImageOps
|
|
7 |
from datetime import datetime
|
8 |
import hashlib
|
9 |
import shutil
|
|
|
10 |
|
11 |
TEMP_CACHE = None
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
def procesar_video(video_path):
|
14 |
try:
|
15 |
original_name = os.path.basename(video_path)
|
@@ -22,20 +29,20 @@ def procesar_video(video_path):
|
|
22 |
os.makedirs(temp_dir, exist_ok=True)
|
23 |
|
24 |
cap = cv2.VideoCapture(video_path)
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
img.save(img_path)
|
35 |
-
frame_paths.append(img_path)
|
36 |
-
frame_count += 1
|
37 |
cap.release()
|
38 |
|
|
|
|
|
|
|
39 |
if frame_count == 0:
|
40 |
raise gr.Error("No se pudieron extraer fotogramas del video")
|
41 |
|
@@ -114,9 +121,7 @@ def limpiar_cache():
|
|
114 |
|
115 |
with gr.Blocks(title="Extractor Forense de Fotogramas") as demo:
|
116 |
gr.Markdown("# 📷 Extractor Forense de Fotogramas de Videos")
|
117 |
-
gr.Markdown("""
|
118 |
-
**Herramienta certificada para extracción forense de fotogramas de videos** (No se guarda ninguna información).
|
119 |
-
""")
|
120 |
gr.Markdown("Desarrollado por José R. Leonett para el Grupo de Peritos Forenses Digitales de Guatemala - [www.forensedigital.gt](https://www.forensedigital.gt)")
|
121 |
|
122 |
with gr.Row():
|
@@ -125,7 +130,7 @@ with gr.Blocks(title="Extractor Forense de Fotogramas") as demo:
|
|
125 |
label="🎞️ VIDEO CARGADO",
|
126 |
format="mp4",
|
127 |
interactive=True,
|
128 |
-
height=
|
129 |
sources=["upload"]
|
130 |
)
|
131 |
procesar_btn = gr.Button("🔍 INICIAR ANÁLISIS", interactive=False)
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import os
|
|
|
6 |
from datetime import datetime
|
7 |
import hashlib
|
8 |
import shutil
|
9 |
+
from concurrent.futures import ThreadPoolExecutor
|
10 |
|
11 |
TEMP_CACHE = None
|
12 |
|
13 |
+
def guardar_frame(frame, index, temp_dir):
|
14 |
+
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
15 |
+
img = Image.fromarray(frame_rgb)
|
16 |
+
img_path = os.path.join(temp_dir, f"frame_{index:04d}.jpg")
|
17 |
+
img.save(img_path)
|
18 |
+
return img_path
|
19 |
+
|
20 |
def procesar_video(video_path):
|
21 |
try:
|
22 |
original_name = os.path.basename(video_path)
|
|
|
29 |
os.makedirs(temp_dir, exist_ok=True)
|
30 |
|
31 |
cap = cv2.VideoCapture(video_path)
|
32 |
+
index = 0
|
33 |
+
futures = []
|
34 |
+
with ThreadPoolExecutor(max_workers=4) as executor:
|
35 |
+
while True:
|
36 |
+
ret, frame = cap.read()
|
37 |
+
if not ret:
|
38 |
+
break
|
39 |
+
futures.append(executor.submit(guardar_frame, frame, index, temp_dir))
|
40 |
+
index += 1
|
|
|
|
|
|
|
41 |
cap.release()
|
42 |
|
43 |
+
frame_paths = [f.result() for f in futures]
|
44 |
+
frame_count = len(frame_paths)
|
45 |
+
|
46 |
if frame_count == 0:
|
47 |
raise gr.Error("No se pudieron extraer fotogramas del video")
|
48 |
|
|
|
121 |
|
122 |
with gr.Blocks(title="Extractor Forense de Fotogramas") as demo:
|
123 |
gr.Markdown("# 📷 Extractor Forense de Fotogramas de Videos")
|
124 |
+
gr.Markdown("""**Herramienta certificada para extracción forense de fotogramas de videos** (No se guarda ninguna información).""")
|
|
|
|
|
125 |
gr.Markdown("Desarrollado por José R. Leonett para el Grupo de Peritos Forenses Digitales de Guatemala - [www.forensedigital.gt](https://www.forensedigital.gt)")
|
126 |
|
127 |
with gr.Row():
|
|
|
130 |
label="🎞️ VIDEO CARGADO",
|
131 |
format="mp4",
|
132 |
interactive=True,
|
133 |
+
height=480,
|
134 |
sources=["upload"]
|
135 |
)
|
136 |
procesar_btn = gr.Button("🔍 INICIAR ANÁLISIS", interactive=False)
|