php操作flv文件获取截图的方法

墨辰丷
发布: 2023-03-31 19:52:02
原创
1343 人浏览过

这篇文章主要介绍了PHP从FLV文件获取视频预览图的方法,实例分析了php操作flv文件获取截图的技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了PHP从FLV文件获取视频预览图的方法。具体实现方法如下:

代码如下:

<?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学习者快速成长!