Bonjour,

Pour un projet, je souhaite extraire une image d'une vidéo en local (extension : .mp4, .avi, etc.) et pour cela, j'ai vu qu'il fallait utiliser la libraire ffmpeg.
A noter que mon projet est hébergé sous o2Switch (Linux xxxxx 4.18.0-305.10.2.2.lve.el7h.x86_64 #1 SMP Wed Jul 28 13:09:44 UTC 2021 x86_64).

Je me permets de venir vers vous, car ça fait plusieurs jours que je me bats avec ça, j'ai essayé plein de choses, mais rien y fait Je désespère un peu!!

Premier code que j'ai essayé :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
	error_reporting(E_ALL);
	ini_set('display_errors', '1');
	/*
		Commands
		
		-i input file name
		-an Disabled audio
		-ss Get image from X seconds in the video
		-s Size of the image
	*/
	// Get one thumbnail from the video
	$ffmpeg = "http://[NOMDOMAINE]/ffmpeg-N-103630-g06de593303-linux64-gpl/bin/ffmpeg";
	$videoFile = "http://[NOMDOMAINE]/sans-titre_OQnF6aR4.mp4";
	$imageFile = "http://[NOMDOMAINE]/2.jpg";
	$size = "120x90";
	$getFromSecond = 5;
	$cmd = "$ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile";
	if(!shell_exec($cmd)) {
		echo "Thumbnaail Created !";
	} else {
		echo "Error Creating Thumbnail";
	}
?>
La librairie "ffmpeg-N-103630-g06de593303-linux64-gpl" a été téléchargée via le lien suivant : https://github.com/BtbN/FFmpeg-Build...21-09-15-12-22
Lorsque j'exécute le code ci-dessus, il m'affiche le texte "Thumbnaail Created !" mais l'image n'est pas crée.


Seconde méthode testée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php
	// error_reporting(E_ALL);
	ini_set("display_errors", 1);
 
	require_once 'vendor/autoload.php';
 
	use Char0n\FFMpegPHP\Movie;
	echo 'z';
 
	$videoInfo = new FFMpegMovie('test.mp4');
 
 
	$videoFrames = $videoInfo->getFrameCount();
	$largeur = $videoImage->getWidth();
	$hauteur = $videoImage->getHeight();
 
	// ici je divise le nombre d'images de la video par 2,
	// ainsi je prendrai ma miniature en plein milieu de la video
	$videoImage = $videoInfo->getFrame($videoFrames/2);
 
 
	// je veux des miniatures de 300px de large je calcule donc le % de réduction pour avoir
	// une largeur de 300px et une hauteur proportionnelle
	$pourcentageReduction = (300/$largeur)*100;
 
	// je calcule donc mes nouvelles valeur en appliquant la focntion
	// ceil qui arrondit à l'entier supérieur (on ne peut pas avoir des moitiés de pixels !)
	$newLargeur = ceil($largeur*($pourcentageReduction/100));
	$newHauteur = ceil($hauteur*($pourcentageReduction/100));
	$miniature = $videoImage->resize($newHauteur, $newLargeur);
 
	$img = $miniature->toGDImage();
	imagejpeg($img, 'ma_miniature.jpeg');
?>
Pour cette méthode, j'ai suivi le lien suivant : https://github.com/char0n/ffmpeg-php
Lorsque j'exécute le code ci-dessus, il m'affiche la chose suivante :
z
Fatal error: Uncaught Error: Class 'FFMpegMovie' not found in /home/frjo3166/public_html/_video/test.php:10 Stack trace: #0 {main} thrown in /home/frjo3166/public_html/_video/test.php on line 10

Troisième méthode testée :
En suivant le lien suivant http://ffmpeg-php.sourceforge.net/ j'ai téléchargé ceci : https://sourceforge.net/projects/ffmpeg-php/ et je l'ai installé sur mon projet.
Lorsque j'effectue la partie "Testing the Installation" en exécutant le code suivant dans mon navigateur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?
	error_reporting(E_ALL);
	ini_set("display_errors", 1);
 
/*
 * This test script is not part of the automatic regression tests. It serves
 * as a simple manual test script and an example of the syntax for calling
 * the ffmpeg-php functions
 * 
 * To run it from the command line type 'php -q ffmpeg_test.php'or from a 
 * browser * copy this file into your web root and point your browser at it.
 */
 
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
 
// load extension
if (!extension_loaded($extension)) {
    dl($extension_soname) or die("Can't load extension $extension_fullname\n");
}
 
function getDirFiles($dirPath)
{
    if ($handle = opendir($dirPath))
    {
        while (false !== ($file = readdir($handle))) {
            $fullpath = $dirPath . '/' . $file;
            if (!is_dir($fullpath) && $file != "CVS" && $file != "." && $file != "..")
                $filesArr[] = trim($fullpath);
        }
        closedir($handle);
    } 
 
    return $filesArr;   
}
 
 
if (php_sapi_name() != 'cgi') {
    echo '<pre>';
}
 
// print available functions and aliases
printf("libavcodec version number: %d\n", LIBAVCODEC_VERSION_NUMBER);
printf("libavcodec build number: %d\n", LIBAVCODEC_BUILD_NUMBER);
 
// print available functions and aliases
echo "\nFunctions available in $extension_fullname extension:\n";
foreach(get_extension_funcs($extension) as $func) {
    echo $func."\n";
}
 
$class = "ffmpeg_movie";
echo "\nMethods available in class $class:\n";
foreach(get_class_methods($class) as $method) {
    echo $method."\n";
}
 
// put some movie files into this array to test the ffmpeg functions
$movies = getDirFiles(dirname(__FILE__) . '/test_media');
 
echo "--------------------\n\n";
foreach($movies as $movie) {        
    $mov = new ffmpeg_movie($movie);
    printf("file name = %s\n", $mov->getFileName());
    printf("duration = %s seconds\n", $mov->getDuration());
    printf("frame count = %s\n", $mov->getFrameCount());
    printf("frame rate = %0.3f fps\n", $mov->getFrameRate());
    printf("comment = %s\n", $mov->getComment());
    printf("title = %s\n", $mov->getTitle());
    printf("author = %s\n", $mov->getAuthor());
    printf("copyright = %s\n", $mov->getCopyright());
    printf("frame height = %d pixels\n", $mov->getFrameHeight());
    printf("frame width = %d pixels\n", $mov->getFrameWidth());
    printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes');
    printf("get pixel format = %s\n", $mov->getPixelFormat());
    printf("get video codec = %s\n", $mov->getVideoCodec());
    printf("get audio codec = %s\n", $mov->getAudioCodec());
    printf("get audio channels = %s\n", $mov->getAudioChannels());
    printf("get bit rate = %d kb/s\n", $mov->getBitRate());
/*    
    while (1) {
        $frame = $mov->getFrame();
        if (!is_resource($frame)) {
            break;
        }
        echo "get frame() $frame" . "\n";
    }
 */    
    printf("get frame = %s\n", $mov->getFrame(10));
    printf("get frame number = %d\n", $mov->getFrameNumber());
    echo "\n--------------------\n\n";
}
 
if (php_sapi_name() != 'cgi') {
    echo '</pre>';
}
 
?>
Voici le résultat :
Fatal error: Uncaught Error: Call to undefined function dl() in /home/frjo3166/public_html/_video/ext_ffmpeg_20050221/ffmpeg1/tests/test_ffmpeg.php:24 Stack trace: #0 {main} thrown in /home/frjo3166/public_html/_video/ext_ffmpeg_20050221/ffmpeg1/tests/test_ffmpeg.php on line 24

Quelqu'un saurait-il comment faire pour extraire une image d'une vidéo soit en utilisant l'une des méthodes présentées ci-dessus où je suis preneur pour toute autre solution sur un serveur o2switch (Linux xxxxx 4.18.0-305.10.2.2.lve.el7h.x86_64 #1 SMP Wed Jul 28 13:09:44 UTC 2021 x86_64) ?

Merci par avance,
Loïc.