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 网页过期时间的控制代码

当然,前提要先打开CDN中一个功能reload_into_ims on.这样用户发送过来no-cache也不怕了.因为这样会给给no-cache转成If-Modified-Since ....

php对图像的各种处理函数代码小结

一、创建图片资源 imagecreatetruecolor(width,height);imagecreatefromgif(图片名称);imagecreatefrompng(图片名称)...

php+ajax实现无刷新数据分页的办法

本文实例讲述了php+ajax实现无刷新分页的方法。分享给大家供大家参考。具体实现方法如下: index.php 文件,代码如下: <?php header("Con...

本地计算机无法启动Apache故障处理

最近因工作需要,要学习PHP的基础编程,于是学习架设PHP工作环境。 但按照教材上介绍的那样,安装了WMAP后,一直无法运行成功。后发现Apache一直都不在运行状态。到WMAP中的Ap...

PHP常见的几种攻击方式实例小结

本文实例总结了PHP常见的几种攻击方式。分享给大家供大家参考,具体如下: 1.SQL Injection(sql注入) ①.暴字段长度 Order by num/* ②.匹配字段 and...