当前位置:首页 > PHP教程 > php应用 > 列表

PHP使用ffmpeg给视频增加字幕显示的方法

发布:smiling 来源: PHP粉丝网  添加日期:2021-05-16 11:58:04 浏览: 评论:0 

这篇文章主要介绍了PHP使用ffmpeg给视频增加字幕显示的方法,实例分析了php操作ffmpeg给视频增加字母的技巧,具有一定参考借鉴价值,需要的朋友可以参考下。

本文实例讲述了PHP使用ffmpeg给视频增加字幕显示的方法,分享给大家供大家参考,具体实现方法如下:

  1. <?php 
  2. $dir = './'; // set to current folder 
  3. if ($handle = opendir($dir)) { 
  4.  while(false!== ($file = readdir($handle))) { 
  5.  if ( is_file($dir.$file) ){ 
  6.  if (preg_match("'\.(avi)$'", $file) ){ 
  7.  $sub_file = str_ireplace(".avi", ".srt", $dir.$file); 
  8.  $idx_file = str_ireplace(".avi", ".idx", $dir.$file); 
  9.  $thumb_file = str_ireplace(".avi", ".jpg", $dir.$file); 
  10.  $out_file = str_ireplace(".avi", ".mp4", $dir.$file); 
  11.  flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file); 
  12.  } 
  13.  else{ 
  14.  continue; 
  15.  } 
  16.  } 
  17.  } 
  18.  closedir($handle); 
  19. } 
  20. //flv_convert_get_thumb('input.avi', 'input.srt', 'output.jpg', 'output.ogm'); 
  21. // code provided and updated by steve of phpsnaps ! thanks 
  22. // accepts: 
  23. // 1: the input video file 
  24. // 2: path to thumb jpg 
  25. // 3: path to transcoded mpeg? 
  26. function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){ 
  27.  // get thumbnail 
  28.  $cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 250 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$out_thumb; 
  29.  $res = shell_exec($cmd); 
  30.  // $res is the output of the command 
  31.  // transcode video 
  32. $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$ 
  33.  $res = shell_exec($cmd); 
  34. } 
  35. ?> 

希望本文所述对大家的php程序设计有所帮助。

Tags: ffmpeg PHP字幕显示

分享到: