Ok daniele_dll,
ti spiego bene cosa voglio fare, in pratica devo costruire uno script che dopo aver caricato un video tramite un form questo deve essere convertito in swf e visualizzato in un player (un po come fa youtube)
Così ho esposto questo problema sul forum e mi hanno consigliato questo:
In pratica sul sito segnalato c'è una classe che fa questa operazione appoggiandosi anche ad un programma esterno "FFMPEG" e "FLVTool".
Alchè ho seguito le istruzioni sul sito, ma c'è qualcosa che non va che non riesco a capire dove, in pratica ho messo il link al mio progetto perchè contiene già il programma più i codici php e il video mpg di prova.
comunque la classe che permette di richiamare il programma è questo:
Codice PHP:
class media_handler
{
function convert_media($filename, $rootpath, $inputpath, $outputpath, $width, $height, $bitrate, $samplingrate)
{
$outfile = "";
// root directory path, where FFMPEG folder exist in your application.
$rPath = $rootpath."\ffmpeg";
// which shows FFMPEG folder exist on the root.
// Set Media Size that is width and hieght
$size = $width."x".$height;
// remove origination extension from file adn add .flv extension, becuase we must give output file name to ffmpeg command.
$outfile =$filename;
// Media Size
$size = Width & "x" & Height;
// remove origination extenstion from file and add .flv extension , becuase we must give output filename to ffmpeg command.
$outfile = 'out_file.flv';
// Use exec command to access command prompt to execute the following FFMPEG Command and convert video to flv format.
$ffmpegcmd1 = "ffmpeg -i ".$inputpath."\\".$filename. " -acodec mp3 -ar " .$samplingrate." -ab ".$bitrate."
-f flv -s ".$size." ".$outputpath."\\".outfile;
$ret = shell_exec($ffmpegcmd1);
// return output file name for other operations
return $outfile;
}
function set_buffering($filename,$rootpath,$path)
{
// root directory path
$_rootPath = rootpath."\flvtool";
// Execute FLV TOOL command also on exec , you can also use other tool for executing command prompt commands.
$ffmpegcmd1 = "flvtool2 -U ".Path."\\".$filename;
$ret = shell_exec($ffmpegcmd1);
// Execute this command to set buffering for FLV
}
function grab_image($filename, $rootpath, $inputpath,$outputpath, $no_of_thumbs, $frame_number, $image_format, $width, $height)
{
// root directory path
$_rootpath = rootpath."\ffmpeg";
// Media Size
$size = width. "x".height;
// I am using static image, you can dynamic it with your own choice.
$outfile = "sample.png";
$ffmpegcmd1 = "ffmpeg -i ".$inputpath."\\".filename." -vframes ".$no_of_thumbs." -ss 00:00:03 -an -vcodec ". $image_format." -f rawvideo -s ".$size. " ". $outputpath."\\".$outfile;
$ret = shell_exec($ffmpegcmd1);
// Execute this command using exec command or any other tool to grab image from converted flv file.
return $outfile;
}
}
Codice PHP:
$_mediahandler = new media_handler();
$rootpath ="";
$inputpath = $rootpath."/Default";
$outputpath = $rootpath. "/FLV"
$thumbpath = $rootpath. "/Thumbs"
Save original video in Default folder.
$source = $HTTP_POST_FILES['file1']['tmp_name'];
$name = $HTTP_POST_FILES['file1']['name'];
$fileSize = $HTTP_POST_FILES['file1']['size'];
$filetype = $HTTP_POST_FILES['file1']['type'];
$dest = '';
copy($source, $inputpath . $name);
// Convert it into FLV Format
$outfile = $_mediahandler.convert_media($name,$rootpath, $inputpath, $outputpath, 320, 240, 32, 22050);
// Grab Image from it.
$image_name = $_mediahandler.grab_image($outfile, $rootpath, $outputpath, $thumbpath, 1, 2, "png", 110, 90);
// user flv tool to set buffering, for this to work you must first download FLVTool and take it into the root folder of your .
$_mediahandler.Set_Buffering($outfile, $rootpath, $outputpath);
// Save all information in the database for other manipulation
Spero che tu possa aiutarmi
Grazie
Matt86