php使用ffmpeg向录像中添Gavin字字幕的落实格局,php使用ffmpeg获取录制新闻并截图的兑现格局

By admin in 4858.com on 2019年7月7日

ffmpeg是一套能够用来记录、转变数字音频、录制,并能将其转会为流的开源Computer程序,蕴含了libavcodec,保障高可移值性和编解码品质。

那篇作品首要介绍了PHP使用ffmpeg给录像增添字幕展现的办法,实例分析了php操作ffmpeg给录像增加字母的本领,具有一定参谋借鉴价值,要求的心上人能够参见下。

PHP脚本调用ffmpeg对录像截图并拼接,供大家仿效,具体内容如下

正文实例呈报了php使用ffmpeg获取录像音信并截图的法子。分享给咱们供大家参照他事他说加以考察,具体如下:

正文将介绍使用php调用ffmpeg获取摄像音信,调用ffmpeg首先要求服务器上安装了ffmpeg,安装格局很简短,可机海关检查索。

正文实例陈述了PHP使用ffmpeg给摄像扩大字幕展现的不二秘籍。分享给大家供大家参谋。具体落成方式如下:

4858.com 1

$movie = new ffmpeg_movie('4.mp4');
$width=$movie->getFrameWidth();
$height=$movie->getFrameHeight();
$count= $movie->getFrameCount();
print $count . '';
$n = round ( $count/16 );
print $n . '';
for ( $i = 1; $i <= 1; $i ++ ) {
  $img = 'screencap' . $i . '.png';
  $x = $n * $i;
  $f = $movie->getFrame($x);
  $gd_image = $f->toGDImage();
  imagepng($gd_image, $img);
  imagedestroy($gd_image);
  echo "
\n";
}
$extension = "ffmpeg";
$extension_soname = $extension . "." . PHP_SHLIB_SUFFIX;
$extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;
// load extension
if (!extension_loaded($extension)) {
  dl($extension_soname) or die("Can't load extension $extension_fullname\n");
}
if (php_sapi_name() != 'cli') {
  echo '
';
}
printf("ffmpeg-php version string: %s\n", FFMPEG_PHP_VERSION_STRING);
printf("ffmpeg-php build date string: %s\n", FFMPEG_PHP_BUILD_DATE_STRING);
printf("libavcodec build number: %d\n", LIBAVCODEC_BUILD_NUMBER);
printf("libavcodec version number: %d\n", LIBAVCODEC_VERSION_NUMBER);
print_class_methods("ffmpeg_movie");
print_class_methods("ffmpeg_frame");
// get an array for movies from the test media directory
$movies = getDirFiles(dirname(__FILE__) . '/tests/test_media');
echo "--------------------\n\n";
foreach($movies as $movie) {
  $mov = new ffmpeg_movie($movie);
  printf("file name = %s\n", $mov->getFileName());
  printf("duration = %s seconds\n", $mov->getDuration());
  printf("frame count = %s\n", $mov->getFrameCount());
  printf("frame rate = %0.3f fps\n", $mov->getFrameRate());
  printf("comment = %s\n", $mov->getComment());
  printf("title = %s\n", $mov->getTitle());
  printf("author = %s\n", $mov->getAuthor());
  printf("copyright = %s\n", $mov->getCopyright());
  printf("get bit rate = %d\n", $mov->getBitRate());
  printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes');
  if ($mov->hasAudio()) {
    printf("get audio stream id= %s\n", $mov->getAudioStreamId());
    printf("get audio codec = %s\n", $mov->getAudioCodec());
    printf("get audio bit rate = %d\n", $mov->getAudioBitRate());
    printf("get audio sample rate = %d \n", $mov->getAudioSampleRate());
    printf("get audio channels = %s\n", $mov->getAudioChannels());
  }
  printf("has video = %s\n", $mov->hasVideo() == 0 ? 'No' : 'Yes');
  if ($mov->hasVideo()) {
    printf("frame height = %d pixels\n", $mov->getFrameHeight());
    printf("frame width = %d pixels\n", $mov->getFrameWidth());
    printf("get video stream id= %s\n", $mov->getVideoStreamId());
    printf("get video codec = %s\n", $mov->getVideoCodec());
    printf("get video bit rate = %d\n", $mov->getVideoBitRate());
    printf("get pixel format = %s\n", $mov->getPixelFormat());
    printf("get pixel aspect ratio = %s\n", $mov->getPixelAspectRatio());
    $frame = $mov->getFrame(10);
    printf("get frame = %s\n", is_object($frame) ? 'true' : 'false');
    printf(" get frame number = %d\n", $mov->getFrameNumber());
    printf(" get frame width = %d\n", $frame->getWidth());
    printf(" get frame height = %d\n", $frame->getHeight());
  }
  echo "\n--------------------\n\n";
}
if (php_sapi_name() != 'cli') {
  echo '';
}
/* FUNCTIONS */
function print_class_methods($class) {
  echo "\nMethods available in class '$class':\n";
  $methods = get_class_methods($class);
  if (is_array($methods)) {
    foreach($methods as $method) {
      echo $method . "\n";
    }
  } else {
    echo "No Methods Defined\n";
  }
}
function getDirFiles($dirPath)
{
  if ($handle = opendir($dirPath))
  {
    while (false !== ($file = readdir($handle))) {
      $fullpath = $dirPath . '/' . $file;
      if (!is_dir($fullpath) && $file != "CVS" && $file != "." && $file != "..")
        $filesArr[] = trim($fullpath);
    }
    closedir($handle);
  }
  return $filesArr;
}
?>

代码如下:

<?php 
$dir = './'; // set to current folder 
if ($handle = opendir($dir)) { 
 while(false!== ($file = readdir($handle))) { 
 if ( is_file($dir.$file) ){ 
 if (preg_match("'\.(avi)$'", $file) ){ 
 $sub_file = str_ireplace(".avi", ".srt", $dir.$file); 
 $idx_file = str_ireplace(".avi", ".idx", $dir.$file); 
 $thumb_file = str_ireplace(".avi", ".jpg", $dir.$file); 
 $out_file = str_ireplace(".avi", ".mp4", $dir.$file); 
 flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file); 
 } 
 else{ 
 continue; 
 } 
 } 
 } 
 closedir($handle); 
} 
//flv_convert_get_thumb('input.avi', 'input.srt', 'output.jpg', 'output.ogm'); 
// code provided and updated by steve of phpsnaps ! thanks 
// accepts: 
// 1: the input video file 
// 2: path to thumb jpg 
// 3: path to transcoded mpeg? 
function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){ 
 // get thumbnail 
 $cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 250 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$out_thumb; 
 $res = shell_exec($cmd); 
 // $res is the output of the command 
 // transcode video 
$cmd = 'mencoder '.$in.' -o '.$out_vid.' -sub '.$in_sub.' -subfont-text-scale 3.0 -subpos 99 -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encop$ 
 $res = shell_exec($cmd); 
} 
?>

当前协助MKV,MPG,DVD等常见格式的录像,别的格式有待测验

运作效果如下图所示:

<?php
// 定义ffmpeg路径及命令常量
define('FFMPEG_CMD', '/usr/local/bin/ffmpeg -i "%s" 2>&1');

/**
 * 使用ffmpeg获取视频信息
 * @param String $file 视频文件
 * @return Array
 */
function getVideoInfo($file){
 ob_start();
 passthru(sprintf(FFMPEG_CMD, $file));
 $video_info = ob_get_contents();
 ob_end_clean();

 // 使用输出缓冲,获取ffmpeg所有输出内容
 $ret = array();

 // Duration: 00:33:42.64, start: 0.000000, bitrate: 152 kb/s
 if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $video_info, $matches)){
  $ret['duration'] = $matches[1]; // 视频长度
  $duration = explode(':', $matches[1]);
  $ret['seconds'] = $duration[0]*3600 + $duration[1]*60 + $duration[2]; // 转为秒数
  $ret['start'] = $matches[2]; // 开始时间
  $ret['bitrate'] = $matches[3]; // bitrate 码率 单位kb
 }

 // Stream #0:1: Video: rv20 (RV20 / 0x30325652), yuv420p, 352x288, 117 kb/s, 15 fps, 15 tbr, 1k tbn, 1k tbc
 if(preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $video_info, $matches)){
  $ret['vcodec'] = $matches[1];  // 编码格式
  $ret['vformat'] = $matches[2]; // 视频格式
  $ret['resolution'] = $matches[3]; // 分辨率
  list($width, $height) = explode('x', $matches[3]);
  $ret['width'] = $width;
  $ret['height'] = $height;
 }

 // Stream #0:0: Audio: cook (cook / 0x6B6F6F63), 22050 Hz, stereo, fltp, 32 kb/s
 if(preg_match("/Audio: (.*), (\d*) Hz/", $video_info, $matches)){
  $ret['acodec'] = $matches[1];  // 音频编码
  $ret['asamplerate'] = $matches[2]; // 音频采样频率
 }

 if(isset($ret['seconds']) && isset($ret['start'])){
  $ret['play_time'] = $ret['seconds'] + $ret['start']; // 实际播放时间
 }

 $ret['size'] = filesize($file); // 视频文件大小
 $video_info = iconv('gbk','utf8', $video_info);
 return array($ret, $video_info);

}

// 输出视频信息
$video_info = getVideoInfo('myvideo.avi');
print_r($video_info[0]);
?>

上述那篇php使用ffmpeg向录像中添Gavin字字幕的贯彻方式就是笔者分享给大家的全体内容了,希望能给大家一个参照,也盼望大家多多帮助脚本之家。

4858.com ,12P 一张截图平均生成时间  1.64s     玖二十个摄像,大约供给2分半左右

4858.com 2

输出:

您恐怕感兴趣的篇章:

  • php利用ffmpeg提取录像中音频与摄像画面包车型客车办法详解
  • php
    调用ffmpeg获取录像信息的简要达成
  • php使用FFmpeg接口获取摄像的播报时间长度、码率、缩略图以及开创时间
  • PHP使用FFmpeg获取摄像播放总时间长度与码率等新闻
  • php使用ffmpeg获取录制新闻并截图的落到实处格局
  • PHP使用ffmpeg给录制扩大字幕显示的措施
  • PHP中运用php5-ffmpeg撷取摄像图片实例
  • PHP+FFMPEG完成将录像自动转码成H264正经Mp4文件
  • PHP中动用FFMPEG获取摄像缩略图和摄像总时间长度实例
  • php使用ffmpeg向录像中添Gavin字字幕的落实格局,php使用ffmpeg获取录制新闻并截图的兑现格局。PHP调用ffmpeg对录像截图并拼接脚本

9P  一张截图平均生成时间  1.13s      九十九个录像,大致必要2分钟左右

越多关于PHP相关内容感兴趣的读者可查阅本站专项论题:《PHP图形与图片操作技巧汇总》、《php操作office文书档案技能计算(满含word,excel,access,ppt)》、《php日期与时光用法计算》、《php面向对象程序设计入门教程》、《php字符串(string)用法计算》、《php+mysql数据库操作入门教程》及《php常见数据库操作手艺汇总》

Array
(
 [duration] => 00:33:42.64
 [seconds] => 2022.64
 [start] => 0.000000
 [bitrate] => 152
 [vcodec] => rv20 (RV20 / 0x30325652)
 [vformat] => yuv420p
 [resolution] => 352x288
 [width] => 352
 [height] => 288
 [acodec] => cook (cook / 0x6B6F6F63)
 [asamplerate] => 22050
 [play_time] => 2022.64
 [size] => 38630744
)

6P  一张截图平均生成时间  0.86s      九十几个摄像,大概必要1分半左右

可望本文所述对我们PHP程序设计具备帮衬。

以上那篇php
调用ffmpeg获取录像新闻的简约完结就是小编共享给大家的全体内容了,希望能给大家三个参考,也意在大家多多支持脚本之家。

3P  一张截图平均生成时间  0.54s      97个录像,大约要求1分钟左右

你或者感兴趣的稿子:

  • php利用ffmpeg提取摄像中音频与摄像镜头的点子详解
  • php
    调用ffmpeg获取摄像音信的简练完成
  • php使用FFmpeg接口获取录制的广播时间长度、码率、缩略图以及开创时间
  • PHP使用FFmpeg获取录像播放总时间长度与码率等音信
  • php使用ffmpeg向录制中添Gavin字字幕的落实格局
  • PHP使用ffmpeg给录像扩大字幕呈现的办法
  • PHP中动用php5-ffmpeg撷取录像图片实例
  • PHP+FFMPEG实现将录像自动转码成H264行业内部Mp4文件
  • PHP中使用FFMPEG获取录像缩略图和录像总时间长度实例
  • PHP调用ffmpeg对摄像截图并拼接脚本

您或者感兴趣的小说:

  • php利用ffmpeg提取录像中音频与摄像画面包车型客车不二秘诀详解
  • php使用FFmpeg接口获取录制的广播时间长度、码率、缩略图以及开创时间
  • PHP使用FFmpeg获取录制播放总时间长度与码率等音信
  • php使用ffmpeg向录制中添Gavin字字幕的落到实处际处境势
  • php使用ffmpeg获取录制新闻并截图的落成形式
  • PHP使用ffmpeg给摄像扩展字幕展现的办法
  • PHP中央银行使php5-ffmpeg撷取摄像图片实例
  • PHP+FFMPEG完毕将录像自动转码成H264行业内部Mp4文件
  • PHP中采纳FFMPEG获取摄像缩略图和摄像总时长实例
  • PHP调用ffmpeg对摄像截图并拼接脚本
<?php 
define('DS', DIRECTORY_SEPARATOR); 
date_default_timezone_set("Asia/Shanghai"); 
class FileLoader 
{ 
  //路径变量 
  private $rootdir    = ''; 
  private $tmp      = "tmp";      //tmp 目录 
  private $source     = "mpg";      //source 目录 
  private $destination  = "screenshoot";  //目标截图路径 
  private $emptyImageName = "empty.jpg";   //合成的背景图 
  //文件数组  
  private $maxShoots   = 12;        //最大的截图数 
  private $videoInfo   = NULL; 
  private $files     = array();     //文件数 
  private $fileArray   = array();      
  private $extensionArray = array("mpg","mkv","mp4","avi","3gp","mov");  //支持的格式 
  private $timeArray   = array("00:00:10","00:00:20","00:00:30","00:01:00","00:01:30","00:02:00","00:02:30","00:03:00","00:03:30","00:03:40","00:03:50","00:04:00"); 
  //统计变量 
  private $timeStart   = 0; 
  private $timeEnd    = 0; 
  private $fileCount   = 0; 
  private $successCount  = 0; 
  private $failedCount  = 0; 

  /** 
  *  初始化信息 
  */  
   function __construct() 
  { 
    file_put_contents("log.txt",""); 
    $this->rootdir = dirname(__FILE__);   
    $count = count($this->timeArray); 

    for($i=1;$i<=$count;$i++) 
    { 
      $ii = $i-1; 
      $this->fileArray[$ii] = $this->tmp.DS.$i.".jpg"; 
    } 
  } 

  /** 
  *  当前时间,精确到小数点 
  */ 
  private static function microtime_float() 
  { 
    list($usec, $sec)= explode(" ", microtime()); 
    return ((float)$usec + (float)$sec); 
  } 

  /** 
  *  00:00:00 时间转秒 
  */ 
  private static function timeToSec($time)  
  { 
     $p = explode(':',$time); 
     $c = count($p); 
     if ($c>1) 
     { 
        $hour  = intval($p[0]); 
        $minute = intval($p[1]); 
        $sec   = intval($p[2]); 
     } 
     else 
     { 
        throw new Exception('error time format'); 
     } 
     $secs = $hour * 3600 + $minute * 60 + $sec; 
     return $secs;  
  } 

  /** 
  *  00:00:00 时间转秒 
  */ 
  private static function secToTime($time)  
  { 

    $hour = floor($time/3600); 
    $min = floor(($time - $hour * 3600)/60); 
    $sec = $time % 60; 
    $timeStr = sprintf("%02d:%02d:%02d",$hour,$min,$sec); 
    return $timeStr;    
  } 

  /** 
  *  获取全部文件 
  */ 
   private function getFiles($dir) 
  { 
    $files = array(); 
    $dir = rtrim($dir, "/\\") . DS; 
    $dh = opendir($dir); 
    if ($dh == false) { return $files; } 

    while (($file = readdir($dh)) != false) 
    { 
      if ($file{0} == '.') { continue; } 

      $path = $dir . $file; 
      if (is_dir($path)) 
      { 
        $files = array_merge($files, $this->getFiles($path)); 
      } 
      elseif (is_file($path)) 
      { 
        $files[] = $path; 
      } 
    } 
    closedir($dh); 
    return $files; 
  } 

  /** 
  *  搜索路径 
  */ 
  public function searchDir($sourcePath = NULL) 
  { 

    $this->timeStart = $this->microtime_float(); 

    if ($sourcePath)  
    { 
      $this->rootdir = $sourcePath; 
    }  

    if (file_exists($this->rootdir) && is_dir($this->rootdir)) 
    { 
      $this->files = $this->getFiles($this->rootdir.DS.$this->source);       
    } 

    $this->fileCount = count($this->files); 

    foreach ($this->files as $path) 
    { 
      $fi = pathinfo($path); 
      $flag = array_search(strtolower($fi['extension']),$this->extensionArray); 
      if (!$flag) continue; 
      $this->getScreenShoot(basename($path)); 
    } 

    $this->timeEnd = $this->microtime_float(); 
    $time = $this->timeEnd - $this->timeStart; 

    if($this->fileCount > 0) 
    { 
      $str = sprintf("[TOTAL]: Cost Time:%8s | Total File:[%d] | Successed:[%d] | Failed:[%d] | Speed:%.2fs per file\n",$this->secToTime($time),$this->fileCount,$this->successCount,$this->failedCount,$time/$this->fileCount); 
      file_put_contents("log.txt",$str,FILE_APPEND);  
    } 
    else 
    { 
      $str = sprintf("[TOTAL]: Cost Time:%8s | Total File:[%d] | Successed:[%d] | Failed:[%d] | Speed:%.2fs per file\n",$this->secToTime($time),$this->fileCount,$this->successCount,$this->failedCount,0); 
      file_put_contents("log.txt",$str,FILE_APPEND); 
    }   

  } 

  /** 
  *  获取视频信息 
  */ 
  private function getVideoInfo($file){ 
      $re = array(); 
      exec(".".DS."ffmpeg -i {$file} 2>&1", $re); 
      $info = implode("\n", $re); 

      if(preg_match("/No such file or directory/i", $info)) 
      { 
        return false; 
      } 

      if(preg_match("/Invalid data/i", $info)){ 
        return false; 
      } 

      $match = array(); 
      preg_match("/\d{2,}x\d+/", $info, $match); 
      list($width, $height) = explode("x", $match[0]); 

      $match = array(); 
      preg_match("/Duration:(.*?),/", $info, $match); 
      if($match) 
      { 
        $duration = date("H:i:s", strtotime($match[1])); 
      }else 
      { 
        $duration = NULL; 
      }   

      $match = array(); 
      preg_match("/bitrate:(.*kb\/s)/", $info, $match); 
      $bitrate = $match[1]; 

      if(!$width && !$height && !$duration && !$bitrate){ 
        return false; 
      }else{ 
        return array( 
          "file" => $file, 
          "width" => $width, 
          "height" => $height, 
          "duration" => $duration, 
          "bitrate" => $bitrate, 
          "secends" => $this->timeToSec($duration) 
        ); 
      } 
    } 



  /** 
  *  设置截图时间 
  */  
  private function setShootSecends($secends,$useDefault = NO) 
  {   

    if($useDefault) 
    { 
      if($secends<18) 
      { 
        $time = 1; 
      }else 
      { 
        $time = 5; 
      }   

      $range = floor(($secends - $time)/ ($this->maxShoots)); 
      if ($range < 1)  
      { 
        $range = 1; 
      } 

      $this->timeArray = array(); 
      for($i=0;$i<$this->maxShoots;$i++) 
      { 
        $this->timeArray[$i] = $this->secToTime($time); 
        $time = $time + $range; 
        if ($time > $secends) break; 
      } 
    } 
  } 

  /** 
  *  拼接图片 
  */ 
  private function getFixedPhoto($fileName) 
  { 

    $target = $this->rootdir.DS.$this->emptyImageName;//背景图片 
    $target_img = Imagecreatefromjpeg($target); 
    $source= array(); 

    foreach ($this->fileArray as $k=>$v) 
    { 
      $source[$k]['source'] = Imagecreatefromjpeg($v); 
      $source[$k]['size'] = getimagesize($v); 
    } 

    $tmpx=5; 
    $tmpy=5;//图片之间的间距 
    for ($i=0; $i< count($this->timeArray); $i++) 
    {   
      imagecopy($target_img,$source[$i]['source'],$tmpx,$tmpy,0,0,$source[$i]['size'][0],$source[$i]['size'][1]); 
      $target_img = $this->setTimeLabel($target_img,$tmpx,$tmpy,$source[$i]['size'][0],$source[$i]['size'][1],$this->timeArray[$i]);   
      $tmpx = $tmpx+ $source[$i]['size'][0]; 
      $tmpx = $tmpx+5; 
      if(($i+1) %3 == 0){ 
        $tmpy = $tmpy+$source[$i]['size'][1]; 
        $tmpy = $tmpy+5; 
        $tmpx=5; 
      } 
    } 

    $target_img = $this->setVideoInfoLabel($target_img,$tmpx,$tmpy,$this->videoInfo); 
    Imagejpeg($target_img,$this->rootdir.DS.$this->destination.DS.$fileName.'.jpg');  
  } 

  /** 
  *  设置时间刻度标签 
  */ 
  private function setTimeLabel($image,$image_x,$image_y,$image_w,$image_h,$img_text) 
  { 
     imagealphablending($image,true); 
     //设定颜色 
     $color=imagecolorallocate($image,255,255,255); 
     $ttf_im=imagettfbbox(30 ,0,"Arial.ttf",$this->img_text); 
     $w = $ttf_im[2] - $ttf_im[6];  
     $h = $ttf_im[3] - $ttf_im[7];  
     unset($ttf_im); 

     $txt_y   =$image_y+$image_h+$h-5; 
     $txt_x   =$image_x+$w+5; 

     imagettftext($image,30,0,$txt_x,$txt_y,$color,"Arial.ttf",$img_text); 
     return $image;  
   } 

  /** 
  *  设置视频信息标签 
  */ 
   private function setVideoInfoLabel($image,$txt_x,$txt_y,$videoInfo) 
   { 
     imagealphablending($image,true); 

     $color=imagecolorallocate($image,0,0,0); 

     imagettftext($image,32,0,100,2000+30,$color,"FZLTHJW.ttf","FileName:".basename($videoInfo["file"])); 
     imagettftext($image,32,0,1600,2000+30,$color,"Arial.ttf","Size:".$videoInfo["width"]."x".$videoInfo["height"]); 
     imagettftext($image,32,0,100,2000+120,$color,"Arial.ttf","Duration:".$videoInfo["duration"]); 
     imagettftext($image,32,0,1600,2000+120,$color,"Arial.ttf","Bitrate:".$videoInfo["bitrate"]); 
     return $image;  
  } 

  /** 
  *  屏幕截图 
  */ 
  public function getScreenShoot($fileName) 
  { 
    $fi = pathinfo($fileName); 
    $this->videoInfo = $this->getVideoInfo($this->rootdir.DS.$this->source.DS.$fileName); 
    if($this->videoInfo) 
    { 
      $this->setShootSecends($this->videoInfo["secends"]); 

      for ($i=0; $i< count($this->timeArray); $i++ ) 
      { 
        $cmd=".".DS."ffmpeg -ss ". $this->timeArray[$i] ." -i ". $this->rootdir.DS.$this->source.DS.$fileName ." -y -f image2 -s 720*480 -vframes 1 ".$this->rootdir.DS.$this->fileArray[$i];   
        exec($cmd,$out,$status);   
      } 
      $this->getFixedPhoto($fileName); 

      $str = sprintf("[%s]:OK...........[%s][%2dP]%-30s\n",date("y-m-d h:i:s",time()),$this->videoInfo["duration"],count($this->timeArray),$fileName); 
      file_put_contents("log.txt",$str,FILE_APPEND); 
      $this->successCount += 1; 
    }else 
    { 
      $str = sprintf("[%s]:FAILED.................................[%s][%2dP]%-30s\n",date("y-m-d h:i:s",time()),$this->videoInfo["duration"],count($this->timeArray),$fileName); 
      file_put_contents("log.txt",$str,FILE_APPEND);  
      $this->failedCount += 1; 
    } 
  } 

  /** 
  *  TODO: 
  *  截取图片, 
  *  需要配置ffmpeg-php,比较麻烦, 
  *  但是这个类确实挺好用的。 
  */ 
  public function getScreenShoot2($fileName) 
  { 
    if(extension_loaded('ffmpeg')){//判断ffmpeg是否载入  
      $mov = new ffmpeg_movie($this->rootdir.DS.$this->source.DS.$fileName);//视频的路径  
      $count = $mov->getFrameCount(); 
      $ff_frame = $mov->getFrame(floor($count/2));  
      if($ff_frame) 
      { 
        $gd_image = $ff_frame->toGDImage();      
        $img=$this->rootdir.DS."test.jpg";//要生成图片的绝对路径  
        imagejpeg($gd_image, $img);//创建jpg图像  
        imagedestroy($gd_image);//销毁一图像  
      } 
    }else{  
      echo "ffmpeg没有载入";  
    }  
  } 
} 

$fileLoader = new FileLoader(); 
$fileLoader->searchDir(); 
?> 

如上正是本文的全体内容,希望对大家的上学抱有支持,也冀望我们多多协助脚本之家。

你可能感兴趣的稿子:

  • php利用ffmpeg提取摄像中音频与摄像镜头的艺术详解
  • php
    调用ffmpeg获取录像消息的粗略实现
  • php使用FFmpeg接口获取录制的播放时间长度、码率、缩略图以及开创时间
  • PHP使用FFmpeg获取摄像播放总时间长度与码率等音信
  • php使用ffmpeg向录像中添Gavin字字幕的兑现情势
  • php使用ffmpeg获取摄像音信并截图的落到实处情势
  • PHP使用ffmpeg给摄像扩大字幕显示的措施
  • PHP中选择php5-ffmpeg撷取录制图片实例
  • PHP+FFMPEG完毕将录制自动转码成H264行业内部Mp4文件
  • PHP中动用FFMPEG获取录像缩略图和摄像总时长实例

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有