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

yipeiwu_com4年前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 XML Expat解析器知识点总结

内建的 Expat 解析器使在 PHP 中处理 XML 文档成为可能。 什么是 XML? XML 用于描述数据,其焦点是数据是什么。XML 文件描述了数据的结构。 在 XML 中,...

java解析json方法总结

工具包org.json.jar,是一个轻量级的,JAVA下的json构造和解析工具包,它还包含JSON与XML, HTTP headers, Cookies, CDL的转换。 这里推荐...

PHP中cookies使用指南

综述    Cookie是在HTTP协议下,服务器或脚本可以维护客户工作站上信息的一种方式。Cookie是由Web服务器保存在用户浏览器上的小文件,它可以包含有关用户的信息(如...

解决php写入数据库乱码的问题

对于乱码这个问题php开发者几乎都会有碰到过,我们下面主要是介绍了php mysql数据库连接时乱码解决方法。 MYSQL数据库使用UTF-8编码的问题 1.用phpmyadmin创建...

使用php自动备份数据库表的实现方法

使用php自动备份数据库表的实现方法

1、前言 mysql数据库的备份方式有很多; 例如: 1、使用mysqldump函数 mysqldump -u username -p dbname table1 table2 ......