您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/2/20 3:49:15发布389次查看
这篇文章主要介绍了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['file'])) ? strval($_get['file']) : 'video.flv';$image = substr($videofile, 0, strlen($videofile) - 4);$time = (isset($_get['time'])) ? strval($_get['time']) : '00:00:01';// debug (" file: ", $videofile);// debug (" image: ", $image);// debug (" time: ", $time);// check time formatif (!preg_match('/\d\d:\d\d:\d\d/', $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中static关键字的定义、迟绑定以及与self关键字的区别
php单例模式的概念及特点
以上就是php操作flv文件获取截图的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product