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

WBOY
Lepaskan: 2016-07-25 08:42:36
asal
841 orang telah melayarinya
  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


sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!