스크린샷을 얻기 위해 PHP를 사용하여 flv 파일을 작동하는 방법

墨辰丷
풀어 주다: 2023-03-31 19:52:02
원래의
1342명이 탐색했습니다.

이 글에서는 주로 FLV 파일에서 비디오 미리보기를 얻는 방법을 소개합니다. 이는 flv 파일을 조작하여 스크린샷을 얻는 방법을 분석합니다. 필요한 친구는 이 글을 참조할 수 있습니다. FLV 파일에서 비디오 미리보기 이미지를 가져오는 방법에서 PHP의 예를 설명합니다. 구체적인 구현 방법은 다음과 같습니다.

코드는 다음과 같습니다.

<?php
// references http://www.longtailvideo.com/support/forum/Modules/12661/External-PHP-with-FFmpeg-using-readfile-
// generate a preview image from an FLV file on-the-fly, or to save
// call with: ffmpeg_image.php?file=video.flv&time=00:00:05&browser=true
// call with: ffmpeg_image.php?file=video.flv&percent=75.3&browser=true
// no time defaults to "00:00:01" (one second), no browser defaults to "true"
$videofile = (isset($_GET[&#39;file&#39;])) ? strval($_GET[&#39;file&#39;]) : &#39;video.flv&#39;;
$image = substr($videofile, 0, strlen($videofile) - 4);
$time = (isset($_GET[&#39;time&#39;])) ? strval($_GET[&#39;time&#39;]) : &#39;00:00:01&#39;;
// debug ("  File: ", $videofile);
// debug (" Image: ", $image);
// debug ("  Time: ", $time);
// check time format
if (!preg_match(&#39;/\d\d:\d\d:\d\d/&#39;, $time))
{
  $time = "00:00:00";
}
if (isset($_GET[&#39;percent&#39;]))
{
  $percent = $_GET[&#39;percent&#39;];
// debug (" Percent: ", $percent);
  ob_start();
  exec("/usr/bin/ffmpeg -i \"". $videofile . "\" 2>&1");
  $duration = ob_get_contents();
  ob_end_clean();
  // debug ("Duration: ", $duration);
  preg_match(&#39;/Duration: (.*?),/&#39;, $duration, $matches);
  $duration = $matches[1];
// debug ("Duration: ", $duration);
  $duration_array = split(&#39;:&#39;, $duration);
  $duration = $duration_array[0] * 3600 + $duration_array[1] * 60 + $duration_array[2];
  $time = $duration * $percent / 100;
// debug (" Time: ", $time);
  $time = intval($time/3600) . ":" . intval(($time-(intval($time/3600)*3600))/60) . ":" . sprintf("%01.3f", ($time-(intval($time/60)*60)));
// debug (" Time: ", $time);
}
$browser = (isset($_GET[&#39;browser&#39;])) ? strval($_GET[&#39;browser&#39;]) : &#39;true&#39;;
// debug (" Browser: ", $browser);
if ($browser == "true")
{
  header(&#39;Content-Type: image/png&#39;);
  exec("/usr/bin/ffmpeg -vcodec png -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 -");
//header(&#39;Content-Type: image/jpeg&#39;);
//exec("/usr/bin/ffmpeg -vcodec mjpeg -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 -");
}
else
{
  exec("/usr/bin/ffmpeg -vcodec png -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 \"" . $image . "\"%d.png");
//exec("/usr/bin/ffmpeg -vcodec mjpeg -i \"" . $videofile . "\" -ss " . $time . " -vframes 1 -f image2 \"" . $image . "\"%d.jpg");
}
?>
로그인 후 복사

요약

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

PHP 흐름의 기본 지식

PHP의 static 키워드 정의, 후기 바인딩 및 self 키워드와의 차이점

PHP 싱글턴 모드의 개념과 특징

위 내용은 스크린샷을 얻기 위해 PHP를 사용하여 flv 파일을 작동하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!