Home  >  Article  >  Backend Development  >  PHP adds subtitles to videos through ffmpeg

PHP adds subtitles to videos through ffmpeg

WBOY
WBOYOriginal
2016-07-25 08:42:36841browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP download remote fileNext article:PHP download remote file