>  기사  >  백엔드 개발  >  ffmpeg를 사용하여 PHP를 사용하여 비디오에 자막을 추가하는 방법

ffmpeg를 사용하여 PHP를 사용하여 비디오에 자막을 추가하는 방법

墨辰丷
墨辰丷원래의
2018-06-12 16:31:562229검색

이 글에서는 주로 ffmpeg를 사용하여 PHP를 사용하여 비디오에 자막을 추가하는 방법을 소개합니다. ffmpeg를 사용하여 PHP를 사용하여 비디오에 자막을 추가하는 기술이 필요한 경우 참조할 수 있습니다. 이 기사에서는 ffmpeg를 사용하여 비디오에 자막을 추가하는 방법을 예제와 함께 설명합니다. 구체적인 구현 방법은 다음과 같습니다.

코드는 다음과 같습니다.

<?php
$dir = &#39;./&#39;; // set to current folder
if ($handle = opendir($dir)) {
 while(false!== ($file = readdir($handle))) {
 if ( is_file($dir.$file) ){
 if (preg_match("&#39;\.(avi)$&#39;", $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(&#39;input.avi&#39;, &#39;input.srt&#39;, &#39;output.jpg&#39;, &#39;output.ogm&#39;);
// 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 = &#39;ffmpeg -v 0 -y -i &#39;.$in.&#39; -vframes 1 -ss 250 -vcodec mjpeg -f rawvideo -s 286x160 -aspect 16:9 &#39;.$out_thumb;
 $res = shell_exec($cmd);
 // $res is the output of the command
 // transcode video
$cmd = &#39;mencoder &#39;.$in.&#39; -o &#39;.$out_vid.&#39; -sub &#39;.$in_sub.&#39; -subfont-text-scale 3.0 -subpos 99 -af volume=10 -aspect 16:9 -of avi -noodml -ovc x264 -x264encop$
 $res = shell_exec($cmd);
}
?>

요약

: 위는 이 글의 전체 내용입니다. 모든 분들의 학습에 도움이 되기를 바랍니다. 관련 추천:

PHP는 안티 리칭 설정으로 온라인 앨범에서 이미지를 캡처하는 기능을 구현합니다.

PHP는 색상 환경에 따라 이미지 워터마크를 동적으로 추가하는 기능을 구현합니다.

PHP는 Baidu 효과에 연결됩니다. Ajax 호출을 통해 웹사이트가 인터넷에 연결되어 있는지 여부를 감지합니다

위 내용은 ffmpeg를 사용하여 PHP를 사용하여 비디오에 자막을 추가하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.