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简单判断iPhone、iPad、Android及PC设备的方法

本文实例讲述了PHP简单判断iPhone、iPad、Android及PC设备的方法。分享给大家供大家参考,具体如下: 因为工作需要我们需要知道是什么样了用户访问了我网站了,现在的移动设备...

PHP设计模式之工厂模式与单例模式

本文实例讲述了PHP设计模式之工厂模式与单例模式实现方法。分享给大家供大家参考,具体如下: 设计模式简单说应对某类问题而设计的解决方式 工厂模式:应对需求创建相应的对象 class...

一致性哈希算法以及其PHP实现详细解析

一致性哈希算法以及其PHP实现详细解析

在做服务器负载均衡时候可供选择的负载均衡的算法有很多,包括:  轮循算法(Round Robin)、哈希算法(HASH)、最少连接算法(Least Connection)、响应...

php 网页播放器用来播放在线视频的代码(自动判断并选择视频文件类型)

在web开发中经常会碰到一些简单的视频播放功能,但现在的视频格式不同,并且可以动态增加,所以我们就必须把视频保存到数据哦,好了下面我们来看我写的段简单的 php视频网页播放器代码吧。 复...

PHP设计模式之策略模式原理与用法实例分析

本文实例讲述了PHP设计模式之策略模式原理与用法。分享给大家供大家参考,具体如下: 策略模式(Strategy Pattern) 策略模式是对象的行为模式,用意是对一组算法的封装。动态的...