PHP编程:PHP从FLV文件获取视频预览图的方法
发布时间:2020-12-13 02:28:05 所属栏目:PHP教程 来源:网络整理
导读:《PHP从FLV文件获取视频预览图的方法》要点: 本文介绍了PHP从FLV文件获取视频预览图的方法,希望对您有用。如果有疑问,可以联系我们。 PHP应用 本篇章节讲解PHP从FLV文件获取视频预览图的办法.供大家参考研究.具体实现办法如下: 代码如下: ?php /
《PHP从FLV文件获取视频预览图的方法》要点: PHP应用本篇章节讲解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['file'])) ? strval($_GET['file']) : 'video.flv'; $image = substr($videofile,strlen($videofile) - 4); $time = (isset($_GET['time'])) ? strval($_GET['time']) : '00:00:01'; // debug ("? File: ",$videofile); // debug (" Image: ",$image); // debug ("? Time: ",$time); // check time format if (!preg_match('/dd:dd:dd/',$time)) { ? $time = "00:00:00"; } if (isset($_GET['percent'])) { ? $percent = $_GET['percent']; // 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('/Duration: (.*?),/',$duration,$matches); ? $duration = $matches[1]; // debug ("Duration: ",$duration); ? $duration_array = split(':',$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['browser'])) ? strval($_GET['browser']) : 'true'; // debug (" Browser: ",$browser); if ($browser == "true") { ? header('Content-Type: image/png'); ? exec("/usr/bin/ffmpeg -vcodec png -i "" . $videofile . "" -ss " . $time . " -vframes 1 -f image2 -"); //header('Content-Type: image/jpeg'); //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从FLV文件获取视频预览图的方法》是否对您有启发,欢迎查看更多与《PHP从FLV文件获取视频预览图的方法》相关教程,学精学透。编程之家 52php.cn为您提供精彩教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |