PHP使用ffmpeg给视频增加字幕显示的方法
作者:鉴客 时间:2024-05-03 15:53:38
本文实例讲述了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,ffmpeg,视频,字幕
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈编码,解码,乱码的问题
2021-02-22 05:15:37
![](https://img.aspxhome.com/file/2023/0/120960_0s.jpg)
Python多进程并发与同步机制超详细讲解
2022-11-22 08:35:02
提高网页加载显示速度的方法
2007-08-10 13:17:00
Python模块的定义,模块的导入,__name__用法实例分析
2023-07-13 13:11:00
![](https://img.aspxhome.com/file/2023/0/61180_0s.png)
Python实现读写sqlite3数据库并将统计数据写入Excel的方法示例
2024-01-21 07:55:04
windows环境下mysql的解压安装及备份和还原
2024-01-27 05:55:48
![](https://img.aspxhome.com/file/2023/5/75635_0s.png)
python pyinstaller 加载ui路径方法
2023-06-12 23:27:20
Spring Batch读取txt文件并写入数据库的方法教程
2024-01-27 03:59:32
![](https://img.aspxhome.com/file/2023/6/74766_0s.jpg)
Pytest框架之fixture详解(三)
2023-06-20 12:05:27
![](https://img.aspxhome.com/file/2023/1/65861_0s.png)
Python爬虫入门案例之回车桌面壁纸网美女图片采集
2022-12-25 19:40:57
![](https://img.aspxhome.com/file/2023/9/133649_0s.png)
Mysql 获取表的comment 字段操作
2024-01-19 12:12:28
![](https://img.aspxhome.com/file/2023/0/122870_0s.jpg)
go语言实现简易比特币系统钱包的原理解析
2024-05-22 10:12:02
asp如何用WSH获取机器的IP配置信息?
2010-06-13 14:39:00
pytorch __init__、forward与__call__的用法小结
2023-09-04 13:20:47
![](https://img.aspxhome.com/file/2023/4/117284_0s.jpg)
Python数据可视化处理库PyEcharts柱状图,饼图,线性图,词云图常用实例详解
2022-03-02 10:43:08
![](https://img.aspxhome.com/file/2023/9/112609_0s.png)
python-httpx的具体使用
2023-08-12 00:25:53
SQL进行排序、分组、统计的10个新技巧
2009-01-23 13:59:00
python scipy.misc.imsave()函数的用法说明
2022-11-01 13:04:24
asp如何在聊天室实现趣味答题并计分功能?
2010-06-18 20:00:00
Python定时执行程序问题(schedule)
2021-07-26 14:18:22
![](https://img.aspxhome.com/file/2023/8/133408_0s.png)