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

yipeiwu_com5年前PHP代码库

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

复制代码 代码如下:

<?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);
}
?>

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

相关文章

PHP中多维数组的foreach遍历示例

复制代码 代码如下: <?php //声明一个三维数组 $info=array( "user"=>array( array(1,"zhangsan",20,"nan"), a...

php提示无法加载或mcrypt没有找到 PHP 扩展 mbstring解决办法

没有找到 PHP 扩展 mbstring,而您现在好像在使用多字节字符集。没有 mbstring 扩展的 phpMyAdmin 不能正确分割字符串,可能产生意想不到的结果。 无法加载mc...

php常用字符函数实例小结

本文实例总结了php常用字符函数。分享给大家供大家参考,具体如下: 1. string substr(string  $string, int $start &nbs...

php中禁止单个IP与ip段访问的代码小结

禁止单个IP <?php //加IP访问限制 if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'),...

PHP二维数组排序简单实现方法

本文实例讲述了PHP二维数组排序简单实现方法。分享给大家供大家参考,具体如下: function multi_compare($a, $b) { $val_arr = array...