Convertir un fichier video en FLV par un script PHP

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Convertir un fichier video en FLV par un script PHP

Convertir un avi en FLV

par vares2 » 16 déc. 2007, 15:22

Je souhaite convertir un avi en FLV; le code ci-dessous marche bien mais demande que je spécifie le chemin d'accès du fichier à convertir
 //	input movie files
	$files_to_process = array(
		'/usr/local/home/xxx/xxx.com/videos/mavideo.avi',
	);
Je souhaite plutôt pouvoir parcourir l'ordinateur pour choisir le fichier à convertir.
J'ai donc utiliser ce formulaire

Code : Tout sélectionner

<!-- Le type d'encodage des données, enctype, DOIT être spécifié comme ce qui suit --> <form action="flv.php" method="post" enctype="multipart/form-data" name="form" id="form"> <!-- MAX_FILE_SIZE doit précéder le champs input de type file --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Le nom de l'élément input détermine le nom dans le tableau $_FILES --> Envoyez ce fichier : <input name="image" type="file" id="image" /> <input type="submit" value="Envoyer le fichier" /> </form>
Je veux savoir comment recuperer la valeur du champ fichier du formulaire puis le convertir.

<?php




// 	define the paths to the required binaries
	define('FFMPEG_BINARY', '/usr/bin/ffmpeg');
	//define('FFMPEG_FLVTOOLS_BINARY', '/usr/bin/flvtool2');
	
	require_once 'ffmpeg.php';
	
// 	please replace xxxxx with the full absolute path to the files and folders
// 	also please make the $video_output_dir read and writeable by the webserver
	
//	input movie files
	$files_to_process = array(
		'/usr/local/home/xxx/xxx.com/videos/mavideo.avi',
	);

//	output files dirname has to exist
	//$video_output_dir = 'xxxxx/ffmpeg/www/example/processed/videos/';
	$video_output_dir = '/usr/local/home/xxx/xxx.com/videos/';
	
//	bit rate of audio (valid vaues are 16,32,64)
	$bitrate = 64;

//	sampling rate (valid values are 11025, 22050, 44100)
	$samprate = 44100;
	
// 	start ffmpeg class
	$ffmpeg = new ffmpeg();
	
// 	set ffmpeg class to run silently
	$ffmpeg->on_error_die = FALSE;
	
// 	loop through the files to process
	foreach($files_to_process as $file)
	{
// 		get the filename parts
		$filename = basename($file);
		$filename_minus_ext = substr($filename, 0, strrpos($filename, '.'));
		
// 		set the input file
		$ok = $ffmpeg->setInputFile($input_dir.$file);
// 		check the return value in-case of error
		if(!$ok)
		{
// 			if there was an error then get it 
			echo $ffmpeg->getLastError()."<br />\r\n";
			$ffmpeg->reset();
			continue;
		}
		
// 		set the output dimensions
		$ffmpeg->setVideoOutputDimensions(320, 240);
		
// 		set the video to be converted to flv
		$ffmpeg->setFormatToFLV($samprate, $bitrate);
		
// 		set the output details
		$ok = $ffmpeg->setOutput($video_output_dir, $filename_minus_ext.'.flv', TRUE);
// 		check the return value in-case of error
		if(!$ok)
		{
// 			if there was an error then get it 
			echo $ffmpeg->getLastError()."<br />\r\n";
			$ffmpeg->reset();
			continue;
		}
		
// 		execute the ffmpeg command
		$result = $ffmpeg->execute(TRUE);
		
// 		get the last command given
// 		$command = $ffmpeg->getLastCommand();
// 		echo $command[0]."<br />\r\n";
// 		echo $command[1]."<br />\r\n";
		
// 		check the return value in-case of error
		if(!$result)
		{
// 			if there was an error then get it 
			echo $ffmpeg->getLastError()."<br />\r\n";
			$ffmpeg->reset();
			continue;
		}
		
		echo 'Video converted... <b>'.array_shift($ffmpeg->getLastOutput()).'</b><br />'."\r\n";
	
// 		reset 
		$ffmpeg->reset();
	}
	
?>

par @rthur » 14 déc. 2007, 01:54

Bonjour,

Essaye de faire la conversion d'abord en ligne de commande avec FFmpeg ça te permettra de voir facilement les messages d'erreur avant de passer via PHP

Convertir un fichier video en FLV par un script PHP

par vares2 » 13 déc. 2007, 19:56

Bonjour,

J'aimerais pouvoir a travers un script PHP convertir n'importe quel type de fichier video au format FLV et en extraire une image.

Merci de m'aider

J'arrive a extraire une image en faisant ceci:
<?php
$output = shell_exec('ffmpeg -i monavi.avi monimage.jpg -t dureeextraite -ss debutextraction');
echo "<pre>$output</pre>";
?>
Mais pour la conversion j'arrive pas