lucasfiotti commited on
Commit ·
d103d3a
1
Parent(s): 8afa347
Version finale fonctionnelle commentée
Browse files- coquille/Jalon2OPTI.py +229 -70
- coquille/Jalon3.py +16 -13
- coquille/main.py +315 -155
- coquille/static/index.html +25 -15
- coquille/static/main.js +105 -63
- coquille/static/style.css +33 -30
coquille/Jalon2OPTI.py
CHANGED
|
@@ -1,45 +1,66 @@
|
|
| 1 |
import time
|
| 2 |
-
import cv2
|
| 3 |
from mediapipe.tasks import python
|
| 4 |
from mediapipe.tasks.python import vision
|
| 5 |
from mediapipe import Image, ImageFormat
|
| 6 |
-
import numpy as np
|
| 7 |
import urllib.request
|
| 8 |
import csv
|
| 9 |
-
import os
|
| 10 |
-
import sys
|
| 11 |
import subprocess
|
| 12 |
import shutil
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
if len(sys.argv) < 2:
|
| 15 |
print("Usage: python Jalon2OPTI.py <video_file> [nom_personnalise]")
|
| 16 |
sys.exit(1)
|
| 17 |
|
|
|
|
| 18 |
video_path = sys.argv[1]
|
| 19 |
if not os.path.exists(video_path):
|
| 20 |
print(f"Erreur: Le fichier '{video_path}' n'existe pas.")
|
| 21 |
sys.exit(1)
|
| 22 |
|
|
|
|
| 23 |
video_name_with_ext = os.path.basename(video_path)
|
| 24 |
video_ext = os.path.splitext(video_name_with_ext)[1]
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
if len(sys.argv) >= 3 and sys.argv[2].strip():
|
| 27 |
video_name = sys.argv[2].strip()
|
| 28 |
else:
|
| 29 |
video_name = os.path.splitext(video_name_with_ext)[0]
|
| 30 |
|
|
|
|
| 31 |
dossier = os.path.dirname(os.path.abspath(sys.argv[0]))
|
| 32 |
|
|
|
|
| 33 |
output_video_path = os.path.join(dossier, f"./liste/landmarks/{video_name}(landmarks){video_ext}")
|
|
|
|
|
|
|
| 34 |
output_csv_path = os.path.join(dossier, f"./liste/csv/{video_name}.csv")
|
|
|
|
|
|
|
| 35 |
temp_video_path = os.path.join(dossier, f"{video_name}_temp_raw.mp4")
|
|
|
|
|
|
|
| 36 |
output_wav_path = os.path.join(dossier, f"./liste/audio/{video_name}.wav")
|
| 37 |
|
| 38 |
print(f"Vidéo d'entrée : {video_path}")
|
| 39 |
print(f"CSV de sortie : {output_csv_path}")
|
| 40 |
print(f"Vidéo annotée : {output_video_path}")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
model_path = os.path.join(dossier, "face_landmarker.task")
|
|
|
|
|
|
|
| 43 |
if not os.path.exists(model_path):
|
| 44 |
print("Téléchargement du modèle face_landmarker...")
|
| 45 |
urllib.request.urlretrieve(
|
|
@@ -47,28 +68,40 @@ if not os.path.exists(model_path):
|
|
| 47 |
model_path
|
| 48 |
)
|
| 49 |
|
|
|
|
|
|
|
| 50 |
options = vision.FaceLandmarkerOptions(
|
| 51 |
base_options=python.BaseOptions(model_asset_path=model_path),
|
| 52 |
-
running_mode=vision.RunningMode.VIDEO,
|
| 53 |
-
num_faces=1,
|
| 54 |
-
min_face_detection_confidence=0.7,
|
| 55 |
-
min_tracking_confidence=0.5
|
| 56 |
)
|
| 57 |
detector = vision.FaceLandmarker.create_from_options(options)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
|
|
|
|
|
|
|
|
|
| 65 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 66 |
out = cv2.VideoWriter(temp_video_path, fourcc, fps, (frame_width, frame_height))
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
csv_file = open(output_csv_path, "w", newline="", encoding="utf-8")
|
| 69 |
csv_writer = csv.writer(csv_file)
|
| 70 |
csv_writer.writerow(["timestamp", "bouche", "oeil_g", "oeil_d", "pitch", "yaw", "roll", "norm_x", "norm_y"])
|
| 71 |
|
|
|
|
| 72 |
|
| 73 |
def generic_optic(width, height):
|
| 74 |
focal_length = width
|
|
@@ -78,18 +111,31 @@ def generic_optic(width, height):
|
|
| 78 |
|
| 79 |
|
| 80 |
def compute_head_pose(landmarks, frame_w, frame_h):
|
|
|
|
| 81 |
model_points = np.array([
|
| 82 |
-
[0.0,
|
| 83 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
], dtype=np.float64)
|
| 85 |
indices = [1, 152, 33, 263, 61, 291]
|
|
|
|
|
|
|
| 86 |
image_points = np.array([[landmarks[i].x * frame_w, landmarks[i].y * frame_h] for i in indices], dtype=np.float64)
|
| 87 |
camera_matrix, dist_coeffs = generic_optic(frame_w, frame_h)
|
|
|
|
|
|
|
| 88 |
success, rotation_vec, translation_vec = cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs,
|
| 89 |
flags=cv2.SOLVEPNP_ITERATIVE)
|
| 90 |
if not success:
|
| 91 |
return None, None, None, None, None
|
|
|
|
|
|
|
| 92 |
rotation_mat, _ = cv2.Rodrigues(rotation_vec)
|
|
|
|
|
|
|
| 93 |
pose_mat = cv2.hconcat([rotation_mat, translation_vec])
|
| 94 |
_, _, _, _, _, _, euler_angles = cv2.decomposeProjectionMatrix(pose_mat)
|
| 95 |
return euler_angles[0, 0], euler_angles[1, 0], euler_angles[2, 0], rotation_vec, translation_vec
|
|
@@ -100,9 +146,13 @@ def compute_face_position(landmarks, frame_w, frame_h):
|
|
| 100 |
ys = [lm.y for lm in landmarks]
|
| 101 |
x_min, x_max = min(xs), max(xs)
|
| 102 |
y_min, y_max = min(ys), max(ys)
|
|
|
|
|
|
|
| 103 |
center_x = int(((x_min + x_max) / 2) * frame_w)
|
| 104 |
center_y = int(((y_min + y_max) / 2) * frame_h)
|
| 105 |
-
|
|
|
|
|
|
|
| 106 |
norm_y = ((y_min + y_max) / 2 - 0.5) * 2
|
| 107 |
face_w = int((x_max - x_min) * frame_w)
|
| 108 |
face_h = int((y_max - y_min) * frame_h)
|
|
@@ -112,67 +162,134 @@ def compute_face_position(landmarks, frame_w, frame_h):
|
|
| 112 |
|
| 113 |
|
| 114 |
def draw_axes(frame, rotation_vec, translation_vec, camera_matrix, dist_coeffs, origin):
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
projected, _ = cv2.projectPoints(axis_points, rotation_vec, translation_vec, camera_matrix, dist_coeffs)
|
| 117 |
o = (int(origin[0]), int(origin[1]))
|
| 118 |
-
cv2.arrowedLine(frame, o, (int(projected[0][0][0]), int(projected[0][0][1])), (0, 0, 255), 2, tipLength=0.3)
|
| 119 |
-
cv2.arrowedLine(frame, o, (int(projected[1][0][0]), int(projected[1][0][1])), (0, 255, 0), 2, tipLength=0.3)
|
| 120 |
-
cv2.arrowedLine(frame, o, (int(projected[2][0][0]), int(projected[2][0][1])), (255, 0, 0), 2, tipLength=0.3)
|
|
|
|
|
|
|
|
|
|
| 121 |
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
list_timestamp
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
while True:
|
| 128 |
-
ret, frame = cap.read()
|
| 129 |
if not ret:
|
| 130 |
break
|
| 131 |
|
|
|
|
| 132 |
timestamp = frame_index / fps
|
| 133 |
frame_index += 1
|
| 134 |
-
h, w, _ = frame.shape
|
| 135 |
|
|
|
|
| 136 |
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 137 |
mp_image = Image(image_format=ImageFormat.SRGB, data=rgb_frame)
|
|
|
|
|
|
|
| 138 |
results = detector.detect_for_video(mp_image, int(timestamp * 1000))
|
| 139 |
|
| 140 |
-
if results.face_landmarks:
|
| 141 |
-
landmarks = results.face_landmarks[0]
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
| 144 |
right_eye_open = abs(landmarks[386].y - landmarks[374].y)
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
elif list_mouth_open:
|
|
|
|
|
|
|
| 176 |
list_timestamp.append(round(timestamp, 2))
|
| 177 |
list_mouth_open.append(list_mouth_open[-1])
|
| 178 |
list_left_eye_open.append(list_left_eye_open[-1])
|
|
@@ -183,6 +300,8 @@ while True:
|
|
| 183 |
list_norm_x.append(list_norm_x[-1])
|
| 184 |
list_norm_y.append(list_norm_y[-1])
|
| 185 |
else:
|
|
|
|
|
|
|
| 186 |
list_timestamp.append(round(timestamp, 2))
|
| 187 |
list_mouth_open.append(0.0)
|
| 188 |
list_left_eye_open.append(0.0)
|
|
@@ -193,8 +312,10 @@ while True:
|
|
| 193 |
list_norm_x.append(0.0)
|
| 194 |
list_norm_y.append(0.0)
|
| 195 |
|
|
|
|
| 196 |
out.write(frame)
|
| 197 |
|
|
|
|
| 198 |
if not list_mouth_open:
|
| 199 |
print("Erreur : aucun visage détecté.")
|
| 200 |
cap.release()
|
|
@@ -204,36 +325,56 @@ if not list_mouth_open:
|
|
| 204 |
csv_file.close()
|
| 205 |
sys.exit(1)
|
| 206 |
|
|
|
|
| 207 |
|
| 208 |
-
def
|
| 209 |
-
|
|
|
|
|
|
|
| 210 |
|
|
|
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
list_norm_y = norm_list(list_norm_y, min(list_norm_y), max(list_norm_y), -0.0075, 0.0075)
|
| 215 |
-
list_left_eye_open = norm_list(list_left_eye_open, min(list_left_eye_open), max(list_left_eye_open), 0, -50.0)
|
| 216 |
-
list_right_eye_open = norm_list(list_right_eye_open, min(list_right_eye_open), max(list_right_eye_open), 0, 50.0)
|
| 217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
for i in range(len(list_timestamp)):
|
| 219 |
csv_writer.writerow([list_timestamp[i], list_mouth_open[i], list_left_eye_open[i],
|
| 220 |
list_right_eye_open[i], list_pitch[i], list_yaw[i],
|
| 221 |
list_roll[i], list_norm_x[i], list_norm_y[i]])
|
| 222 |
|
|
|
|
| 223 |
cap.release()
|
| 224 |
out.release()
|
| 225 |
cv2.destroyAllWindows()
|
| 226 |
detector.close()
|
| 227 |
csv_file.close()
|
| 228 |
|
|
|
|
| 229 |
print("\n[H264] Conversion pour compatibilité navigateur...")
|
| 230 |
|
|
|
|
| 231 |
ffmpeg_cmd = shutil.which("ffmpeg")
|
| 232 |
if not ffmpeg_cmd:
|
| 233 |
candidates = [
|
| 234 |
r"C:\ffmpeg\bin\ffmpeg.exe",
|
| 235 |
r"C:\Program Files\ffmpeg\bin\ffmpeg.exe",
|
| 236 |
-
r"C:\Users\adril\scoop\shims\ffmpeg.exe",
|
| 237 |
]
|
| 238 |
for c in candidates:
|
| 239 |
if os.path.exists(c):
|
|
@@ -243,6 +384,14 @@ if not ffmpeg_cmd:
|
|
| 243 |
if ffmpeg_cmd:
|
| 244 |
safe_output = os.path.join(dossier, f"{video_name}_landmarks_h264.mp4")
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
result = subprocess.run(
|
| 247 |
[ffmpeg_cmd, "-y", "-i", temp_video_path,
|
| 248 |
"-c:v", "libx264", "-preset", "fast", "-crf", "23",
|
|
@@ -251,15 +400,20 @@ if ffmpeg_cmd:
|
|
| 251 |
capture_output=True, text=True
|
| 252 |
)
|
| 253 |
if result.returncode == 0:
|
| 254 |
-
os.remove(temp_video_path)
|
| 255 |
if os.path.exists(output_video_path):
|
| 256 |
os.remove(output_video_path)
|
| 257 |
-
os.rename(safe_output, output_video_path)
|
| 258 |
print("[H264] Succès.")
|
| 259 |
else:
|
|
|
|
|
|
|
| 260 |
os.rename(temp_video_path, output_video_path)
|
| 261 |
print(f"[H264] ffmpeg a échoué : {result.stderr[-300:]}")
|
| 262 |
|
|
|
|
|
|
|
|
|
|
| 263 |
if ffmpeg_cmd:
|
| 264 |
wav_result = subprocess.run(
|
| 265 |
[ffmpeg_cmd, "-y", "-i", video_path, "-vn", "-acodec", "pcm_s16le",
|
|
@@ -271,4 +425,9 @@ if ffmpeg_cmd:
|
|
| 271 |
else:
|
| 272 |
print(f"[WAV] Échec extraction audio : {wav_result.stderr[-200:]}")
|
| 273 |
else:
|
| 274 |
-
print("[WAV] ffmpeg introuvable, pas d'extraction audio.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
+
import cv2 # OpenCV : lecture/écriture vidéo et dessin
|
| 3 |
from mediapipe.tasks import python
|
| 4 |
from mediapipe.tasks.python import vision
|
| 5 |
from mediapipe import Image, ImageFormat
|
| 6 |
+
import numpy as np # Calculs mathématiques/matrices
|
| 7 |
import urllib.request
|
| 8 |
import csv
|
| 9 |
+
import os # Manip de chemins et fichiers
|
| 10 |
+
import sys # Accès aux arguments de la ligne de commande
|
| 11 |
import subprocess
|
| 12 |
import shutil
|
| 13 |
|
| 14 |
+
### LECTURE DES ARGUMENTS ET DES CHEMINS ###
|
| 15 |
+
|
| 16 |
+
# On s'assure qu'on a bien mis la vidéo en argument
|
| 17 |
if len(sys.argv) < 2:
|
| 18 |
print("Usage: python Jalon2OPTI.py <video_file> [nom_personnalise]")
|
| 19 |
sys.exit(1)
|
| 20 |
|
| 21 |
+
# Récupération du chemin absolu vers la vidéo d'entrée
|
| 22 |
video_path = sys.argv[1]
|
| 23 |
if not os.path.exists(video_path):
|
| 24 |
print(f"Erreur: Le fichier '{video_path}' n'existe pas.")
|
| 25 |
sys.exit(1)
|
| 26 |
|
| 27 |
+
# On extrait le nom de fichier et son extension pour construire les sorties
|
| 28 |
video_name_with_ext = os.path.basename(video_path)
|
| 29 |
video_ext = os.path.splitext(video_name_with_ext)[1]
|
| 30 |
|
| 31 |
+
|
| 32 |
+
# Si un nom personnalisé est fourni en 2eme argument on l'utilise
|
| 33 |
+
# sinon on prend le nom du fichier sans extension
|
| 34 |
if len(sys.argv) >= 3 and sys.argv[2].strip():
|
| 35 |
video_name = sys.argv[2].strip()
|
| 36 |
else:
|
| 37 |
video_name = os.path.splitext(video_name_with_ext)[0]
|
| 38 |
|
| 39 |
+
# Dossier où se trouve ce code
|
| 40 |
dossier = os.path.dirname(os.path.abspath(sys.argv[0]))
|
| 41 |
|
| 42 |
+
# Vidéo landmarkée (format final h264 pour le navigateur)
|
| 43 |
output_video_path = os.path.join(dossier, f"./liste/landmarks/{video_name}(landmarks){video_ext}")
|
| 44 |
+
|
| 45 |
+
# Fichier CSV contenant tous les signaux extraits image par image
|
| 46 |
output_csv_path = os.path.join(dossier, f"./liste/csv/{video_name}.csv")
|
| 47 |
+
|
| 48 |
+
# Vidéo temporaire en mp4v brut (avant conversion h264 par ffmpeg)
|
| 49 |
temp_video_path = os.path.join(dossier, f"{video_name}_temp_raw.mp4")
|
| 50 |
+
|
| 51 |
+
# Audio extrait de la vidéo source (format WAV car Reachy mini ne lit que les .wav)
|
| 52 |
output_wav_path = os.path.join(dossier, f"./liste/audio/{video_name}.wav")
|
| 53 |
|
| 54 |
print(f"Vidéo d'entrée : {video_path}")
|
| 55 |
print(f"CSV de sortie : {output_csv_path}")
|
| 56 |
print(f"Vidéo annotée : {output_video_path}")
|
| 57 |
|
| 58 |
+
### CHARGER LE MODÈLE MEDIAPIPE ###
|
| 59 |
+
|
| 60 |
+
# Chemin local du modèle
|
| 61 |
model_path = os.path.join(dossier, "face_landmarker.task")
|
| 62 |
+
|
| 63 |
+
# Téléchargement auto si le fichier est absent
|
| 64 |
if not os.path.exists(model_path):
|
| 65 |
print("Téléchargement du modèle face_landmarker...")
|
| 66 |
urllib.request.urlretrieve(
|
|
|
|
| 68 |
model_path
|
| 69 |
)
|
| 70 |
|
| 71 |
+
### CONFIGURATION DU MODÈLE ###
|
| 72 |
+
|
| 73 |
options = vision.FaceLandmarkerOptions(
|
| 74 |
base_options=python.BaseOptions(model_asset_path=model_path),
|
| 75 |
+
running_mode=vision.RunningMode.VIDEO, # Mode vidéo : images séquentielles
|
| 76 |
+
num_faces=1, # On ne suit qu'un seul visage à la fois
|
| 77 |
+
min_face_detection_confidence=0.7, # Seuil de détection initiale à 70%
|
| 78 |
+
min_tracking_confidence=0.5 # Seuil de suivi entre les frames à 50%
|
| 79 |
)
|
| 80 |
detector = vision.FaceLandmarker.create_from_options(options)
|
| 81 |
|
| 82 |
+
### CHARGER LA VIDÉO ###
|
| 83 |
+
|
| 84 |
+
cap = cv2.VideoCapture(video_path) # Ouvre la vidéo en lecture
|
| 85 |
+
fps = cap.get(cv2.CAP_PROP_FPS) # Récupère le nombre de fps
|
| 86 |
+
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # Largeur en pixels
|
| 87 |
+
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # Hauteur en pixels
|
| 88 |
+
frame_index = 0 # Compteur d'image (pour le calcul du timestamp)
|
| 89 |
|
| 90 |
+
|
| 91 |
+
# VideoWriter : écrit les frames annotées dans un fichier mp4v temporaire
|
| 92 |
+
# On utilise mp4v puis ffmpeg pour le recompresser en h264 ensuite
|
| 93 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 94 |
out = cv2.VideoWriter(temp_video_path, fourcc, fps, (frame_width, frame_height))
|
| 95 |
|
| 96 |
+
### CRÉATION DU FICHIER CSV ###
|
| 97 |
+
|
| 98 |
+
# Le CSV contient une ligne par image avec tous les signaux extraits
|
| 99 |
+
# C'est ce fichier que reachy mini va lire dans main.py pour pouvoir bouger
|
| 100 |
csv_file = open(output_csv_path, "w", newline="", encoding="utf-8")
|
| 101 |
csv_writer = csv.writer(csv_file)
|
| 102 |
csv_writer.writerow(["timestamp", "bouche", "oeil_g", "oeil_d", "pitch", "yaw", "roll", "norm_x", "norm_y"])
|
| 103 |
|
| 104 |
+
### FONCTIONS UTILITAIRES ###
|
| 105 |
|
| 106 |
def generic_optic(width, height):
|
| 107 |
focal_length = width
|
|
|
|
| 111 |
|
| 112 |
|
| 113 |
def compute_head_pose(landmarks, frame_w, frame_h):
|
| 114 |
+
# Coordonnées 3D d'un modèle de visage générique
|
| 115 |
model_points = np.array([
|
| 116 |
+
[0.0, 0.0, 0.0 ], # bout du nez (référence)
|
| 117 |
+
[0.0, -330.0, -65.0], # menton
|
| 118 |
+
[-225.0, 170.0, -135.0], # coin oeil gauche
|
| 119 |
+
[225.0, 170.0, -135.0], # coin oeil droit
|
| 120 |
+
[-150.0, -150.0, -125.0], # coin bouche gauche
|
| 121 |
+
[150.0, -150.0, -125.0], # coin bouche droit
|
| 122 |
], dtype=np.float64)
|
| 123 |
indices = [1, 152, 33, 263, 61, 291]
|
| 124 |
+
|
| 125 |
+
# Coordonnées 2D correspondantes dans l'image courante
|
| 126 |
image_points = np.array([[landmarks[i].x * frame_w, landmarks[i].y * frame_h] for i in indices], dtype=np.float64)
|
| 127 |
camera_matrix, dist_coeffs = generic_optic(frame_w, frame_h)
|
| 128 |
+
|
| 129 |
+
# solvePnP résout des problème de pose : trouve R et t de façon à ce que image_point = K * [R|t] * model_point
|
| 130 |
success, rotation_vec, translation_vec = cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs,
|
| 131 |
flags=cv2.SOLVEPNP_ITERATIVE)
|
| 132 |
if not success:
|
| 133 |
return None, None, None, None, None
|
| 134 |
+
|
| 135 |
+
# Conversion du vecteur de rotation (Rodrigues) en matrice 3x3
|
| 136 |
rotation_mat, _ = cv2.Rodrigues(rotation_vec)
|
| 137 |
+
|
| 138 |
+
# Décomposition de la matrice pour obtenir les angles d'Euler
|
| 139 |
pose_mat = cv2.hconcat([rotation_mat, translation_vec])
|
| 140 |
_, _, _, _, _, _, euler_angles = cv2.decomposeProjectionMatrix(pose_mat)
|
| 141 |
return euler_angles[0, 0], euler_angles[1, 0], euler_angles[2, 0], rotation_vec, translation_vec
|
|
|
|
| 146 |
ys = [lm.y for lm in landmarks]
|
| 147 |
x_min, x_max = min(xs), max(xs)
|
| 148 |
y_min, y_max = min(ys), max(ys)
|
| 149 |
+
|
| 150 |
+
# Centre du visage
|
| 151 |
center_x = int(((x_min + x_max) / 2) * frame_w)
|
| 152 |
center_y = int(((y_min + y_max) / 2) * frame_h)
|
| 153 |
+
|
| 154 |
+
# 0.5 correspond au centre de l'image qui est ramené à 0
|
| 155 |
+
norm_x = ((x_min + x_max) / 2 - 0.5) * 2 # dans [-1, 1]
|
| 156 |
norm_y = ((y_min + y_max) / 2 - 0.5) * 2
|
| 157 |
face_w = int((x_max - x_min) * frame_w)
|
| 158 |
face_h = int((y_max - y_min) * frame_h)
|
|
|
|
| 162 |
|
| 163 |
|
| 164 |
def draw_axes(frame, rotation_vec, translation_vec, camera_matrix, dist_coeffs, origin):
|
| 165 |
+
|
| 166 |
+
# Points 3D représentant le bout de chaque axe
|
| 167 |
+
axis_points = np.array([
|
| 168 |
+
[160.0, 0.0, 0.0 ], # axe X
|
| 169 |
+
[0.0, 160.0, 0.0], # axe Y
|
| 170 |
+
[0.0, 0.0, -160.0 ], # axe Z (vers l'avant = Z négatif)
|
| 171 |
+
], dtype=np.float64)
|
| 172 |
+
|
| 173 |
+
# Projection des points 3D en coordonnées 2D image
|
| 174 |
projected, _ = cv2.projectPoints(axis_points, rotation_vec, translation_vec, camera_matrix, dist_coeffs)
|
| 175 |
o = (int(origin[0]), int(origin[1]))
|
| 176 |
+
cv2.arrowedLine(frame, o, (int(projected[0][0][0]), int(projected[0][0][1])), (0, 0, 255), 2, tipLength=0.3) # Rouge x
|
| 177 |
+
cv2.arrowedLine(frame, o, (int(projected[1][0][0]), int(projected[1][0][1])), (0, 255, 0), 2, tipLength=0.3) # Vert Y
|
| 178 |
+
cv2.arrowedLine(frame, o, (int(projected[2][0][0]), int(projected[2][0][1])), (255, 0, 0), 2, tipLength=0.3) # Bleu Z
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
### CRÉATION DES LISTES POUR STOCKER LES SIGNAUX ###
|
| 182 |
|
| 183 |
+
# Ces listes stockent les valeurs extraites image par image.
|
| 184 |
+
# Elles seront normalisées APRÈS la boucle principale (on a besoin du min/max
|
| 185 |
+
# global pour la normalisation donc on ne peut pas le faire tel quel).
|
| 186 |
|
| 187 |
+
list_timestamp = [] # Temps en s depuis le début de la vidéo
|
| 188 |
+
list_mouth_open = [] # Ouverture de la bouche
|
| 189 |
+
list_left_eye_open = [] # Ouverture oeil gauche
|
| 190 |
+
list_right_eye_open = [] # Ouverture oeil droit
|
| 191 |
+
list_pitch = [] # Inclinaison avant/arrière de la tête
|
| 192 |
+
list_yaw = [] # Rotation gauche/droite de la tête # pitch, yaw et roll sont en degrés
|
| 193 |
+
list_roll = [] # Inclinaison latérale de la tête
|
| 194 |
+
list_norm_x = [] # Position horizontale normalisée du visage
|
| 195 |
+
list_norm_y = [] # Position verticale normalisée du visage
|
| 196 |
+
|
| 197 |
+
### BOUCLE PRINCIPALE ###
|
| 198 |
|
| 199 |
while True:
|
| 200 |
+
ret, frame = cap.read() # Lit la prochaine frame de la vidéo
|
| 201 |
if not ret:
|
| 202 |
break
|
| 203 |
|
| 204 |
+
# Calcul du timestamp en s
|
| 205 |
timestamp = frame_index / fps
|
| 206 |
frame_index += 1
|
| 207 |
+
h, w, _ = frame.shape # Dimensions de la frame courante
|
| 208 |
|
| 209 |
+
# Conversion BGR -> RGB pour MediaPipe car Mediapipe veut du RGB
|
| 210 |
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 211 |
mp_image = Image(image_format=ImageFormat.SRGB, data=rgb_frame)
|
| 212 |
+
|
| 213 |
+
# Détection des landmarks, envoi du timestamp en ms
|
| 214 |
results = detector.detect_for_video(mp_image, int(timestamp * 1000))
|
| 215 |
|
| 216 |
+
if results.face_landmarks: # Si un visage est détécté :
|
| 217 |
+
landmarks = results.face_landmarks[0] # Récupère le premier et le seul visage détécté
|
| 218 |
+
|
| 219 |
+
mouth_open = abs(landmarks[13].y - landmarks[14].y) # Ouverture de la bouche
|
| 220 |
+
|
| 221 |
+
left_eye_open = abs(landmarks[159].y - landmarks[145].y) # Ouverture des yeux
|
| 222 |
right_eye_open = abs(landmarks[386].y - landmarks[374].y)
|
| 223 |
+
|
| 224 |
+
pitch, yaw, roll, rot_vec, trans_vec = compute_head_pose(landmarks, w, h) # Orientation complète de la tête (pitch / yaw / roll)
|
| 225 |
+
|
| 226 |
+
(center_x, center_y, # Position et taille du visage dans l'image
|
| 227 |
+
norm_x, norm_y,
|
| 228 |
+
face_w, face_h,
|
| 229 |
+
face_size_ratio,
|
| 230 |
+
bbox) = compute_face_position(landmarks, w, h)
|
| 231 |
+
|
| 232 |
+
yaw = -yaw
|
| 233 |
+
if pitch < 0:
|
| 234 |
+
pitch += 180
|
| 235 |
+
else:
|
| 236 |
+
pitch -= 180 # Convertit yaw et pitch pour que reachy mini les lise correctement
|
| 237 |
+
|
| 238 |
+
# Reachy Mini a des valeurs en roll et pitch comprises entre -40 et 40, et entre -180 et 180 pour yaw donc
|
| 239 |
+
if roll < (-40):
|
| 240 |
+
roll = -40
|
| 241 |
+
if roll > (40):
|
| 242 |
+
roll = 40
|
| 243 |
+
|
| 244 |
+
if pitch < (-40):
|
| 245 |
+
pitch = -40
|
| 246 |
+
if pitch > (40):
|
| 247 |
+
pitch = 40
|
| 248 |
+
|
| 249 |
+
if yaw < (-180):
|
| 250 |
+
yaw = -180
|
| 251 |
+
if yaw > (180):
|
| 252 |
+
yaw = 180
|
| 253 |
+
|
| 254 |
+
print(
|
| 255 |
+
f"t={timestamp:.2f}s | "
|
| 256 |
+
f"bouche={mouth_open:.3f} | "
|
| 257 |
+
f"oeil_g={left_eye_open:.3f} | oeil_d={right_eye_open:.3f} | "
|
| 258 |
+
f"pitch={pitch:+.1f}° | yaw={yaw:+.1f}° | roll={roll:+.1f}° | "
|
| 259 |
+
f"pos=({norm_x:+.2f}, {norm_y:+.2f})"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
list_timestamp.append(round(timestamp, 2))
|
| 263 |
+
list_mouth_open.append(round(mouth_open, 3))
|
| 264 |
+
list_left_eye_open.append(round(left_eye_open, 3))
|
| 265 |
+
list_right_eye_open.append(round(right_eye_open, 3))
|
| 266 |
+
list_pitch.append(round(pitch, 1))
|
| 267 |
+
list_yaw.append(round(yaw, 1))
|
| 268 |
+
list_roll.append(round(roll, 1))
|
| 269 |
+
list_norm_x.append(round(norm_x, 2))
|
| 270 |
+
list_norm_y.append(round(norm_y, 2))
|
| 271 |
+
|
| 272 |
+
for landmark in landmarks: # Affichage des landmarks
|
| 273 |
+
x = int(landmark.x * w)
|
| 274 |
+
y = int(landmark.y * h)
|
| 275 |
+
cv2.circle(frame, (x, y), 1, (0, 255, 0), -1)
|
| 276 |
+
|
| 277 |
+
x1, y1, x2, y2 = bbox # Dessine le rectangle autour du visage
|
| 278 |
+
cv2.rectangle(frame, (x1, y1), (x2, y2), (255, 165, 0), 1)
|
| 279 |
+
|
| 280 |
+
cv2.circle(frame, (center_x, center_y), 5, (0, 165, 255), -1) # Dessine le centre du visage en orange
|
| 281 |
+
|
| 282 |
+
cv2.drawMarker(frame, (w // 2, h // 2), (128, 128, 128), # Croix au centre de l'image
|
| 283 |
+
cv2.MARKER_CROSS, 20, 1)
|
| 284 |
+
|
| 285 |
+
if rot_vec is not None: # Si compute_head_pose réussit on execute sinon on arrête pour éviter le crash
|
| 286 |
+
camera_matrix, dist_coeffs = generic_optic(w, h)
|
| 287 |
+
|
| 288 |
+
nose_tip = (int(landmarks[1].x * w), int(landmarks[1].y * h)) # Calcule la position du nez
|
| 289 |
+
draw_axes(frame, rot_vec, trans_vec, camera_matrix, dist_coeffs, nose_tip) # Dessine les axes
|
| 290 |
elif list_mouth_open:
|
| 291 |
+
|
| 292 |
+
# Gestion des erreurs : visage perdu pendant un court instant donc on repete la dernière valeur connue pour que Reachy ne fasse pas de mouvements bizarres
|
| 293 |
list_timestamp.append(round(timestamp, 2))
|
| 294 |
list_mouth_open.append(list_mouth_open[-1])
|
| 295 |
list_left_eye_open.append(list_left_eye_open[-1])
|
|
|
|
| 300 |
list_norm_x.append(list_norm_x[-1])
|
| 301 |
list_norm_y.append(list_norm_y[-1])
|
| 302 |
else:
|
| 303 |
+
|
| 304 |
+
# Gestion des erreurs : pas de visage détéctés donc on initialise tout à 0
|
| 305 |
list_timestamp.append(round(timestamp, 2))
|
| 306 |
list_mouth_open.append(0.0)
|
| 307 |
list_left_eye_open.append(0.0)
|
|
|
|
| 312 |
list_norm_x.append(0.0)
|
| 313 |
list_norm_y.append(0.0)
|
| 314 |
|
| 315 |
+
# Écrit la frame landmarkée
|
| 316 |
out.write(frame)
|
| 317 |
|
| 318 |
+
# Vérification qu'on ait au moins un visage dans la vidéo
|
| 319 |
if not list_mouth_open:
|
| 320 |
print("Erreur : aucun visage détecté.")
|
| 321 |
cap.release()
|
|
|
|
| 325 |
csv_file.close()
|
| 326 |
sys.exit(1)
|
| 327 |
|
| 328 |
+
### CONVERSION DES SIGNAUX ###
|
| 329 |
|
| 330 |
+
def convert_for_rm(values, min_value, max_value, window, gap):
|
| 331 |
+
if min_value != max_value:
|
| 332 |
+
return [((i - min_value) / (max_value - min_value)) * window - gap for i in values]
|
| 333 |
+
return [0.0 for _ in values]
|
| 334 |
|
| 335 |
+
# Normalisation pour Reachy Mini
|
| 336 |
|
| 337 |
+
# Ouverture de la bouche comprise entre -0.01 et 0.01
|
| 338 |
+
list_mouth_open = convert_for_rm(list_mouth_open, min(list_mouth_open), max(list_mouth_open), 0.02, 0.01)
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
+
# Position horizontale du visage comprise entre -0.03 et 0.03
|
| 341 |
+
list_norm_x = convert_for_rm(list_norm_x, min(list_norm_x), max(list_norm_x), 0.06, 0.03)
|
| 342 |
+
|
| 343 |
+
# Position verticale du visage comprise entre -0.0075 et 0.0075
|
| 344 |
+
list_norm_y = convert_for_rm(list_norm_y, min(list_norm_y), max(list_norm_y), 0.015 , 0.0075)
|
| 345 |
+
|
| 346 |
+
# Ouverture oeil gauche comprise entre 0 et 50 degrés (convertis en radian
|
| 347 |
+
list_left_eye_open = convert_for_rm(list_left_eye_open, min(list_left_eye_open), max(list_left_eye_open), 50.0, 0.0)
|
| 348 |
+
|
| 349 |
+
# Inversion : oeil fermé = antenne baissée, oeil ouvert = antenne levée
|
| 350 |
+
list_left_eye_open = [-i for i in list_left_eye_open]
|
| 351 |
+
|
| 352 |
+
# Ouverture oeil droit comprise entre 0 et 50 degrés (convertis en radian
|
| 353 |
+
list_right_eye_open = convert_for_rm(list_right_eye_open, min(list_right_eye_open), max(list_right_eye_open), 50.0, 0.0)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
+
# Une ligne pour chaque frame analysée du csv
|
| 357 |
for i in range(len(list_timestamp)):
|
| 358 |
csv_writer.writerow([list_timestamp[i], list_mouth_open[i], list_left_eye_open[i],
|
| 359 |
list_right_eye_open[i], list_pitch[i], list_yaw[i],
|
| 360 |
list_roll[i], list_norm_x[i], list_norm_y[i]])
|
| 361 |
|
| 362 |
+
# on libère les ressources OpenCV et mediapipe en fermant le lecteur vidéo, son writer/ Ferme les fenêtres opencv/ Libère le detecteur mediapipe puis ferme le csv
|
| 363 |
cap.release()
|
| 364 |
out.release()
|
| 365 |
cv2.destroyAllWindows()
|
| 366 |
detector.close()
|
| 367 |
csv_file.close()
|
| 368 |
|
| 369 |
+
### CONVERSION EN H264 POUR LE NAVIGATEUR ###
|
| 370 |
print("\n[H264] Conversion pour compatibilité navigateur...")
|
| 371 |
|
| 372 |
+
# Recherche de ffmpeg dans des chemins systèmes
|
| 373 |
ffmpeg_cmd = shutil.which("ffmpeg")
|
| 374 |
if not ffmpeg_cmd:
|
| 375 |
candidates = [
|
| 376 |
r"C:\ffmpeg\bin\ffmpeg.exe",
|
| 377 |
r"C:\Program Files\ffmpeg\bin\ffmpeg.exe",
|
|
|
|
| 378 |
]
|
| 379 |
for c in candidates:
|
| 380 |
if os.path.exists(c):
|
|
|
|
| 384 |
if ffmpeg_cmd:
|
| 385 |
safe_output = os.path.join(dossier, f"{video_name}_landmarks_h264.mp4")
|
| 386 |
|
| 387 |
+
# Options ffmpeg :
|
| 388 |
+
# -c:v libx264 pour le h264
|
| 389 |
+
# -preset fast bon compromis vitesse/qualité
|
| 390 |
+
# -crf 23 qualité constante (0=lossless, 51=dégradé max)
|
| 391 |
+
# -pix_fmt yuv420p format de pixel universel (obligatoire pour Safari/iOS)
|
| 392 |
+
# -movflags +faststart place les métadonnées en début de fichier (streaming)
|
| 393 |
+
# -an supprime la piste audio (elle sera gérée séparément)
|
| 394 |
+
|
| 395 |
result = subprocess.run(
|
| 396 |
[ffmpeg_cmd, "-y", "-i", temp_video_path,
|
| 397 |
"-c:v", "libx264", "-preset", "fast", "-crf", "23",
|
|
|
|
| 400 |
capture_output=True, text=True
|
| 401 |
)
|
| 402 |
if result.returncode == 0:
|
| 403 |
+
os.remove(temp_video_path) # Supprime la vidéo temp
|
| 404 |
if os.path.exists(output_video_path):
|
| 405 |
os.remove(output_video_path)
|
| 406 |
+
os.rename(safe_output, output_video_path) # La déplace vers le dossier
|
| 407 |
print("[H264] Succès.")
|
| 408 |
else:
|
| 409 |
+
|
| 410 |
+
# Si ffmpeg a pas marché, alors il y aura simplement le mp4v
|
| 411 |
os.rename(temp_video_path, output_video_path)
|
| 412 |
print(f"[H264] ffmpeg a échoué : {result.stderr[-300:]}")
|
| 413 |
|
| 414 |
+
|
| 415 |
+
### EXTRACTION DE L'AUDIO ###
|
| 416 |
+
|
| 417 |
if ffmpeg_cmd:
|
| 418 |
wav_result = subprocess.run(
|
| 419 |
[ffmpeg_cmd, "-y", "-i", video_path, "-vn", "-acodec", "pcm_s16le",
|
|
|
|
| 425 |
else:
|
| 426 |
print(f"[WAV] Échec extraction audio : {wav_result.stderr[-200:]}")
|
| 427 |
else:
|
| 428 |
+
print("[WAV] ffmpeg introuvable, pas d'extraction audio.")
|
| 429 |
+
|
| 430 |
+
# Suppression de la vidéo temp
|
| 431 |
+
if os.path.basename(video_path) == "video_temp.mp4":
|
| 432 |
+
os.remove(video_path)
|
| 433 |
+
print("[CLEANUP] video_temp.mp4 supprimé.")
|
coquille/Jalon3.py
CHANGED
|
@@ -45,20 +45,8 @@ class Test(ReachyMiniApp):
|
|
| 45 |
reachy_mini.media.start_playing()
|
| 46 |
reachy_mini.media.push_audio_sample(audio)
|
| 47 |
|
| 48 |
-
# Tout est pret : signaler au serveur que la lecture commence
|
| 49 |
-
try:
|
| 50 |
-
req = urllib.request.Request(
|
| 51 |
-
f"{SERVER_URL}/ready",
|
| 52 |
-
data=b"{}",
|
| 53 |
-
headers={"Content-Type": "application/json"},
|
| 54 |
-
method="POST"
|
| 55 |
-
)
|
| 56 |
-
urllib.request.urlopen(req, timeout=2)
|
| 57 |
-
print("[READY] Signal envoye au serveur")
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f"[READY] Echec signal : {e}")
|
| 60 |
-
|
| 61 |
last_timestamp = 0
|
|
|
|
| 62 |
for row in rows:
|
| 63 |
if stop_event.is_set():
|
| 64 |
break
|
|
@@ -75,6 +63,21 @@ class Test(ReachyMiniApp):
|
|
| 75 |
head_pose = create_head_pose(x=x_pos, y=y_pos, z=z_pos, pitch=pitch_deg, yaw=yaw_deg, roll=roll_deg)
|
| 76 |
reachy_mini.set_target(head=head_pose, antennas=antennas_rad)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
time.sleep(float(row['timestamp']) - last_timestamp)
|
| 79 |
last_timestamp = float(row['timestamp'])
|
| 80 |
|
|
|
|
| 45 |
reachy_mini.media.start_playing()
|
| 46 |
reachy_mini.media.push_audio_sample(audio)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
last_timestamp = 0
|
| 49 |
+
_ready_sent = False
|
| 50 |
for row in rows:
|
| 51 |
if stop_event.is_set():
|
| 52 |
break
|
|
|
|
| 63 |
head_pose = create_head_pose(x=x_pos, y=y_pos, z=z_pos, pitch=pitch_deg, yaw=yaw_deg, roll=roll_deg)
|
| 64 |
reachy_mini.set_target(head=head_pose, antennas=antennas_rad)
|
| 65 |
|
| 66 |
+
# Signaler au serveur juste apres le premier set_target
|
| 67 |
+
if not _ready_sent:
|
| 68 |
+
_ready_sent = True
|
| 69 |
+
try:
|
| 70 |
+
req = urllib.request.Request(
|
| 71 |
+
f"{SERVER_URL}/ready",
|
| 72 |
+
data=b"{}",
|
| 73 |
+
headers={"Content-Type": "application/json"},
|
| 74 |
+
method="POST"
|
| 75 |
+
)
|
| 76 |
+
urllib.request.urlopen(req, timeout=2)
|
| 77 |
+
print("[READY] Signal envoye au serveur (premier set_target)")
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print(f"[READY] Echec signal : {e}")
|
| 80 |
+
|
| 81 |
time.sleep(float(row['timestamp']) - last_timestamp)
|
| 82 |
last_timestamp = float(row['timestamp'])
|
| 83 |
|
coquille/main.py
CHANGED
|
@@ -1,19 +1,20 @@
|
|
| 1 |
-
#
|
|
|
|
| 2 |
import sys
|
| 3 |
-
import io
|
| 4 |
-
|
| 5 |
-
# Force la sortie UTF-8 pour éviter les crashs de décodage Unicode avec le daemon Reachy
|
| 6 |
-
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
|
| 7 |
-
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace")
|
| 8 |
-
|
| 9 |
-
import threading
|
| 10 |
-
import subprocess
|
| 11 |
import os
|
| 12 |
-
import time
|
| 13 |
-
|
| 14 |
-
from fastapi
|
| 15 |
-
from fastapi.
|
|
|
|
| 16 |
from reachy_mini import ReachyMini, ReachyMiniApp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
DOSSIER = os.path.dirname(os.path.abspath(__file__))
|
| 19 |
STATIC = os.path.join(DOSSIER, "static")
|
|
@@ -21,56 +22,203 @@ DOSSIER_CSV = os.path.join(DOSSIER, "liste", "csv")
|
|
| 21 |
DOSSIER_LANDMARKS = os.path.join(DOSSIER, "liste", "landmarks")
|
| 22 |
DOSSIER_AUDIO = os.path.join(DOSSIER, "liste", "audio")
|
| 23 |
|
| 24 |
-
#
|
| 25 |
os.makedirs(DOSSIER_CSV, exist_ok=True)
|
| 26 |
os.makedirs(DOSSIER_LANDMARKS, exist_ok=True)
|
| 27 |
os.makedirs(DOSSIER_AUDIO, exist_ok=True)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
_ready_event = threading.Event()
|
| 31 |
-
_play_start_time: float = 0.0
|
| 32 |
-
|
| 33 |
|
| 34 |
class Coquille(ReachyMiniApp):
|
| 35 |
-
custom_app_url: str | None = "http://localhost:8042"
|
| 36 |
request_media_backend: str | None = None
|
| 37 |
|
| 38 |
def __init__(self, *args, **kwargs):
|
| 39 |
super().__init__(*args, **kwargs)
|
| 40 |
-
self.robot = None
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 44 |
self.robot = reachy_mini
|
| 45 |
-
self.
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
|
|
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
app = Coquille()
|
| 51 |
|
|
|
|
| 52 |
app.settings_app.mount("/static", StaticFiles(directory=STATIC), name="static")
|
| 53 |
|
| 54 |
|
| 55 |
@app.settings_app.get("/")
|
| 56 |
def index():
|
|
|
|
| 57 |
return FileResponse(os.path.join(STATIC, "index.html"))
|
| 58 |
|
| 59 |
|
| 60 |
@app.settings_app.get("/favicon.ico")
|
| 61 |
def favicon():
|
|
|
|
| 62 |
return Response(status_code=204)
|
| 63 |
|
| 64 |
|
| 65 |
@app.settings_app.get("/liste")
|
| 66 |
def liste():
|
| 67 |
-
|
| 68 |
-
noms = [f
|
| 69 |
return JSONResponse({"noms": noms})
|
| 70 |
|
| 71 |
|
| 72 |
@app.settings_app.post("/charger")
|
| 73 |
async def charger(request: Request):
|
|
|
|
|
|
|
|
|
|
| 74 |
form = await request.form()
|
| 75 |
video_file = form.get("video")
|
| 76 |
nom = (form.get("nom") or "").strip()
|
|
@@ -78,194 +226,206 @@ async def charger(request: Request):
|
|
| 78 |
if not video_file or not nom:
|
| 79 |
return JSONResponse({"succes": False, "message": "Vidéo ou nom manquant."}, status_code=400)
|
| 80 |
|
|
|
|
| 81 |
video_path = os.path.join(DOSSIER, "video_temp.mp4")
|
| 82 |
-
contents = await video_file.read()
|
| 83 |
with open(video_path, "wb") as f:
|
| 84 |
-
f.write(
|
| 85 |
|
| 86 |
try:
|
| 87 |
-
|
| 88 |
[sys.executable, os.path.join(DOSSIER, "Jalon2OPTI.py"), video_path, nom],
|
| 89 |
-
cwd=DOSSIER,
|
| 90 |
-
capture_output=True,
|
| 91 |
-
text=True,
|
| 92 |
-
encoding="utf-8",
|
| 93 |
-
errors="replace",
|
| 94 |
-
check=True
|
| 95 |
)
|
| 96 |
-
print(f"[PIPELINE OK
|
| 97 |
-
except subprocess.CalledProcessError
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
"message": f"Pipeline échoué : {e.stderr or e.stdout or 'erreur inconnue'}"
|
| 102 |
-
}, status_code=500)
|
| 103 |
|
| 104 |
return JSONResponse({"succes": True, "nom": nom})
|
| 105 |
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
@app.settings_app.post("/play")
|
| 118 |
async def play(request: Request):
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
data = await request.json()
|
| 121 |
nom = data.get("nom", "").strip()
|
| 122 |
|
| 123 |
if not nom:
|
| 124 |
-
return JSONResponse({"succes": False, "message": "Nom manquant
|
| 125 |
|
| 126 |
csv_path = os.path.join(DOSSIER_CSV, f"{nom}.csv")
|
| 127 |
wav_path = os.path.join(DOSSIER_AUDIO, f"{nom}.wav")
|
| 128 |
|
| 129 |
if not os.path.exists(csv_path):
|
| 130 |
-
return JSONResponse({"succes": False, "message": f"CSV introuvable : {
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
cwd=DOSSIER,
|
| 143 |
-
)
|
| 144 |
-
|
| 145 |
-
print(f"[PLAY] apply_signals PID {_apply_proc.pid} pour '{nom}'")
|
| 146 |
-
return JSONResponse({"succes": True, "nom": nom})
|
| 147 |
|
| 148 |
|
| 149 |
@app.settings_app.get("/is-ready")
|
| 150 |
async def is_ready():
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
return JSONResponse({"ready":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
-
@app.settings_app.post("/
|
| 157 |
-
async def
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
return JSONResponse({"succes": True, "delay_ms": int(elapsed * 1000)})
|
| 162 |
|
| 163 |
|
| 164 |
@app.settings_app.post("/stop")
|
| 165 |
-
async def stop():
|
| 166 |
-
|
| 167 |
-
|
| 168 |
return JSONResponse({"succes": True})
|
| 169 |
|
| 170 |
|
| 171 |
@app.settings_app.get("/video/{nom}")
|
| 172 |
def video(nom: str, request: Request):
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
if name_no_ext == target:
|
| 178 |
-
path = os.path.join(DOSSIER_LANDMARKS, f)
|
| 179 |
-
break
|
| 180 |
-
|
| 181 |
-
print(f"[VIDEO] Recherche : {path} | Existe : {path is not None and os.path.exists(path)}")
|
| 182 |
-
if not path or not os.path.exists(path):
|
| 183 |
-
mp4s = [f for f in os.listdir(DOSSIER_LANDMARKS) if f.endswith(".mp4")]
|
| 184 |
-
print(f"[VIDEO] MP4 disponibles : {mp4s}")
|
| 185 |
-
return JSONResponse({"succes": False, "message": f"Vidéo introuvable pour : {nom}"}, status_code=404)
|
| 186 |
|
| 187 |
file_size = os.path.getsize(path)
|
| 188 |
range_header = request.headers.get("range")
|
| 189 |
|
| 190 |
if range_header:
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
end = int(parts[1]) if parts[1] else file_size - 1
|
| 195 |
end = min(end, file_size - 1)
|
| 196 |
-
|
| 197 |
|
| 198 |
-
def
|
| 199 |
with open(path, "rb") as f:
|
| 200 |
f.seek(start)
|
| 201 |
-
|
| 202 |
-
while
|
| 203 |
-
|
| 204 |
-
if not
|
| 205 |
break
|
| 206 |
-
|
| 207 |
-
yield
|
| 208 |
-
|
| 209 |
-
return StreamingResponse(
|
| 210 |
-
iter_file(),
|
| 211 |
-
status_code=206,
|
| 212 |
-
headers={
|
| 213 |
-
"Content-Range": f"bytes {start}-{end}/{file_size}",
|
| 214 |
-
"Accept-Ranges": "bytes",
|
| 215 |
-
"Content-Length": str(chunk_size),
|
| 216 |
-
},
|
| 217 |
-
media_type="video/mp4"
|
| 218 |
-
)
|
| 219 |
-
else:
|
| 220 |
-
return FileResponse(path, media_type="video/mp4", headers={"Accept-Ranges": "bytes"})
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
try:
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
nom = (data.get("nom") or "").strip()
|
| 231 |
if not nom:
|
| 232 |
return JSONResponse({"succes": False, "message": "Nom manquant."}, status_code=400)
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
# Recherche dynamique de la vidéo pour s'adapter à toutes les extensions (.mp4, .avi, etc.)
|
| 238 |
-
video_path = None
|
| 239 |
-
target = f"{nom}(landmarks)"
|
| 240 |
-
for f in os.listdir(DOSSIER_LANDMARKS):
|
| 241 |
-
name_no_ext, _ = os.path.splitext(f)
|
| 242 |
-
if name_no_ext == target:
|
| 243 |
-
video_path = os.path.join(DOSSIER_LANDMARKS, f)
|
| 244 |
-
break
|
| 245 |
-
|
| 246 |
-
supprime = []
|
| 247 |
-
chemins_a_verifier = [csv_path, audio_path]
|
| 248 |
-
if video_path:
|
| 249 |
-
chemins_a_verifier.append(video_path)
|
| 250 |
-
|
| 251 |
-
for p in chemins_a_verifier:
|
| 252 |
-
if os.path.exists(p):
|
| 253 |
-
try:
|
| 254 |
-
os.remove(p)
|
| 255 |
-
supprime.append(p)
|
| 256 |
-
except PermissionError:
|
| 257 |
-
return JSONResponse({
|
| 258 |
-
"succes": False,
|
| 259 |
-
"message": f"Fichier verrouillé (fermez la vidéo ou attendez la fin de l'animation) : {os.path.basename(p)}"
|
| 260 |
-
}, status_code=500)
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
-
return JSONResponse({"succes":
|
| 267 |
|
| 268 |
|
| 269 |
if __name__ == "__main__":
|
| 270 |
import uvicorn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
uvicorn.run(app.settings_app, host="127.0.0.1", port=8042)
|
|
|
|
| 1 |
+
import threading # Lancement du thread de lecture CSV sans bloquer le serveur
|
| 2 |
+
import subprocess # Exécution de Jalon2OPTI.py comme sous-processus Python
|
| 3 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import os
|
| 5 |
+
import time # Gestion précise du timing pour la synchronisation
|
| 6 |
+
import csv
|
| 7 |
+
from fastapi import Request # Objet requête HTTP
|
| 8 |
+
from fastapi.responses import JSONResponse, FileResponse, StreamingResponse, Response # Différents types de réponses
|
| 9 |
+
from fastapi.staticfiles import StaticFiles # Fichiers statiques
|
| 10 |
from reachy_mini import ReachyMini, ReachyMiniApp
|
| 11 |
+
from reachy_mini.utils import create_head_pose
|
| 12 |
+
import numpy as np # Conversion degrés → radians pour les antennes
|
| 13 |
+
import soundfile as sf # Lecture de fichiers audio WAV
|
| 14 |
+
import scipy.signal
|
| 15 |
+
import yt_dlp # Téléchargement de vidéos YouTube
|
| 16 |
+
|
| 17 |
+
### CHEMINS DE SAUVEGARDE ###
|
| 18 |
|
| 19 |
DOSSIER = os.path.dirname(os.path.abspath(__file__))
|
| 20 |
STATIC = os.path.join(DOSSIER, "static")
|
|
|
|
| 22 |
DOSSIER_LANDMARKS = os.path.join(DOSSIER, "liste", "landmarks")
|
| 23 |
DOSSIER_AUDIO = os.path.join(DOSSIER, "liste", "audio")
|
| 24 |
|
| 25 |
+
# Crée les dossiers si jamais ils sont absents
|
| 26 |
os.makedirs(DOSSIER_CSV, exist_ok=True)
|
| 27 |
os.makedirs(DOSSIER_LANDMARKS, exist_ok=True)
|
| 28 |
os.makedirs(DOSSIER_AUDIO, exist_ok=True)
|
| 29 |
|
| 30 |
+
### CLASSE PRINCIPALE POUR L'APP ###
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
class Coquille(ReachyMiniApp):
|
| 33 |
+
custom_app_url: str | None = "http://localhost:8042" # URL interne ouverte en local
|
| 34 |
request_media_backend: str | None = None
|
| 35 |
|
| 36 |
def __init__(self, *args, **kwargs):
|
| 37 |
super().__init__(*args, **kwargs)
|
| 38 |
+
self.robot: ReachyMini | None = None # Instance du robot
|
| 39 |
+
|
| 40 |
+
# Le robot et la lecture de la vidéo sont prets à démarrer
|
| 41 |
+
self.robot_ready = threading.Event()
|
| 42 |
+
self.playback_ready = threading.Event()
|
| 43 |
+
self.playback_paused = False # Lecture en pause
|
| 44 |
+
self.playback_stop = False # Arret
|
| 45 |
|
| 46 |
def run(self, reachy_mini: ReachyMini, stop_event: threading.Event):
|
| 47 |
self.robot = reachy_mini
|
| 48 |
+
self.robot_ready.set()
|
| 49 |
+
print("[ROBOT] Connecté et prêt")
|
| 50 |
+
stop_event.wait() # Bloque jusqu'à l'arret de l'app
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
### FONCTIONS UTILITAIRES ###
|
| 54 |
+
|
| 55 |
+
def interruptible_sleep(seconds: float, app_instance: Coquille):
|
| 56 |
+
deadline = time.perf_counter() + seconds
|
| 57 |
+
while time.perf_counter() < deadline:
|
| 58 |
+
if app_instance.playback_stop:
|
| 59 |
+
return
|
| 60 |
+
if app_instance.playback_paused:
|
| 61 |
+
deadline += 0.01
|
| 62 |
+
time.sleep(0.01)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
### PERMET D'ATTENDRE QUE LE ROBOT SOIT LA 2PUIS EXECUTE LE REJEU DE LA LOGIQUE DU JALON 3 ###
|
| 66 |
+
def execute_jalon3_thread(csv_path: str, wav_path: str, app_instance: Coquille):
|
| 67 |
+
|
| 68 |
+
# Attente que le robot robot soit là
|
| 69 |
+
if not app_instance.robot_ready.wait(timeout=15):
|
| 70 |
+
print("[JALON3] Timeout : robot non connecté")
|
| 71 |
+
app_instance.playback_ready.set()
|
| 72 |
+
return
|
| 73 |
+
|
| 74 |
+
robot = app_instance.robot
|
| 75 |
+
if robot is None:
|
| 76 |
+
print("[JALON3] Robot None — abandon")
|
| 77 |
+
app_instance.playback_ready.set()
|
| 78 |
+
return
|
| 79 |
+
|
| 80 |
+
try:
|
| 81 |
+
|
| 82 |
+
# Chargement du csv
|
| 83 |
+
with open(csv_path, newline='') as f:
|
| 84 |
+
rows = list(csv.DictReader(f))
|
| 85 |
+
|
| 86 |
+
# Préparer l'audio
|
| 87 |
+
audio_ok = False
|
| 88 |
+
if os.path.exists(wav_path):
|
| 89 |
+
try:
|
| 90 |
+
# Lecture du .wav
|
| 91 |
+
audio, samplerate_in = sf.read(wav_path, dtype="float32")
|
| 92 |
+
|
| 93 |
+
# Conversion stéréo mono
|
| 94 |
+
if audio.ndim > 1:
|
| 95 |
+
audio = np.mean(audio, axis=1)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
output_sr = robot.media.get_output_audio_samplerate()
|
| 99 |
+
if samplerate_in != output_sr:
|
| 100 |
+
audio = scipy.signal.resample(
|
| 101 |
+
audio,
|
| 102 |
+
int(len(audio) * (output_sr / samplerate_in))
|
| 103 |
+
)
|
| 104 |
+
audio_ok = True
|
| 105 |
+
print(f"[JALON3] Audio chargé ({len(audio)} samples)")
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"[JALON3] Erreur chargement audio : {e}")
|
| 108 |
+
else:
|
| 109 |
+
print(f"[JALON3] Pas de fichier WAV : {wav_path}")
|
| 110 |
+
|
| 111 |
+
print(f"[JALON3] {len(rows)} frames — signal prêt envoyé")
|
| 112 |
+
|
| 113 |
+
# Signaler au JS que tout est prêt
|
| 114 |
+
app_instance.playback_ready.set()
|
| 115 |
+
|
| 116 |
+
# Démarrer l'audio
|
| 117 |
+
if audio_ok:
|
| 118 |
+
try:
|
| 119 |
+
robot.media.start_playing()
|
| 120 |
+
robot.media.push_audio_sample(audio)
|
| 121 |
+
print("[JALON3] Audio lancé")
|
| 122 |
+
except Exception as e:
|
| 123 |
+
print(f"[JALON3] Erreur démarrage audio : {e}")
|
| 124 |
+
|
| 125 |
+
# Boucle de lecture image par image
|
| 126 |
+
start_time = time.perf_counter() # T0 de référence pour la synchronisation
|
| 127 |
|
| 128 |
+
for idx, row in enumerate(rows):
|
| 129 |
|
| 130 |
+
# Vérification de l'arrêt demandé
|
| 131 |
+
if app_instance.playback_stop:
|
| 132 |
+
print(f"[JALON3] Stop à frame {idx}")
|
| 133 |
+
break
|
| 134 |
+
|
| 135 |
+
# Attente de la reprise en pause
|
| 136 |
+
while app_instance.playback_paused and not app_instance.playback_stop:
|
| 137 |
+
time.sleep(0.01)
|
| 138 |
+
|
| 139 |
+
if app_instance.playback_stop:
|
| 140 |
+
break
|
| 141 |
+
|
| 142 |
+
try:
|
| 143 |
+
# Construction de la pose de la tête
|
| 144 |
+
# x = ouverture de bouche (lèvre du robot)
|
| 145 |
+
# y = position horizontale du visage
|
| 146 |
+
# z = position verticale du visage
|
| 147 |
+
# pitch = inclinaison avant/arrière
|
| 148 |
+
# yaw = rotation gauche/droite
|
| 149 |
+
# roll = inclinaison latérale
|
| 150 |
+
head_pose = create_head_pose(
|
| 151 |
+
x=float(row["bouche"]),
|
| 152 |
+
y=float(row["norm_x"]),
|
| 153 |
+
z=float(row["norm_y"]),
|
| 154 |
+
pitch=float(row["pitch"]),
|
| 155 |
+
yaw=float(row["yaw"]),
|
| 156 |
+
roll=float(row["roll"]),
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
# Angles des antennes
|
| 160 |
+
# oeil g (antenne gauche) et d (antenne droite) en degrés puis conversion en radian pour Reachy
|
| 161 |
+
antennas_rad = np.deg2rad(np.array([float(row["oeil_g"]), float(row["oeil_d"])]))
|
| 162 |
+
|
| 163 |
+
# Envoi de la commande au robot
|
| 164 |
+
robot.set_target(head=head_pose, antennas=antennas_rad)
|
| 165 |
+
|
| 166 |
+
# Syncrhonisation temporelle
|
| 167 |
+
# Calcul en fonction du tps réel et du timestamp csv avant d'envoyer la prochaine frame
|
| 168 |
+
ts = float(row["timestamp"])
|
| 169 |
+
elapsed = time.perf_counter() - start_time
|
| 170 |
+
sleep_time = ts - elapsed
|
| 171 |
+
if sleep_time > 0.001:
|
| 172 |
+
interruptible_sleep(sleep_time, app_instance)
|
| 173 |
+
|
| 174 |
+
except Exception as e:
|
| 175 |
+
print(f"[JALON3] Erreur frame {idx}: {e}")
|
| 176 |
+
|
| 177 |
+
# Arrêter l'audio proprement
|
| 178 |
+
if audio_ok:
|
| 179 |
+
try:
|
| 180 |
+
robot.media.stop_playing()
|
| 181 |
+
except Exception as e:
|
| 182 |
+
print(f"[JALON3] Erreur arrêt audio : {e}")
|
| 183 |
+
|
| 184 |
+
print("[JALON3] Terminé")
|
| 185 |
+
|
| 186 |
+
except Exception as e:
|
| 187 |
+
print(f"[JALON3] Erreur générale: {e}")
|
| 188 |
+
app_instance.playback_ready.set() # Evite le blocage du JS
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
### APP ###
|
| 192 |
app = Coquille()
|
| 193 |
|
| 194 |
+
# Appelle le dossier static pour le navigateur
|
| 195 |
app.settings_app.mount("/static", StaticFiles(directory=STATIC), name="static")
|
| 196 |
|
| 197 |
|
| 198 |
@app.settings_app.get("/")
|
| 199 |
def index():
|
| 200 |
+
# Appelle la page index.html du dossier static
|
| 201 |
return FileResponse(os.path.join(STATIC, "index.html"))
|
| 202 |
|
| 203 |
|
| 204 |
@app.settings_app.get("/favicon.ico")
|
| 205 |
def favicon():
|
| 206 |
+
# Evite les erreurs 404
|
| 207 |
return Response(status_code=204)
|
| 208 |
|
| 209 |
|
| 210 |
@app.settings_app.get("/liste")
|
| 211 |
def liste():
|
| 212 |
+
# Retourne la liste des enregistrements en scannant le dossier csv pour avoir les noms de chaque enregistrement
|
| 213 |
+
noms = [f[:-4] for f in os.listdir(DOSSIER_CSV) if f.endswith(".csv")]
|
| 214 |
return JSONResponse({"noms": noms})
|
| 215 |
|
| 216 |
|
| 217 |
@app.settings_app.post("/charger")
|
| 218 |
async def charger(request: Request):
|
| 219 |
+
# Recoit une video locale pour lancer le pipeline ensuite
|
| 220 |
+
# Sauvegarde la vidéo sur le disque en vdieo_temp.mp4
|
| 221 |
+
# Lance le Jalon2OPTI puis retourne succès ou erreur en fonction
|
| 222 |
form = await request.form()
|
| 223 |
video_file = form.get("video")
|
| 224 |
nom = (form.get("nom") or "").strip()
|
|
|
|
| 226 |
if not video_file or not nom:
|
| 227 |
return JSONResponse({"succes": False, "message": "Vidéo ou nom manquant."}, status_code=400)
|
| 228 |
|
| 229 |
+
# Sauvegarde temporaire de la vidéo chargée
|
| 230 |
video_path = os.path.join(DOSSIER, "video_temp.mp4")
|
|
|
|
| 231 |
with open(video_path, "wb") as f:
|
| 232 |
+
f.write(await video_file.read())
|
| 233 |
|
| 234 |
try:
|
| 235 |
+
subprocess.run(
|
| 236 |
[sys.executable, os.path.join(DOSSIER, "Jalon2OPTI.py"), video_path, nom],
|
| 237 |
+
cwd=DOSSIER, capture_output=True, text=True, check=True, timeout=300
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
)
|
| 239 |
+
print(f"[PIPELINE] OK pour {nom}")
|
| 240 |
+
except subprocess.CalledProcessError:
|
| 241 |
+
return JSONResponse({"succes": False, "message": "Pipeline échoué"}, status_code=500)
|
| 242 |
+
except subprocess.TimeoutExpired:
|
| 243 |
+
return JSONResponse({"succes": False, "message": "Pipeline timeout"}, status_code=500)
|
|
|
|
|
|
|
| 244 |
|
| 245 |
return JSONResponse({"succes": True, "nom": nom})
|
| 246 |
|
| 247 |
|
| 248 |
+
@app.settings_app.post("/supprimer")
|
| 249 |
+
async def supprimer(request: Request):
|
| 250 |
+
# Supprime les fichiers wav video landmarkée et csv d'un enregistrement
|
| 251 |
+
# Si une vidéo n'a par exemple pas d'audio on l'ignore
|
| 252 |
+
data = await request.json()
|
| 253 |
+
nom = data.get("nom")
|
| 254 |
+
if not nom:
|
| 255 |
+
return JSONResponse({"succes": False, "message": "Nom manquant"}, status_code=400)
|
| 256 |
+
|
| 257 |
+
# Suppression de chaque fichier
|
| 258 |
+
for path in [
|
| 259 |
+
os.path.join(DOSSIER_CSV, f"{nom}.csv"),
|
| 260 |
+
os.path.join(DOSSIER_LANDMARKS, f"{nom}(landmarks).mp4"),
|
| 261 |
+
os.path.join(DOSSIER_AUDIO, f"{nom}.wav"),
|
| 262 |
+
]:
|
| 263 |
+
if os.path.exists(path):
|
| 264 |
+
os.remove(path)
|
| 265 |
+
|
| 266 |
+
print(f"[DELETE] {nom} supprimé")
|
| 267 |
+
return JSONResponse({"succes": True})
|
| 268 |
|
| 269 |
|
| 270 |
@app.settings_app.post("/play")
|
| 271 |
async def play(request: Request):
|
| 272 |
+
# Lance un enregistrement sur le robot
|
| 273 |
+
# Dans un premier tps, vérifie sur le csv est présent
|
| 274 |
+
# Réinitialise les play et pause
|
| 275 |
+
# Remet à 0 l'évent du robot pret
|
| 276 |
+
# Lance le rejeu dans un thread pour reachy mini
|
| 277 |
+
|
| 278 |
+
# Le JS interroge le /is-ready pour savoir quand commencer la vidéo
|
| 279 |
data = await request.json()
|
| 280 |
nom = data.get("nom", "").strip()
|
| 281 |
|
| 282 |
if not nom:
|
| 283 |
+
return JSONResponse({"succes": False, "message": "Nom manquant"}, status_code=400)
|
| 284 |
|
| 285 |
csv_path = os.path.join(DOSSIER_CSV, f"{nom}.csv")
|
| 286 |
wav_path = os.path.join(DOSSIER_AUDIO, f"{nom}.wav")
|
| 287 |
|
| 288 |
if not os.path.exists(csv_path):
|
| 289 |
+
return JSONResponse({"succes": False, "message": f"CSV introuvable : {nom}"}, status_code=404)
|
| 290 |
+
|
| 291 |
+
# Réinitialisation de l'état de lecture
|
| 292 |
+
app.playback_paused = False
|
| 293 |
+
app.playback_stop = False
|
| 294 |
+
app.playback_ready.clear() # Reset de l'évent pour pouvoir relancer
|
| 295 |
+
|
| 296 |
+
thread = threading.Thread(target=execute_jalon3_thread, args=(csv_path, wav_path, app), daemon=True)
|
| 297 |
+
thread.start()
|
| 298 |
+
|
| 299 |
+
print(f"[PLAY] Thread lancé pour {nom}")
|
| 300 |
+
return JSONResponse({"succes": True})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
|
| 302 |
|
| 303 |
@app.settings_app.get("/is-ready")
|
| 304 |
async def is_ready():
|
| 305 |
+
# Vérifie si on peut lancer la lecture
|
| 306 |
+
# Si ready=True le JS lance la vidéo en même tps que le rejeu de reachy
|
| 307 |
+
return JSONResponse({"ready": app.playback_ready.is_set()})
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
@app.settings_app.post("/pause")
|
| 311 |
+
async def pause(request: Request):
|
| 312 |
+
# Met la lecture en pause
|
| 313 |
+
app.playback_paused = True
|
| 314 |
+
return JSONResponse({"succes": True})
|
| 315 |
|
| 316 |
|
| 317 |
+
@app.settings_app.post("/resume")
|
| 318 |
+
async def resume(request: Request):
|
| 319 |
+
# Reprend la lecture après une pause
|
| 320 |
+
app.playback_paused = False
|
| 321 |
+
return JSONResponse({"succes": True})
|
|
|
|
| 322 |
|
| 323 |
|
| 324 |
@app.settings_app.post("/stop")
|
| 325 |
+
async def stop(request: Request):
|
| 326 |
+
# Arret complet de la lecture
|
| 327 |
+
app.playback_stop = True
|
| 328 |
return JSONResponse({"succes": True})
|
| 329 |
|
| 330 |
|
| 331 |
@app.settings_app.get("/video/{nom}")
|
| 332 |
def video(nom: str, request: Request):
|
| 333 |
+
# lis la vidéo landmarkée
|
| 334 |
+
path = os.path.join(DOSSIER_LANDMARKS, f"{nom}(landmarks).mp4")
|
| 335 |
+
if not os.path.exists(path):
|
| 336 |
+
return JSONResponse({"succes": False, "message": f"Vidéo introuvable : {nom}"}, status_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
|
| 338 |
file_size = os.path.getsize(path)
|
| 339 |
range_header = request.headers.get("range")
|
| 340 |
|
| 341 |
if range_header:
|
| 342 |
+
start, _, end_str = range_header.replace("bytes=", "").partition("-")
|
| 343 |
+
start = int(start)
|
| 344 |
+
end = int(end_str) if end_str else file_size - 1
|
|
|
|
| 345 |
end = min(end, file_size - 1)
|
| 346 |
+
chunk = end - start + 1
|
| 347 |
|
| 348 |
+
def stream():
|
| 349 |
with open(path, "rb") as f:
|
| 350 |
f.seek(start)
|
| 351 |
+
rem = chunk
|
| 352 |
+
while rem > 0:
|
| 353 |
+
data = f.read(min(65536, rem))
|
| 354 |
+
if not data:
|
| 355 |
break
|
| 356 |
+
rem -= len(data)
|
| 357 |
+
yield data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
+
return StreamingResponse(stream(), status_code=206, media_type="video/mp4", headers={
|
| 360 |
+
"Content-Range": f"bytes {start}-{end}/{file_size}",
|
| 361 |
+
"Accept-Ranges": "bytes",
|
| 362 |
+
"Content-Length": str(chunk),
|
| 363 |
+
})
|
| 364 |
|
| 365 |
+
return FileResponse(path, media_type="video/mp4", headers={"Accept-Ranges": "bytes"})
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
@app.settings_app.post("/telecharger")
|
| 369 |
+
async def telecharger(request: Request):
|
| 370 |
+
# Télécharge une vidéo YouTube dans video_temp.mp4 via yt_dlp
|
| 371 |
+
# la vidéo est sauvegardée en vidéo_temp qu'on utilisera pour la lancer dans le navigateur
|
| 372 |
+
data = await request.json()
|
| 373 |
+
url = data.get("url", "").strip()
|
| 374 |
+
if not url:
|
| 375 |
+
return JSONResponse({"succes": False, "message": "URL manquante."}, status_code=400)
|
| 376 |
+
|
| 377 |
+
video_path = os.path.join(DOSSIER, "video_temp.mp4")
|
| 378 |
+
if os.path.exists(video_path):
|
| 379 |
+
os.remove(video_path) # Supprime une ancienne vidéo temp pour qu'elle soit bien temporaire
|
| 380 |
try:
|
| 381 |
+
ydl_opts = {
|
| 382 |
+
"outtmpl": video_path, # Chemin de sortie
|
| 383 |
+
# Fusion de l'audio et de la vidéo et choix des meilleurs qualités de vidéo
|
| 384 |
+
"format": "mp4/bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]",
|
| 385 |
+
"merge_output_format": "mp4",
|
| 386 |
+
}
|
| 387 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 388 |
+
ydl.download([url])
|
| 389 |
+
except Exception as e:
|
| 390 |
+
return JSONResponse({"succes": False, "message": str(e)}, status_code=500)
|
| 391 |
+
|
| 392 |
+
return JSONResponse({"succes": True})
|
| 393 |
|
| 394 |
+
|
| 395 |
+
@app.settings_app.post("/lancer-youtube")
|
| 396 |
+
async def lancer_youtube(request: Request):
|
| 397 |
+
# Lance Jalon2OPTI sur la video_temp.mp4 déjà téléchargée
|
| 398 |
+
# Séparé de /telecharger pour permettre au JS d'attendre la fin du téléchargement avant de demander le traitement (qui peut être long).
|
| 399 |
+
data = await request.json()
|
| 400 |
nom = (data.get("nom") or "").strip()
|
| 401 |
if not nom:
|
| 402 |
return JSONResponse({"succes": False, "message": "Nom manquant."}, status_code=400)
|
| 403 |
|
| 404 |
+
video_path = os.path.join(DOSSIER, "video_temp.mp4")
|
| 405 |
+
if not os.path.exists(video_path):
|
| 406 |
+
return JSONResponse({"succes": False, "message": "Aucune vidéo téléchargée."}, status_code=404)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
+
try:
|
| 409 |
+
subprocess.run(
|
| 410 |
+
[sys.executable, os.path.join(DOSSIER, "Jalon2OPTI.py"), video_path, nom],
|
| 411 |
+
cwd=DOSSIER, capture_output=True, text=True,
|
| 412 |
+
encoding="utf-8", errors="replace", check=True
|
| 413 |
+
)
|
| 414 |
+
print(f"[PIPELINE] OK pour {nom}")
|
| 415 |
+
except subprocess.CalledProcessError as e:
|
| 416 |
+
return JSONResponse({
|
| 417 |
+
"succes": False,
|
| 418 |
+
"message": e.stderr or e.stdout or "erreur inconnue"
|
| 419 |
+
}, status_code=500)
|
| 420 |
|
| 421 |
+
return JSONResponse({"succes": True, "nom": nom})
|
| 422 |
|
| 423 |
|
| 424 |
if __name__ == "__main__":
|
| 425 |
import uvicorn
|
| 426 |
+
|
| 427 |
+
# Lance le thread de connexion robot en arrière-plan (daemon=True : s'arrête automatiquement à la fermeture du processus principal)
|
| 428 |
+
threading.Thread(target=app.wrapped_run, daemon=True).start()
|
| 429 |
+
|
| 430 |
+
# Démarre le serveur HTTP FastAPI sur le port 8042
|
| 431 |
uvicorn.run(app.settings_app, host="127.0.0.1", port=8042)
|
coquille/static/index.html
CHANGED
|
@@ -8,18 +8,14 @@
|
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Syne:wght@400;600;700&display=swap" rel="stylesheet">
|
| 10 |
<link rel="stylesheet" href="/static/style.css">
|
|
|
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
|
| 14 |
<header>
|
| 15 |
<div class="header-left">
|
| 16 |
<span class="logo-mark"></span>
|
| 17 |
-
<span class="logo-text">
|
| 18 |
-
</div>
|
| 19 |
-
<div class="header-right">
|
| 20 |
-
<span class="status-indicator" id="daemon-status">
|
| 21 |
-
<span class="dot"></span>daemon offline
|
| 22 |
-
</span>
|
| 23 |
</div>
|
| 24 |
</header>
|
| 25 |
|
|
@@ -27,29 +23,43 @@
|
|
| 27 |
|
| 28 |
<section class="panel" id="panel-source">
|
| 29 |
<div class="panel-label">01 — source</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
<div class="video-zone" id="video-zone">
|
| 32 |
<div class="video-placeholder" id="video-placeholder">
|
| 33 |
<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.2">
|
| 34 |
<path d="M15 10l4.553-2.069A1 1 0 0121 8.87v6.26a1 1 0 01-1.447.894L15 14M3 8a2 2 0 012-2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V8z"/>
|
| 35 |
</svg>
|
| 36 |
-
<span>
|
| 37 |
</div>
|
| 38 |
<video id="video-preview" style="display:none;" controls></video>
|
| 39 |
</div>
|
| 40 |
|
|
|
|
|
|
|
| 41 |
<div class="input-row">
|
| 42 |
-
<input type="text" id="recording-name" placeholder="
|
| 43 |
-
<
|
| 44 |
-
<
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
</div>
|
| 49 |
|
| 50 |
<button class="btn btn-primary" id="btn-run" disabled>
|
| 51 |
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
| 52 |
-
|
| 53 |
</button>
|
| 54 |
</section>
|
| 55 |
|
|
@@ -62,7 +72,7 @@
|
|
| 62 |
</main>
|
| 63 |
|
| 64 |
<footer>
|
| 65 |
-
<div class="status-line" id="status-line">
|
| 66 |
<div class="progress-bar" id="progress-bar"></div>
|
| 67 |
</footer>
|
| 68 |
|
|
|
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@300;400;500&family=Syne:wght@400;600;700&display=swap" rel="stylesheet">
|
| 10 |
<link rel="stylesheet" href="/static/style.css">
|
| 11 |
+
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
|
| 15 |
<header>
|
| 16 |
<div class="header-left">
|
| 17 |
<span class="logo-mark"></span>
|
| 18 |
+
<span class="logo-text">les<em>tal</em></span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</div>
|
| 20 |
</header>
|
| 21 |
|
|
|
|
| 23 |
|
| 24 |
<section class="panel" id="panel-source">
|
| 25 |
<div class="panel-label">01 — source</div>
|
| 26 |
+
<div id = "local-or-video">
|
| 27 |
+
<button class = "btn" id = "local-video">Vidéo locale</button>
|
| 28 |
+
<button class = "btn" id = "youtube-video">Vidéo youtube</button>
|
| 29 |
+
</div>
|
| 30 |
|
| 31 |
<div class="video-zone" id="video-zone">
|
| 32 |
<div class="video-placeholder" id="video-placeholder">
|
| 33 |
<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.2">
|
| 34 |
<path d="M15 10l4.553-2.069A1 1 0 0121 8.87v6.26a1 1 0 01-1.447.894L15 14M3 8a2 2 0 012-2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V8z"/>
|
| 35 |
</svg>
|
| 36 |
+
<span>Aucune vidéo</span>
|
| 37 |
</div>
|
| 38 |
<video id="video-preview" style="display:none;" controls></video>
|
| 39 |
</div>
|
| 40 |
|
| 41 |
+
<input type="text" id="video-link" placeholder="Lien de la vidéo" autocomplete="off" />
|
| 42 |
+
|
| 43 |
<div class="input-row">
|
| 44 |
+
<input type="text" id="recording-name" placeholder="Nom de l'enregistrement" autocomplete="off" />
|
| 45 |
+
<div id = load-local>
|
| 46 |
+
<label class="btn btn-ghost" for="file-input">
|
| 47 |
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4M17 8l-5-5-5 5M12 3v12"/></svg>
|
| 48 |
+
Charger
|
| 49 |
+
</label>
|
| 50 |
+
<input type="file" id="file-input" accept="video/*" style="display:none;" />
|
| 51 |
+
</div>
|
| 52 |
+
<button id = load-youtube>
|
| 53 |
+
<label class="btn btn-ghost">
|
| 54 |
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4M17 8l-5-5-5 5M12 3v12"/></svg>
|
| 55 |
+
Charger
|
| 56 |
+
</label>
|
| 57 |
+
</button>
|
| 58 |
</div>
|
| 59 |
|
| 60 |
<button class="btn btn-primary" id="btn-run" disabled>
|
| 61 |
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
|
| 62 |
+
Lancer le pipeline
|
| 63 |
</button>
|
| 64 |
</section>
|
| 65 |
|
|
|
|
| 72 |
</main>
|
| 73 |
|
| 74 |
<footer>
|
| 75 |
+
<div class="status-line" id="status-line">En attente</div>
|
| 76 |
<div class="progress-bar" id="progress-bar"></div>
|
| 77 |
</footer>
|
| 78 |
|
coquille/static/main.js
CHANGED
|
@@ -1,36 +1,88 @@
|
|
| 1 |
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
| 2 |
const fileInput = document.getElementById('file-input');
|
| 3 |
const runBtn = document.getElementById('btn-run');
|
| 4 |
const nameInput = document.getElementById('recording-name');
|
| 5 |
const preview = document.getElementById('video-preview');
|
| 6 |
const placeholder = document.getElementById('video-placeholder');
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
let selectedFile = null;
|
| 9 |
|
| 10 |
-
//
|
| 11 |
chargerBibliotheque();
|
| 12 |
|
| 13 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
fileInput.addEventListener('change', (e) => {
|
| 15 |
const file = e.target.files[0];
|
| 16 |
if (!file) return;
|
| 17 |
-
|
| 18 |
selectedFile = file;
|
|
|
|
| 19 |
preview.src = URL.createObjectURL(file);
|
| 20 |
preview.style.display = 'block';
|
| 21 |
placeholder.style.display = 'none';
|
| 22 |
-
|
| 23 |
runBtn.disabled = false;
|
| 24 |
updateStatus(`Vidéo prête : ${file.name}`, 'active');
|
| 25 |
});
|
| 26 |
|
| 27 |
-
//
|
| 28 |
runBtn.addEventListener('click', async () => {
|
|
|
|
| 29 |
const nom = nameInput.value.trim();
|
| 30 |
if (!nom) return updateStatus("Donnez un nom à l'enregistrement", 'error');
|
| 31 |
-
if (!selectedFile) return updateStatus("Chargez une vidéo d'abord", 'error');
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
try {
|
| 35 |
const responsescv = await fetch('/liste');
|
| 36 |
if (!responsescv.ok) throw new Error();
|
|
@@ -46,41 +98,45 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 46 |
updateStatus("Extraction des landmarks et génération des mouvements...", 'active');
|
| 47 |
setProgress(30);
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
try {
|
| 54 |
-
console.log("[DEBUG] Envoi POST à /charger...");
|
| 55 |
-
const response = await fetch('/charger', { method: 'POST', body: formData });
|
| 56 |
-
console.log("[DEBUG] Réponse reçue, status:", response.status);
|
| 57 |
-
|
| 58 |
if (!response.ok) {
|
| 59 |
-
console.error("[ERROR] Serveur retourne:", response.status, response.statusText);
|
| 60 |
const text = await response.text();
|
| 61 |
-
console.error("[ERROR] Body:", text);
|
| 62 |
updateStatus(`Erreur serveur (${response.status}): ${text}`, 'error');
|
| 63 |
runBtn.disabled = false;
|
| 64 |
return;
|
| 65 |
}
|
| 66 |
|
| 67 |
const data = await response.json();
|
| 68 |
-
console.log("[DEBUG] Données reçues:", data);
|
| 69 |
|
| 70 |
if (data.succes) {
|
| 71 |
setProgress(100);
|
| 72 |
updateStatus(`Enregistrement "${nom}" ajouté ! Lancement de la vidéo...`, 'done');
|
| 73 |
|
| 74 |
-
//
|
| 75 |
setTimeout(() => {
|
| 76 |
preview.src = `/video/${encodeURIComponent(nom)}?t=${Date.now()}`;
|
| 77 |
preview.style.display = 'block';
|
| 78 |
placeholder.style.display = 'none';
|
| 79 |
|
| 80 |
const playVideo = () => {
|
| 81 |
-
preview.play().catch(() => {
|
| 82 |
-
preview.controls = true;
|
| 83 |
-
});
|
| 84 |
};
|
| 85 |
|
| 86 |
if (preview.readyState >= 3) {
|
|
@@ -91,7 +147,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 91 |
|
| 92 |
nameInput.value = '';
|
| 93 |
selectedFile = null;
|
| 94 |
-
chargerBibliotheque();
|
| 95 |
}, 500);
|
| 96 |
} else {
|
| 97 |
setProgress(0);
|
|
@@ -99,7 +155,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 99 |
}
|
| 100 |
} catch (err) {
|
| 101 |
setProgress(0);
|
| 102 |
-
console.error("[ERROR] Exception:", err);
|
| 103 |
updateStatus(`Erreur: ${err.message}`, 'error');
|
| 104 |
} finally {
|
| 105 |
runBtn.disabled = false;
|
|
@@ -107,8 +162,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
| 107 |
});
|
| 108 |
});
|
| 109 |
|
| 110 |
-
//
|
| 111 |
|
|
|
|
| 112 |
async function chargerBibliotheque() {
|
| 113 |
try {
|
| 114 |
const response = await fetch('/liste');
|
|
@@ -122,7 +178,6 @@ async function chargerBibliotheque() {
|
|
| 122 |
data.noms.forEach((nom, i) => {
|
| 123 |
const item = document.createElement('li');
|
| 124 |
item.className = 'library-item';
|
| 125 |
-
// [AJOUT DU COLLÈGUE] : Intégration des deux boutons côte à côte avec ses classes CSS
|
| 126 |
item.innerHTML = `
|
| 127 |
<span class="item-index">${String(i + 1).padStart(2, '0')}</span>
|
| 128 |
<span class="item-name">${nom}</span>
|
|
@@ -133,10 +188,12 @@ async function chargerBibliotheque() {
|
|
| 133 |
});
|
| 134 |
}
|
| 135 |
} catch (err) {
|
| 136 |
-
console.error("Erreur de chargement de la bibliothèque
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
|
|
|
|
|
|
| 140 |
async function playRecording(nom, btn) {
|
| 141 |
document.querySelectorAll('.library-item').forEach(el => el.classList.remove('playing'));
|
| 142 |
document.querySelectorAll('.btn-play').forEach(b => {
|
|
@@ -153,20 +210,18 @@ async function playRecording(nom, btn) {
|
|
| 153 |
const preview = document.getElementById('video-preview');
|
| 154 |
const placeholder = document.getElementById('video-placeholder');
|
| 155 |
|
| 156 |
-
// [TA MODIF] : Masquer la vidéo pendant l'attente, on retire le src
|
| 157 |
preview.pause();
|
| 158 |
preview.removeAttribute('src');
|
| 159 |
preview.load();
|
| 160 |
|
| 161 |
-
//
|
| 162 |
-
let simData;
|
| 163 |
try {
|
| 164 |
const simResp = await fetch('/play', {
|
| 165 |
method: 'POST',
|
| 166 |
headers: { 'Content-Type': 'application/json' },
|
| 167 |
-
body: JSON.stringify({ nom
|
| 168 |
});
|
| 169 |
-
simData = await simResp.json();
|
| 170 |
if (!simData.succes) {
|
| 171 |
setProgress(0);
|
| 172 |
updateStatus(`Erreur simulation : ${simData.message}`, 'error');
|
|
@@ -184,10 +239,9 @@ async function playRecording(nom, btn) {
|
|
| 184 |
return;
|
| 185 |
}
|
| 186 |
|
| 187 |
-
console.log('[PLAY] Polling /is-ready — ' + new Date().toISOString());
|
| 188 |
updateStatus(`En attente du signal robot...`, 'active');
|
| 189 |
|
| 190 |
-
//
|
| 191 |
const POLL_INTERVAL = 250;
|
| 192 |
const POLL_TIMEOUT = 60000;
|
| 193 |
const pollStart = Date.now();
|
|
@@ -196,19 +250,15 @@ async function playRecording(nom, btn) {
|
|
| 196 |
await new Promise((resolve, reject) => {
|
| 197 |
const poll = async () => {
|
| 198 |
if (Date.now() - pollStart > POLL_TIMEOUT) {
|
| 199 |
-
return reject(new Error(
|
| 200 |
}
|
| 201 |
try {
|
| 202 |
const r = await fetch('/is-ready');
|
| 203 |
const d = await r.json();
|
| 204 |
const elapsed = ((Date.now() - pollStart) / 1000).toFixed(1);
|
| 205 |
-
updateStatus(`En attente du signal robot
|
| 206 |
-
if (d.ready)
|
| 207 |
-
|
| 208 |
-
resolve();
|
| 209 |
-
} else {
|
| 210 |
-
setTimeout(poll, POLL_INTERVAL);
|
| 211 |
-
}
|
| 212 |
} catch (e) {
|
| 213 |
setTimeout(poll, POLL_INTERVAL);
|
| 214 |
}
|
|
@@ -224,9 +274,7 @@ async function playRecording(nom, btn) {
|
|
| 224 |
return;
|
| 225 |
}
|
| 226 |
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
// Attribution finale de la source après le feu vert du serveur
|
| 230 |
preview.src = `/video/${encodeURIComponent(nom)}`;
|
| 231 |
preview.style.display = 'block';
|
| 232 |
placeholder.style.display = 'none';
|
|
@@ -237,12 +285,11 @@ async function playRecording(nom, btn) {
|
|
| 237 |
preview.load();
|
| 238 |
});
|
| 239 |
|
| 240 |
-
|
| 241 |
-
preview.play().catch(e => { console.error('[PLAY] play() refusé:', e); preview.controls = true; });
|
| 242 |
setProgress(100);
|
| 243 |
updateStatus(`Lecture en cours...`, 'done');
|
| 244 |
|
| 245 |
-
//
|
| 246 |
preview.onended = () => {
|
| 247 |
btn.classList.remove('active');
|
| 248 |
btn.textContent = 'play';
|
|
@@ -252,31 +299,26 @@ async function playRecording(nom, btn) {
|
|
| 252 |
};
|
| 253 |
}
|
| 254 |
|
|
|
|
|
|
|
| 255 |
function updateStatus(msg, type) {
|
| 256 |
const el = document.getElementById('status-line');
|
| 257 |
-
if (el) {
|
| 258 |
-
el.textContent = msg;
|
| 259 |
-
el.className = `status-line ${type}`;
|
| 260 |
-
}
|
| 261 |
}
|
| 262 |
|
| 263 |
-
// Gestion de la barre de progression
|
| 264 |
function setProgress(pct) {
|
| 265 |
const bar = document.getElementById('progress-bar');
|
| 266 |
if (bar) {
|
| 267 |
bar.style.width = `${pct}%`;
|
| 268 |
-
if (pct === 100) {
|
| 269 |
-
setTimeout(() => { bar.style.width = '0%'; }, 1200);
|
| 270 |
-
}
|
| 271 |
}
|
| 272 |
}
|
| 273 |
|
| 274 |
-
//
|
| 275 |
async function deleteRecording(nom) {
|
| 276 |
const preview = document.getElementById('video-preview');
|
| 277 |
const placeholder = document.getElementById('video-placeholder');
|
| 278 |
|
| 279 |
-
// Si la vidéo en train d'être jouée est supprimée, on réinitialise l'affichage
|
| 280 |
if (preview.src.includes(encodeURIComponent(nom))) {
|
| 281 |
preview.pause();
|
| 282 |
preview.src = '';
|
|
@@ -291,16 +333,16 @@ async function deleteRecording(nom) {
|
|
| 291 |
const response = await fetch('/supprimer', {
|
| 292 |
method: 'POST',
|
| 293 |
headers: { 'Content-Type': 'application/json' },
|
| 294 |
-
body: JSON.stringify({ nom
|
| 295 |
});
|
| 296 |
const data = await response.json();
|
| 297 |
if (data.succes) {
|
| 298 |
-
updateStatus(
|
| 299 |
-
chargerBibliotheque();
|
| 300 |
} else {
|
| 301 |
-
updateStatus(
|
| 302 |
}
|
| 303 |
} catch (err) {
|
| 304 |
-
updateStatus(
|
| 305 |
}
|
| 306 |
}
|
|
|
|
| 1 |
document.addEventListener("DOMContentLoaded", () => {
|
| 2 |
+
// Récup de tous les éléments du HTML
|
| 3 |
const fileInput = document.getElementById('file-input');
|
| 4 |
const runBtn = document.getElementById('btn-run');
|
| 5 |
const nameInput = document.getElementById('recording-name');
|
| 6 |
const preview = document.getElementById('video-preview');
|
| 7 |
const placeholder = document.getElementById('video-placeholder');
|
| 8 |
+
const localVideo = document.getElementById('local-video');
|
| 9 |
+
const youtubeVideo = document.getElementById('youtube-video');
|
| 10 |
+
const videoLink = document.getElementById('video-link');
|
| 11 |
+
const loadLocal = document.getElementById('load-local');
|
| 12 |
+
const loadYoutube = document.getElementById('load-youtube');
|
| 13 |
let selectedFile = null;
|
| 14 |
|
| 15 |
+
// Charge la bibliothèque des vidéos déjà analysées
|
| 16 |
chargerBibliotheque();
|
| 17 |
|
| 18 |
+
// Affichage selection entre mode local et yt
|
| 19 |
+
localVideo.addEventListener('click', () =>{
|
| 20 |
+
videoLink.style.display = "none";
|
| 21 |
+
loadLocal.style.display = "block";
|
| 22 |
+
loadYoutube.style.display = "none";
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
youtubeVideo.addEventListener('click', () =>{
|
| 26 |
+
videoLink.style.display = "block";
|
| 27 |
+
loadLocal.style.display = "none";
|
| 28 |
+
loadYoutube.style.display = "block";
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
// Permet de télécharger une vidéo yt
|
| 32 |
+
loadYoutube.addEventListener('click', async () => {
|
| 33 |
+
const link = videoLink.value.trim();
|
| 34 |
+
if (!link) return updateStatus("Entrez le lien d'une vidéo youtube", 'error');
|
| 35 |
+
|
| 36 |
+
updateStatus("Téléchargement en cours...", 'active');
|
| 37 |
+
setProgress(20);
|
| 38 |
+
loadYoutube.disabled = true;
|
| 39 |
+
|
| 40 |
+
try {
|
| 41 |
+
// Appelle l'api python pour télécharger
|
| 42 |
+
const response = await fetch('/telecharger', {
|
| 43 |
+
method: 'POST',
|
| 44 |
+
headers: { 'Content-Type': 'application/json' },
|
| 45 |
+
body: JSON.stringify({ url: link }) // On envoie l'url au serveur
|
| 46 |
+
});
|
| 47 |
+
const data = await response.json();
|
| 48 |
+
if (data.succes) {
|
| 49 |
+
setProgress(60);
|
| 50 |
+
updateStatus("Vidéo téléchargée — donnez un nom et lancez le pipeline", 'done');
|
| 51 |
+
runBtn.disabled = false; // le bouton lancer le pipeline est débloqué
|
| 52 |
+
} else {
|
| 53 |
+
setProgress(0);
|
| 54 |
+
updateStatus(`Erreur téléchargement : ${data.message}`, 'error');
|
| 55 |
+
}
|
| 56 |
+
} catch (err) {
|
| 57 |
+
setProgress(0);
|
| 58 |
+
updateStatus(`Erreur : ${err.message}`, 'error');
|
| 59 |
+
} finally {
|
| 60 |
+
loadYoutube.disabled = false;
|
| 61 |
+
}
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// Charger une vidéo sur son pc en local
|
| 65 |
fileInput.addEventListener('change', (e) => {
|
| 66 |
const file = e.target.files[0];
|
| 67 |
if (!file) return;
|
|
|
|
| 68 |
selectedFile = file;
|
| 69 |
+
// Permet de lire la vidéo dans le navigateur
|
| 70 |
preview.src = URL.createObjectURL(file);
|
| 71 |
preview.style.display = 'block';
|
| 72 |
placeholder.style.display = 'none';
|
|
|
|
| 73 |
runBtn.disabled = false;
|
| 74 |
updateStatus(`Vidéo prête : ${file.name}`, 'active');
|
| 75 |
});
|
| 76 |
|
| 77 |
+
// Lancer le pipeline
|
| 78 |
runBtn.addEventListener('click', async () => {
|
| 79 |
+
// Différentes vérif : si la vidéo est chargée, a un nom ou si c'est un double
|
| 80 |
const nom = nameInput.value.trim();
|
| 81 |
if (!nom) return updateStatus("Donnez un nom à l'enregistrement", 'error');
|
|
|
|
| 82 |
|
| 83 |
+
const isYoutube = loadYoutube.style.display === "block";
|
| 84 |
+
if (!isYoutube && !selectedFile) return updateStatus("Chargez une vidéo d'abord", 'error');
|
| 85 |
+
|
| 86 |
try {
|
| 87 |
const responsescv = await fetch('/liste');
|
| 88 |
if (!responsescv.ok) throw new Error();
|
|
|
|
| 98 |
updateStatus("Extraction des landmarks et génération des mouvements...", 'active');
|
| 99 |
setProgress(30);
|
| 100 |
|
| 101 |
+
let response;
|
| 102 |
+
// Si vidéo yt
|
| 103 |
+
if (isYoutube) {
|
| 104 |
+
// lance la vidéo car déjà sur le serv
|
| 105 |
+
response = await fetch('/lancer-youtube', {
|
| 106 |
+
method: 'POST',
|
| 107 |
+
headers: { 'Content-Type': 'application/json' },
|
| 108 |
+
body: JSON.stringify({ nom })
|
| 109 |
+
});
|
| 110 |
+
} else {
|
| 111 |
+
// sinon fichier local donc il faut l'envoyer sur le serveur (upload)
|
| 112 |
+
const formData = new FormData();
|
| 113 |
+
formData.append('video', selectedFile);
|
| 114 |
+
formData.append('nom', nom);
|
| 115 |
+
response = await fetch('/charger', { method: 'POST', body: formData });
|
| 116 |
+
}
|
| 117 |
|
| 118 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
if (!response.ok) {
|
|
|
|
| 120 |
const text = await response.text();
|
|
|
|
| 121 |
updateStatus(`Erreur serveur (${response.status}): ${text}`, 'error');
|
| 122 |
runBtn.disabled = false;
|
| 123 |
return;
|
| 124 |
}
|
| 125 |
|
| 126 |
const data = await response.json();
|
|
|
|
| 127 |
|
| 128 |
if (data.succes) {
|
| 129 |
setProgress(100);
|
| 130 |
updateStatus(`Enregistrement "${nom}" ajouté ! Lancement de la vidéo...`, 'done');
|
| 131 |
|
| 132 |
+
// Mise à jour du cadre vidéo : le lecteur va lire la vidéo analysée avec les landmarks
|
| 133 |
setTimeout(() => {
|
| 134 |
preview.src = `/video/${encodeURIComponent(nom)}?t=${Date.now()}`;
|
| 135 |
preview.style.display = 'block';
|
| 136 |
placeholder.style.display = 'none';
|
| 137 |
|
| 138 |
const playVideo = () => {
|
| 139 |
+
preview.play().catch(() => { preview.controls = true; });
|
|
|
|
|
|
|
| 140 |
};
|
| 141 |
|
| 142 |
if (preview.readyState >= 3) {
|
|
|
|
| 147 |
|
| 148 |
nameInput.value = '';
|
| 149 |
selectedFile = null;
|
| 150 |
+
chargerBibliotheque(); // Bibliothèque rafraichieavec le nouvel enregistrement
|
| 151 |
}, 500);
|
| 152 |
} else {
|
| 153 |
setProgress(0);
|
|
|
|
| 155 |
}
|
| 156 |
} catch (err) {
|
| 157 |
setProgress(0);
|
|
|
|
| 158 |
updateStatus(`Erreur: ${err.message}`, 'error');
|
| 159 |
} finally {
|
| 160 |
runBtn.disabled = false;
|
|
|
|
| 162 |
});
|
| 163 |
});
|
| 164 |
|
| 165 |
+
// Bibliothèque sur le côté droit
|
| 166 |
|
| 167 |
+
// Récupère la liste des vidéos enregistrées sur le serveur pour ajouter des éléments li HTML
|
| 168 |
async function chargerBibliotheque() {
|
| 169 |
try {
|
| 170 |
const response = await fetch('/liste');
|
|
|
|
| 178 |
data.noms.forEach((nom, i) => {
|
| 179 |
const item = document.createElement('li');
|
| 180 |
item.className = 'library-item';
|
|
|
|
| 181 |
item.innerHTML = `
|
| 182 |
<span class="item-index">${String(i + 1).padStart(2, '0')}</span>
|
| 183 |
<span class="item-name">${nom}</span>
|
|
|
|
| 188 |
});
|
| 189 |
}
|
| 190 |
} catch (err) {
|
| 191 |
+
console.error("Erreur de chargement de la bibliothèque", err);
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|
| 195 |
+
|
| 196 |
+
// Jouer la vidéo qu'on veut sur le robot
|
| 197 |
async function playRecording(nom, btn) {
|
| 198 |
document.querySelectorAll('.library-item').forEach(el => el.classList.remove('playing'));
|
| 199 |
document.querySelectorAll('.btn-play').forEach(b => {
|
|
|
|
| 210 |
const preview = document.getElementById('video-preview');
|
| 211 |
const placeholder = document.getElementById('video-placeholder');
|
| 212 |
|
|
|
|
| 213 |
preview.pause();
|
| 214 |
preview.removeAttribute('src');
|
| 215 |
preview.load();
|
| 216 |
|
| 217 |
+
// Le serveur prépare le robot avec le fichier qu'on veut
|
|
|
|
| 218 |
try {
|
| 219 |
const simResp = await fetch('/play', {
|
| 220 |
method: 'POST',
|
| 221 |
headers: { 'Content-Type': 'application/json' },
|
| 222 |
+
body: JSON.stringify({ nom })
|
| 223 |
});
|
| 224 |
+
const simData = await simResp.json();
|
| 225 |
if (!simData.succes) {
|
| 226 |
setProgress(0);
|
| 227 |
updateStatus(`Erreur simulation : ${simData.message}`, 'error');
|
|
|
|
| 239 |
return;
|
| 240 |
}
|
| 241 |
|
|
|
|
| 242 |
updateStatus(`En attente du signal robot...`, 'active');
|
| 243 |
|
| 244 |
+
// Toutes les 250ms on demande au serveur si il y'a un Reachy, ça va permettre d'avoir un rejeu de Reachy synchronisée avec le lancement de la vidéo
|
| 245 |
const POLL_INTERVAL = 250;
|
| 246 |
const POLL_TIMEOUT = 60000;
|
| 247 |
const pollStart = Date.now();
|
|
|
|
| 250 |
await new Promise((resolve, reject) => {
|
| 251 |
const poll = async () => {
|
| 252 |
if (Date.now() - pollStart > POLL_TIMEOUT) {
|
| 253 |
+
return reject(new Error("Timeout : le robot n'a pas répondu dans les 60s"));
|
| 254 |
}
|
| 255 |
try {
|
| 256 |
const r = await fetch('/is-ready');
|
| 257 |
const d = await r.json();
|
| 258 |
const elapsed = ((Date.now() - pollStart) / 1000).toFixed(1);
|
| 259 |
+
updateStatus(`En attente du signal robot… ${elapsed}s`, 'active');
|
| 260 |
+
if (d.ready) resolve(); // le robot est pret
|
| 261 |
+
else setTimeout(poll, POLL_INTERVAL); // Sinon on lui redemande
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
} catch (e) {
|
| 263 |
setTimeout(poll, POLL_INTERVAL);
|
| 264 |
}
|
|
|
|
| 274 |
return;
|
| 275 |
}
|
| 276 |
|
| 277 |
+
// Le robot est pret donc on lance la vidéo landmarkée dans le navigateur
|
|
|
|
|
|
|
| 278 |
preview.src = `/video/${encodeURIComponent(nom)}`;
|
| 279 |
preview.style.display = 'block';
|
| 280 |
placeholder.style.display = 'none';
|
|
|
|
| 285 |
preview.load();
|
| 286 |
});
|
| 287 |
|
| 288 |
+
preview.play().catch(e => { preview.controls = true; });
|
|
|
|
| 289 |
setProgress(100);
|
| 290 |
updateStatus(`Lecture en cours...`, 'done');
|
| 291 |
|
| 292 |
+
// Quand la vidéo est finie, le robot s'arrête
|
| 293 |
preview.onended = () => {
|
| 294 |
btn.classList.remove('active');
|
| 295 |
btn.textContent = 'play';
|
|
|
|
| 299 |
};
|
| 300 |
}
|
| 301 |
|
| 302 |
+
|
| 303 |
+
// Infos et barre de progression sur l'avancement de l'action qu'on effectue,
|
| 304 |
function updateStatus(msg, type) {
|
| 305 |
const el = document.getElementById('status-line');
|
| 306 |
+
if (el) { el.textContent = msg; el.className = `status-line ${type}`; }
|
|
|
|
|
|
|
|
|
|
| 307 |
}
|
| 308 |
|
|
|
|
| 309 |
function setProgress(pct) {
|
| 310 |
const bar = document.getElementById('progress-bar');
|
| 311 |
if (bar) {
|
| 312 |
bar.style.width = `${pct}%`;
|
| 313 |
+
if (pct === 100) setTimeout(() => { bar.style.width = '0%'; }, 1200);
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
}
|
| 316 |
|
| 317 |
+
// Supprimer un enregistrement de la bibliothèque
|
| 318 |
async function deleteRecording(nom) {
|
| 319 |
const preview = document.getElementById('video-preview');
|
| 320 |
const placeholder = document.getElementById('video-placeholder');
|
| 321 |
|
|
|
|
| 322 |
if (preview.src.includes(encodeURIComponent(nom))) {
|
| 323 |
preview.pause();
|
| 324 |
preview.src = '';
|
|
|
|
| 333 |
const response = await fetch('/supprimer', {
|
| 334 |
method: 'POST',
|
| 335 |
headers: { 'Content-Type': 'application/json' },
|
| 336 |
+
body: JSON.stringify({ nom })
|
| 337 |
});
|
| 338 |
const data = await response.json();
|
| 339 |
if (data.succes) {
|
| 340 |
+
updateStatus(`"${nom}" supprimé.`, 'done');
|
| 341 |
+
chargerBibliotheque(); // Refresh de la bibliothèque
|
| 342 |
} else {
|
| 343 |
+
updateStatus(`Erreur suppression : ${data.message}`, 'error');
|
| 344 |
}
|
| 345 |
} catch (err) {
|
| 346 |
+
updateStatus(`Erreur : ${err.message}`, 'error');
|
| 347 |
}
|
| 348 |
}
|
coquille/static/style.css
CHANGED
|
@@ -68,26 +68,6 @@ header {
|
|
| 68 |
color: var(--accent);
|
| 69 |
}
|
| 70 |
|
| 71 |
-
.status-indicator {
|
| 72 |
-
display: flex;
|
| 73 |
-
align-items: center;
|
| 74 |
-
gap: 7px;
|
| 75 |
-
font-size: 11px;
|
| 76 |
-
color: var(--text-secondary);
|
| 77 |
-
letter-spacing: 0.04em;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
.status-indicator .dot {
|
| 81 |
-
width: 6px;
|
| 82 |
-
height: 6px;
|
| 83 |
-
border-radius: 50%;
|
| 84 |
-
background: var(--text-muted);
|
| 85 |
-
transition: background 0.3s;
|
| 86 |
-
}
|
| 87 |
-
|
| 88 |
-
.status-indicator.online .dot { background: var(--accent); }
|
| 89 |
-
.status-indicator.online { color: var(--accent-dim); }
|
| 90 |
-
|
| 91 |
main {
|
| 92 |
display: grid;
|
| 93 |
grid-template-columns: 1fr 1fr;
|
|
@@ -121,7 +101,7 @@ main {
|
|
| 121 |
border-radius: var(--radius-lg);
|
| 122 |
overflow: hidden;
|
| 123 |
position: relative;
|
| 124 |
-
min-height: 0
|
| 125 |
}
|
| 126 |
|
| 127 |
.video-placeholder {
|
|
@@ -140,7 +120,7 @@ main {
|
|
| 140 |
#video-preview {
|
| 141 |
width: 100%;
|
| 142 |
height: 100%;
|
| 143 |
-
object-fit:
|
| 144 |
display: block;
|
| 145 |
}
|
| 146 |
|
|
@@ -171,6 +151,15 @@ input[type="text"]::placeholder {
|
|
| 171 |
color: var(--text-muted);
|
| 172 |
}
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
.btn {
|
| 175 |
display: inline-flex;
|
| 176 |
align-items: center;
|
|
@@ -223,6 +212,14 @@ input[type="text"]::placeholder {
|
|
| 223 |
background: transparent;
|
| 224 |
}
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
.library-list {
|
| 227 |
list-style: none;
|
| 228 |
display: flex;
|
|
@@ -297,13 +294,6 @@ input[type="text"]::placeholder {
|
|
| 297 |
background: var(--accent-bg);
|
| 298 |
}
|
| 299 |
|
| 300 |
-
/* Petit ajout pour différencier le bouton de suppression au survol */
|
| 301 |
-
.btn-delete:hover {
|
| 302 |
-
border-color: #f56565;
|
| 303 |
-
color: #f56565;
|
| 304 |
-
background: rgba(245, 101, 101, 0.1);
|
| 305 |
-
}
|
| 306 |
-
|
| 307 |
footer {
|
| 308 |
height: 48px;
|
| 309 |
border-top: 1px solid var(--border);
|
|
@@ -334,4 +324,17 @@ footer {
|
|
| 334 |
width: 0%;
|
| 335 |
background: var(--accent);
|
| 336 |
transition: width 0.4s ease;
|
| 337 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
color: var(--accent);
|
| 69 |
}
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
main {
|
| 72 |
display: grid;
|
| 73 |
grid-template-columns: 1fr 1fr;
|
|
|
|
| 101 |
border-radius: var(--radius-lg);
|
| 102 |
overflow: hidden;
|
| 103 |
position: relative;
|
| 104 |
+
min-height: 0
|
| 105 |
}
|
| 106 |
|
| 107 |
.video-placeholder {
|
|
|
|
| 120 |
#video-preview {
|
| 121 |
width: 100%;
|
| 122 |
height: 100%;
|
| 123 |
+
object-fit: contain;
|
| 124 |
display: block;
|
| 125 |
}
|
| 126 |
|
|
|
|
| 151 |
color: var(--text-muted);
|
| 152 |
}
|
| 153 |
|
| 154 |
+
#video-link{
|
| 155 |
+
display: none;
|
| 156 |
+
flex: 0.1;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
#load-youtube{
|
| 160 |
+
display:none;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
.btn {
|
| 164 |
display: inline-flex;
|
| 165 |
align-items: center;
|
|
|
|
| 212 |
background: transparent;
|
| 213 |
}
|
| 214 |
|
| 215 |
+
#local-or-video{
|
| 216 |
+
display: flex;
|
| 217 |
+
justify-content: space-around;
|
| 218 |
+
button{
|
| 219 |
+
width: 48%;
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
.library-list {
|
| 224 |
list-style: none;
|
| 225 |
display: flex;
|
|
|
|
| 294 |
background: var(--accent-bg);
|
| 295 |
}
|
| 296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
footer {
|
| 298 |
height: 48px;
|
| 299 |
border-top: 1px solid var(--border);
|
|
|
|
| 324 |
width: 0%;
|
| 325 |
background: var(--accent);
|
| 326 |
transition: width 0.4s ease;
|
| 327 |
+
}
|
| 328 |
+
.sim-badge {
|
| 329 |
+
display: none;
|
| 330 |
+
font-family: var(--font-mono);
|
| 331 |
+
font-size: 10px;
|
| 332 |
+
font-weight: 500;
|
| 333 |
+
letter-spacing: 0.12em;
|
| 334 |
+
color: #f6ad55;
|
| 335 |
+
background: rgba(246,173,85,0.1);
|
| 336 |
+
border: 1px solid rgba(246,173,85,0.35);
|
| 337 |
+
border-radius: 4px;
|
| 338 |
+
padding: 2px 7px;
|
| 339 |
+
margin-right: 10px;
|
| 340 |
+
}
|