PHP using FFmpeg to add text captions to video _php instance

Source: Internet
Author: User

This article mainly introduced the PHP use FFmpeg to add the caption display method to the video, the example analyzes the PHP operation FFmpeg to add the letter to the video skill, has certain reference value, needs the friend to be possible to refer under.

This example describes the way PHP uses FFmpeg to add subtitles to video. Share to everyone for your reference. The implementation methods are as follows:

 <?php $dir = './';//set to current folder if ($handle = Opendir ($dir)) {while F alse!== ($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! 
//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 command//transcode video $cmd = ' mencoder '. $in. ' o '. $out _vid. '-sub '. $in _sub. '-SUBF 
Ont-text-scale 3.0-subpos 99-af volume=10-aspect 16:9-of avi-noodml-ovc x264-x264encop$ $res = shell_exec ($cmd); } 

Above this PHP uses FFmpeg to the video to add the text caption The realization method is the small series to share to everybody's content, hoped can give everybody a reference, also hoped that everybody supports the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.