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面向对象五大原则之里氏替换原则(LSP)详解

本文实例讲述了PHP面向对象五大原则之里氏替换原则(LSP)。分享给大家供大家参考,具体如下: 替换原则由MIT计算机科学实验室的Liskov女士在1987年的OOPSLA大会上的一篇文...

PHP,ASP.JAVA,JAVA代码格式化工具整理

PHP代码格式化工具http://www.waterproof.fr/products/phpCodeBeautifier/最近修改一个代码,里面完全没有缩进,用这个能够格式化一下。相当...

PHP5各个版本的新功能和新特性总结

本文目录:PHP5.2 以前:autoload, PDO 和 MySQLi, 类型约束PHP5.2:JSON 支持PHP5.3:弃用的功能,匿名函数,新增魔术方法,命名空间,后期静态绑定...

Discuz不使用插件实现简单的打赏功能

Discuz不使用插件实现简单的打赏功能

实现目标:用户自行上传自己的支付宝及微信收款二维码,在主题帖增加打赏按钮及浮窗。 功能逻辑:利用后台自定义用户栏目实现用户上传二维码的功能,然后再在内容页加以判断、调用。 修改步骤: 1...

php 数学运算验证码实现代码

复制代码 代码如下:<?php //------------------------------------- // 文件说明:数学运算验证码 // 文件作者:Jesse Lee...