Uzun süre araştrıdım. Adam gibi bir kaynak bulamamıştım. Cevizde birisi anlatmış. Buldum denedim ve sorunsuz çalışıyor.
İlk başta aşağıdaki ffmpeg dosyasını indirip C: içine açın
RapidShare: 1-Click Webhosting
Ardından aşağıdaki scriptle dönüştürme işlemlerini, videodan görüntü alma işlemlerini yapabilirsiniz
PHP Kodu:
<?
//Configuration
define ('EZFFMPEG_BIN_PATH', 'C:\\bin\\ffmpeg.exe');//Chemin local vers ffmpeg
$src_filepath='C:\\1.avi'; //Kaynak Dosya Yolu
$output_capture_filepath='C:\\1.jpg'; //Oluşturulacak resim yolu
$output_filepath='C:\\1.flv'; //Oluşturulacak video yolu
$seconds_position=30; // Videonun kaçıncı saniyesinde alınacağı
$jpg_resolution="320x240"; // Çözünürlüğü
function ezffmpeg_vdofile_infos( $src_filepath )
{
$commandline = EZFFMPEG_BIN_PATH." -i ".$src_filepath;
$exec_return = ezffmpeg_exec($commandline);
$exec_return_content = explode ("\n" , $exec_return);
//Traitement du retour
if( $error_line_id = ezffmpeg_array_search('error', $exec_return_content) )
{
//Erreur, retourne status = -1 et error_msg = message d'erreur
$error_line = trim($exec_return_content[$error_line_id]);
$return_array['status'] = -1;
$return_array['error_msg'] = $error_line;
}
else
{
//OK, decode le resultat et renvoie status = 1 + datas
$return_array['status'] = 1;
//Decodage des infos duree / bitrate
if($infos_line_id = ezffmpeg_array_search('Duration:', $exec_return_content))
{
$infos_line = trim($exec_return_content[$infos_line_id]);
$infos_cleaning = explode (': ', $infos_line);
//Duree
$infos_datas = explode (',', $infos_cleaning[1]);
$return_array['vdo_duration_format'] = trim($infos_datas[0]);
$return_array['vdo_duration_seconds'] = ezffmpeg_common_time_to_seconds($return_array['vdo_duration_format']);
//Bitrate
$return_array['vdo_bitrate'] = trim($infos_cleaning[3]);
}
//Decodage des infos codec video
if($infos_line_id = ezffmpeg_array_search('Video:', $exec_return_content))
{
$infos_line = trim($exec_return_content[$infos_line_id]);
$infos_cleaning = explode (': ', $infos_line);
$infos_datas = explode (',', $infos_cleaning[2]);
$return_array['vdo_format'] = trim($infos_datas[0]);
$return_array['vdo_codec'] = trim($infos_datas[1]);
$return_array['vdo_res'] = trim($infos_datas[2]);
$return_array['vdo_fps'] = trim($infos_datas[3]);
}
//Decodage des infos codec video
if($infos_line_id = ezffmpeg_array_search('Audio:', $exec_return_content))
{
$infos_line = trim($exec_return_content[$infos_line_id]);
$infos_cleaning = explode (': ', $infos_line);
$infos_datas = explode (',', $infos_cleaning[2]);
$return_array['aud_codec'] = trim($infos_datas[0]);
$return_array['aud_frequency'] = trim($infos_datas[1]);
$return_array['aud_monostereo'] = trim($infos_datas[2]);
$return_array['aud_bitrate'] = trim($infos_datas[3]);
}
}
return($return_array);
}
//Conversion d'une video (1 : OK, 2 : SANS LE SON, -1 : ERR)
function ezffmpeg_vdofile_convert ($src_filepath, $output_filepath, $vdo_format='flv', $vdo_resolution="320x240", $vdo_bitrate = '512k', $vdo_framerate = '25', $audio_bitrate='32', $audio_frequency='44100' )
{
$commandline = EZFFMPEG_BIN_PATH." -i ".$src_filepath." -f ".$vdo_format." -s ".$vdo_resolution." -pass 1 -ab ".$audio_bitrate." -aspect 4:3 -r ".$vdo_framerate." -ar ".$audio_frequency." -b ".$vdo_bitrate." ".$output_filepath;
$exec_return = ezffmpeg_exec($commandline);
$exec_return_content = explode ("\n" , $exec_return);
//Si la conversion a echoue, methode alternative (sans le son)
if((!file_exists($output_filepath)) || (filesize($output_filepath) <= 0))
{
$commandline = EZFFMPEG_BIN_PATH." -i ".$src_filepath." -f ".$vdo_format." -s ".$vdo_resolution." -b ".$vdo_bitrate." -aspect 4:3 -r ".$vdo_framerate." -an ".$output_filepath;
$exec_return = ezffmpeg_exec($commandline);
$exec_return_content = explode ("\n" , $exec_return);
//Test reussite
if((!file_exists($output_filepath)) || (filesize($output_filepath) <= 0))
{
return(2);//Echec conversion normale, conversion sans le son (2)
}
else
{
return(-1);//Echec, pas de conversion
}
}
else
{
return(1);//Conversion normale, tout s'est bien passe (1)
}
}
//Conversion d'une video vers de la 3G (1 : OK, 2 : SANS LE SON, -1 : ERR)
function ezffmpeg_vdofile_3g ($src_filepath, $output_filepath )
{
$commandline = EZFFMPEG_BIN_PATH." -i ".$src_filepath." -y -acodec amr_nb -s 176x144 -ar 8000 -b 80 -vcodec h263 -ac 1 ".$output_filepath;
$exec_return = ezffmpeg_exec($commandline);
$exec_return_content = explode ("\n" , $exec_return);
//Si la conversion a echoue, methode alternative (sans le son)
if((!file_exists($output_filepath)) || (filesize($output_filepath) <= 0))
{
$commandline = EZFFMPEG_BIN_PATH." -i ".$src_filepath." -an -s 176x144 -vcodec h263 -ac 1 ".$output_filepath;
$exec_return = ezffmpeg_exec($commandline);
$exec_return_content = explode ("\n" , $exec_return);
//Test reussite
if((!file_exists($output_filepath)) || (filesize($output_filepath) <= 0))
{
return(2);//Echec conversion normale, conversion sans le son (2)
}
else
{
return(-1);//Echec, pas de conversion
}
}
else
{
return(1);//Conversion normale, tout s'est bien passe (1)
}
}
//Creation d'une capture jpg d'une video
function ezffmpeg_vdofile_capture_jpg ($src_filepath, $output_filepath, $seconds_position, $jpg_resolution="320x240" )
{
$commandline = EZFFMPEG_BIN_PATH." -i ".$src_filepath." -y -f mjpeg -t 0.001 -s ".$jpg_resolution." -ss ".$seconds_position." ".$output_filepath;
$exec_return = ezffmpeg_exec($commandline);
$exec_return_content = explode ("\n" , $exec_return);
if((!file_exists($output_filepath)) || (filesize($output_filepath) <= 0))
{
return(1);//Conversion OK (1)
}
else
{
return(-1);//Echec, pas de conversion
}
}
//Formatage d'une timestamp HH:MM:SS en secondes
function ezffmpeg_common_time_to_seconds($timestamp)
{
$timestamp_datas = explode (':', $timestamp);
$nb_seconds = $timestamp_datas[2];
$nb_minutes = $timestamp_datas[1];
$nb_hours = $timestamp_datas[0];
$return_val = ($nb_hours*3600)+($nb_minutes*60)+$nb_seconds;
return($return_val);
}
//Execution propre de FFMpeg avec recuperation des datas
function ezffmpeg_exec ($commandline)
{
$read = '';
$handle = popen($commandline.' 2>&1', 'r');
while(!feof($handle))
{
$read .= fread($handle, 2096);
}
pclose($handle);
return($read);
}
//Recherche data dans un array
function ezffmpeg_array_search($needle, $array_lines)
{
$return_val = false;
reset ($array_lines);
foreach( $array_lines as $num_line => $line_content )
{
if( strpos($line_content, $needle) !== false )
{
return($num_line);
}
}
return($return_val);
}
?>
Eğer bu scripti kullanmak istemezseniz
PHP Kodu:
system('C:\\bin\\ffmpeg.exe -i C:\\1.avi C:\\1.flv');
şeklinde ffmpeg i kullanabilirsiniz..
Yazıyı güzel gördüğüm için
alıntı yaptım.
Bunlarda yaptığım bazı örnekler
Ekran görüntüsü almak
PHP Kodu:
system('C:\\bin\\ffmpeg.exe -i C:\\xampp\\htdocs\\flv\\h\\xx.wmv -s 320*240 -vframes 1 -f mjpeg C:\\xampp\\htdocs\\flv\\h\\x.jpg');
wmv yi flv ye çevirmek
PHP Kodu:
system('C:\\bin\\ffmpeg.exe -i C:\\xampp\\htdocs\\flv\\h\\xx.wmv C:\\xampp\\htdocs\\flv\\h\\1.flv');