Convertir un avi en FLV
Posté : 16 déc. 2007, 18:42
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
J'ai donc utiliser ce formulaire
Je veux savoir comment recuperer la valeur du champ fichier du formulaire puis le 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><?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();
}
?>