FFMPEG-PHP récuperer la durée ?

FFMPEG-PHP récuperer la durée ? - PHP - Programmation

Marsh Posté le 08-07-2008 à 10:10:38    

Hello tout le monde, j'ose espérer que vous saurez m'aider.
Voilà, j'ai trouvé une source bien sympatoche permettant de faciliter la gestion de ffmpeg.
Seul point qui me chagrine. Je n'arrive pas à récuperer la durée de la vidéo.
Si quelqu'un sait comment m'aider, qu'il n'hésite pas, il aura toute ma gratitude :o
 
Ci-dessous la source :

Code :
  1. <?php
  2. /*
  3. * @ name : video.php
  4. * @ description : a class used to encode, decode, resize and reformat videos...
  5. * @ author : Yaug - Manuel Esteban
  6. * @ contact : yaug@caramail.com
  7. * @ date : 03/01/2008
  8. */class Video{
  9.     public     $video_file, $duration, $bitrate, $video_format, $audio_format,
  10.             $video_size, $video_fps, $audio_freq, $audio_bitrate,
  11.             $encoding_vformat, $encoding_aformat, $encoding_vcodec, $encoding_acodec,
  12.             $encoding_vsize, $encoding_duration, $encoding_afreq, $encoding_target,
  13.             $encoding_packet_size, $encoding_aspect, $encoding_ac, $encoding_bitrate,
  14.             $encoding_abitrate, $encoding_fps, $encoding_time_position, $encoding_nosound;
  15.     private $video_id;
  16.     /*
  17.      * function : __construct
  18.      * @description : Constructor
  19.      * @param : $video
  20.     */    public function __construct($video){
  21.         $this->video_file     = $video;
  22.         $this->video_id        = md5($video);
  23.         //On récupère les infos de la vidéo
  24.         exec("ffmpeg  -i ".$this->video_file." &> ".$this->video_id.".info" );
  25.         $this->get_video_info();
  26.     }
  27.     /*
  28.      * function : __destruct
  29.      * @description : Destructor
  30.      * @param :
  31.     */    public function __destruct(){
  32.         if( is_file($this->video_id.".info" ) ) unlink($this->video_id.".info" );
  33.     }
  34.     /*
  35.      * function : getextension
  36.      * @description : return the extension of any file
  37.      * @param : $file - name of the file (video.avi)
  38.     */    public function getextension($file){
  39.         return substr($file,strrpos($file,'.')+1);
  40.     }
  41.     /*
  42.      * function : get_video_info
  43.      * @description : Extract all the video information with ffmpeg
  44.     */    private function get_video_info(){
  45.         $handle = fopen($this->video_id.".info","r" );
  46.         if($handle){
  47.             while (!feof($handle)) {
  48.                 $buffer = fgets($handle, 4096);
  49.                 $Line=explode(" ",$buffer);
  50.                 //print_r($Line);
  51.                 //print("\n" );
  52.                 switch($Line[2]){
  53.                     case 'Duration:':
  54.                         $this->duration = $Line[3];
  55.                         $this->bitrate     = $Line[7];
  56.                     case 'Stream':
  57.                         if($Line[4]=="Video:" ){
  58.                             $this->video_format = $Line[5];
  59.                             $this->video_size     = $Line[7];
  60.                             $this->video_fps     = $Line[8];
  61.                         }elseif($Line[4]=="Audio:" ){
  62.                             $this->audio_format = $Line[5];
  63.                             $this->audio_freq     = $Line[6];
  64.                             $this->audio_bitrate= $Line[9];
  65.                         }
  66.                 }
  67.             }
  68.             fclose($handle);
  69.             return true;
  70.         }
  71.         return false;
  72.     }
  73.     /*
  74.      * function : set_encoding_vformat()
  75.      * @description : Set the format for video encoding
  76.      * @param : $format (the format of the output video)
  77.     */    public function set_encoding_vformat($format){
  78.         $this->encoding_vformat = $format;
  79.     }
  80.     /*
  81.      * function : set_encoding_aformat()
  82.      * @description : Set the format for audio encoding
  83.      * @param : $format (the format of the output audio)
  84.     */    public function set_encoding_aformat($format){
  85.         $this->encoding_aformat = $format;
  86.     }
  87.     /*
  88.      * function : set_encoding_vcodec()
  89.      * @description : Set the codec for video encoding, be carefull with the codec name
  90.      * @param : $codec (the codec of the output video)
  91.     */    public function set_encoding_vcodec($codec){
  92.         $this->encoding_vcodec = $codec;
  93.     }
  94.     /*
  95.      * function : set_encoding_acodec()
  96.      * @description : Set the codec for audio encoding, be carefull with the codec name
  97.      * @param : $codec (the codec of the output audio)
  98.     */    public function set_encoding_acodec($codec){
  99.         $this->encoding_acodec = $codec;
  100.     }
  101.     /*
  102.      * function : set_encoding_vsize()
  103.      * @description : Set the size of the output video
  104.      * @param : $width (width of the output video)
  105.      * @param : $height (height of the output video)
  106.     */    public function set_encoding_vsize($size){
  107.         $this->encoding_vsize = $size;
  108.     }
  109.     /*
  110.      * function : set_encoding_duration()
  111.      * @description : Set the size of the output video
  112.      * @param : $duration (duration of the output like 00:00:10)
  113.     */    public function set_encoding_duration($duration){
  114.         $this->encoding_duration = $duration;
  115.     }
  116.     /*
  117.      * function : set_encoding_afreq()
  118.      * @description : Set the audio frequence of the output video
  119.      * @param : $freq (audio frequence of the output like 00:00:10)
  120.     */    public function set_encoding_afreq($freq){
  121.         $this->encoding_afreq = $freq;
  122.     }
  123.     /*
  124.      * function : set_encoding_target()
  125.      * @description : Specify target file type
  126.      * @param : $target (Specified target file type)
  127.     */    public function set_encoding_target($target){
  128.         $this->encoding_target = $target;
  129.     }
  130.     /*
  131.      * function : set_encoding_packet_size()
  132.      * @description : Set packet size in bits.
  133.      * @param : $weight (Size)
  134.     */    public function set_encoding_packet_size($weight){
  135.         $this->encoding_packet_size = $weight;
  136.     }
  137.     /*
  138.      * function : set_encoding_aspect()
  139.      * @description : Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777).
  140.      * @param : $ratio (Ratio of the generated video)
  141.     */    public function set_encoding_aspect($ratio){
  142.         $this->encoding_aspect = $ratio;
  143.     }
  144.     /*
  145.      * function : set_encoding_ac()
  146.      * @description : Set the number of audio channels
  147.      * @param : $nb (Number of channels)
  148.     */    public function set_encoding_ac($nb){
  149.         $this->encoding_ac = $nb;
  150.     }
  151.     /*
  152.      * function : set_encoding_bitrate()
  153.      * @description : Set the video bitrate in bit/s
  154.      * @param : $bitrate
  155.     */    public function set_encoding_bitrate($bitrate){
  156.         $this->encoding_bitrate = $bitrate;
  157.     }
  158.     /*
  159.      * function : set_encoding_abitrate()
  160.      * @description : Set the audio bitrate in bit/s
  161.      * @param : $abitrate
  162.     */    public function set_encoding_abitrate($abitrate){
  163.         $this->encoding_abitrate = $abitrate;
  164.     }
  165.     /*
  166.      * function : set_encoding_fps()
  167.      * @description : Set frame rate
  168.      * @param : $fps
  169.     */    public function set_encoding_fps($fps){
  170.         $this->encoding_fps = $fps;
  171.     }
  172.     /*
  173.      * function : set_encoding_time_position()
  174.      * @description : time position in seconds. hh:mm:ss[.xxx] syntax is also supported.
  175.      * @param : $position
  176.     */    public function set_encoding_time_position($position){
  177.         $this->encoding_time_position = $position;
  178.     }
  179.     /*
  180.      * function : set_encoding_nosound()
  181.      * @description : time position in seconds. hh:mm:ss[.xxx] syntax is also supported.
  182.      * @param : $position
  183.     */    public function set_encoding_nosound(){
  184.         if($this->encoding_nosound)$this->encoding_nosound=false;
  185.         else $this->encoding_nosound=true;
  186.     }
  187.     /*
  188.      * function : encode()
  189.      * @description : Encode video with defined params
  190.      * @param : $file_name (name of the file created.)
  191.     */    public function encode($file_name){
  192.         $command = "ffmpeg -y -i ".$this->video_file;
  193.         if($this->encoding_vformat)     $command.=" -f ".$this->encoding_vformat;
  194.         if($this->encoding_vcodec)         $command.=" -vcodec ".$this->encoding_vcodec;
  195.         if($this->encoding_acodec)         $command.=" -acodec ".$this->encoding_acodec;
  196.         if($this->encoding_vsize)         $command.=" -s ".$this->encoding_vsize;
  197.         if($this->encoding_duration)    $command.=" -t ".$this->encoding_duration;
  198.         if($this->encoding_fps)            $command.=" -r ".$this->encoding_fps;
  199.         if($this->encoding_bitrate)        $command.=" -b ".$this->encoding_bitrate;
  200.         if($this->encoding_nosound)        $command.=" -an ";
  201.         if($this->encoding_abitrate)    $command.=" -ab ".$this->encoding_abitrate;
  202.         if($this->encoding_afreq)        $command.=" -ar ".$this->encoding_afreq;
  203.         if($this->encoding_ac)            $command.=" -ac ".$this->encoding_ac;
  204.         if($this->encoding_target)        $command.=" -target ".$this->encoding_target;
  205.         if($this->encoding_packet_size)    $command.=" -ps ".$this->encoding_packet_size;
  206.         if($this->encoding_aspect)        $command.=" -aspect ".$this->encoding_aspect;
  207.         if($this->encoding_time_position)    $command.=" -ss ".$this->encoding_time_position;
  208.         $command.=" $file_name";
  209.         print("commande executée : $command" );
  210.         shell_exec($command);
  211.     }
  212.     /*
  213.      * function : get_image()
  214.      * @description : Get an image for a specific frame of a video
  215.      * @param : $frame (00:00:10.0002)
  216.      * @param : $image_name (name of this image)
  217.      * @param : $size
  218.     */    public function get_image($frame,$image_name,$size){
  219.         $this->encoding_vformat         = "mjpeg";
  220.         $this->encoding_duration         = "001";
  221.         $this->encoding_time_position     = $frame;
  222.         $this->encoding_vsize             = $size;
  223.         
  224.         //We build the image
  225.         $this->encode($image_name);
  226.     }
  227. }
  228. ?>

Reply

Marsh Posté le 08-07-2008 à 10:10:38   

Reply

Marsh Posté le 08-07-2008 à 12:18:24    

$this->duration :??:


Message édité par Profil supprimé le 08-07-2008 à 12:18:54
Reply

Marsh Posté le 08-07-2008 à 13:31:14    

Ben j'ai essayé et ça ne fonctionne pas :??:

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed