PHP通过ffmpeg给视频增加字幕显示

WBOY
发布: 2016-07-25 08:42:36
原创
841 人浏览过
  1. $dir = './'; // set to current folder
  2. if ($handle = opendir($dir)) {
  3. while(false!== ($file = readdir($handle))) {
  4. if ( is_file($dir.$file) ){
  5. if (preg_match("'\.(avi)$'", $file) ){
  6. $sub_file = str_ireplace(".avi", ".srt", $dir.$file);
  7. $idx_file = str_ireplace(".avi", ".idx", $dir.$file);
  8. $thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
  9. $out_file = str_ireplace(".avi", ".mp4", $dir.$file);
  10. flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
  11. }
  12. else{
  13. continue;
  14. }
  15. }
  16. }
  17. closedir($handle);
  18. }
  19. //flv_convert_get_thumb('input.avi', 'input.srt', 'output.jpg', 'output.ogm');
  20. // code provided and updated by steve of phpsnaps ! thanks
  21. // accepts:
  22. // 1: the input video file
  23. // 2: path to thumb jpg
  24. // 3: path to transcoded mpeg?
  25. function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){
  26. // get thumbnail
  27. $cmd = 'ffmpeg -v 0 -y -i '.$in.' -vframes 1 -ss 250 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 '.$out_thumb;
  28. $res = shell_exec($cmd);
  29. // $res is the output of the command
  30. // transcode video
  31. $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$
  32. $res = shell_exec($cmd);
  33. }
  34. ?>
复制代码

PHP, ffmpeg


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!