php使用ffmpeg向視頻中添加文字字幕的實現方法_php執行個體

來源:互聯網
上載者:User

這篇文章主要介紹了PHP使用ffmpeg給視頻增加字幕顯示的方法,執行個體分析了php操作ffmpeg給視頻增加字母的技巧,具有一定參考借鑒價值,需要的朋友可以參考下。

本文執行個體講述了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使用ffmpeg向視頻中添加文字字幕的實現方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.