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获取文件相对路径的方法

本文实例讲述了PHP获取文件相对路径的方法。分享给大家供大家参考。具体实现方法如下: <?php $a = '/a/b/c/d/e.php'; $b = '/a/b/1...

PHP封装类似thinkphp连贯操作数据库Db类与简单应用示例

本文实例讲述了PHP封装类似thinkphp连贯操作数据库Db类与简单应用。分享给大家供大家参考,具体如下: <?php header("Content-Type:te...

php PDO判断连接是否可用的实现方法

mysql_ping() 检查到服务器的连接是否正常。如果到服务器的连接可用,则返回true,否则返回false。 但PDO不支持mysql_ping()方法,因此需要自己编写代码模拟m...

php中使用getimagesize获取图片、flash等文件的尺寸信息实例

如果你还想着通过解析swf文件头信息来获取flash文件的尺寸信息,那真的有点走远了。因为从PHP 4开始已经内置getimagesize函数来做这个事。其功能测定任何 GIF,JPG,...

PHP实现超简单的SSL加密解密、验证及签名的方法示例

本文实例讲述了PHP实现超简单的SSL加密解密、验证及签名的方法。分享给大家供大家参考,具体如下: 1. sign签名代码: function sign($data) { //读...