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

yipeiwu_com6年前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和JavaScrip分别获取关联数组的键值示例代码

PHP版: 复制代码 代码如下: $o = array('x'=>1, 'y'=>2, 'z'=>3); $arr = array(); $i = 0; foreach...

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

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

总结一些PHP中好用但又容易忽略的小知识

本文主要给大家总结了PHP中一些好用的小知识,分享出来供大家参考学习,下面来看看详细的介绍: 1、PHP函数之判断函数是否存在 当我们创建了自定义函数,并且了解了可变函数的用法,为了确保...

PHPUnit PHP测试框架安装方法

单元测试是几个现代敏捷开发方法的基础,使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ,并且可以与phing集成来自动测试,最...

PHP回调函数简单用法示例

本文实例讲述了PHP回调函数简单用法。分享给大家供大家参考,具体如下: php中提供了两个内置的回调函数call_user_func()、call_user_func_array()。...