PHP adds subtitle display to video, using FFmpeg

Source: Internet
Author: User
Usage:copy code above to encoder.php place this file to your Web server root directory, install all the requried too LS needed to use ffmpeg-php now place some Video.avi and video.srt or video.sub etc video.idx subtitle, to encode video wi Th SRT Visit your script http://yourip/encoder.php it should grab thumbnail then start the encoding job, refresh page and Thats it

This encoding script have been tested on a bare bone VPS ubuntu 8.04 Server with the following tools installed

Apache2
PHP5
Php-cli
ffmpeg-php
Ffmpeg
MEncoder

Optional:mplayer-could is used instead of ffmpeg to grab thumbnails
  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-O F AVI-NOODML-OVC x264-x264encop$
  32. $res = Shell_exec ($cmd);
  33. }
  34. ?>
Copy Code
  • 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.