-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.php
More file actions
54 lines (46 loc) · 2.05 KB
/
convert.php
File metadata and controls
54 lines (46 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['video'])) {
// Définir les chemins
$uploadDir = "brouillon/";
$originalFileName = basename($_FILES["video"]["name"]);
$uploadedFilePath = $uploadDir . $originalFileName;
// Vérifier et déplacer le fichier téléchargé
if (move_uploaded_file($_FILES["video"]["tmp_name"], $uploadedFilePath)) {
echo "Le fichier " . htmlspecialchars($originalFileName) . " a été téléchargé.<br>";
// Chemin vers l'exécutable FFmpeg
$ffmpegPath = __DIR__ . "/ffmpeg/bin/ffmpeg";
// Définir les noms des fichiers
$uniqueId = uniqid();
$convertedFileName = "converted_{$uniqueId}.mp4";
$convertedFilePath = $uploadDir . $convertedFileName;
// Convertir la vidéo en MP4
$command = "$ffmpegPath -i " . escapeshellarg($uploadedFilePath) . " -c:v libx264 -c:a aac -pix_fmt yuv420p -movflags faststart -hide_banner " . escapeshellarg($convertedFilePath) . " 2>&1";
$output = shell_exec($command);
if (file_exists($convertedFilePath)) {
echo "La vidéo a été convertie en MP4 et enregistrée sous le nom : " . htmlspecialchars($convertedFileName) . "<br>";
} else {
echo "Erreur lors de la conversion de la vidéo : " . nl2br(htmlspecialchars($output));
exit;
}
// Nettoyer le fichier téléchargé si ce n'est plus nécessaire
unlink($uploadedFilePath);
} else {
echo "Erreur lors du téléchargement du fichier.";
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Upload et Conversion Vidéo</title>
</head>
<body>
<h2>Upload et Conversion Vidéo</h2>
<form action="" method="post" enctype="multipart/form-data">
<label for="video">Sélectionnez une vidéo :</label>
<input type="file" name="video" id="video" accept="video/*" required>
<button type="submit">Uploader et Convertir</button>
</form>
</body>
</html>