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程序设计有所帮助。

相关文章

Mac下php 5升级到php 7的步骤详解

前言 在MAC OS X 10.11中php的版本是5.5的,近来一年多里,看到了很多关于php7介绍,以为php7增加了很多新特性,也删除了原来很多的老特性,所以一直以来并没想去尝试使...

PHP获取ip对应地区和使用网络类型的方法

本文实例讲述了PHP获取ip对应地区和使用网络类型的方法。分享给大家供大家参考。具体分析如下: 这里测试的时候因为ip168网站禁止,所以试着在原有代码上修改为ip138数据库的数据调用...

PHP使用DOM对XML解析处理操作示例

PHP使用DOM对XML解析处理操作示例

本文实例讲述了PHP使用DOM对XML解析处理操作。分享给大家供大家参考,具体如下: DOM(Document Object Model):文档对象模型。核心思想是:把 xml文件看作是...

无法载入 mcrypt 扩展,请检查 PHP 配置终极解决方案

无法载入 mcrypt 扩展,<br />请检查 PHP 配置 出现以下几种情况后可能会造成运行phpmyadmin程序提示“无法载入 mcrypt 扩展,<br /&...

php 删除数组元素

如果没有提供 callback 函数,array_filter() 将删除 input 中所有等值为 FALSE 的条目。 删除数组中为空值的元素就可以使用这个函数。 复制代码 代码如下...