本文实例讲述了php使用ffmpeg获取视频信息并截图的方法。分享给大家供大家参考,具体如下:
$movie = new ffmpeg_movie('4.mp4'); $width=$movie->getFrameWidth(); $height=$movie->getFrameHeight(); $count= $movie->getFrameCount(); print $count . ''; $n = round ( $count/16 ); print $n . ''; for ( $i = 1; $i <= 1; $i ++ ) { $img = 'screencap' . $i . '.png'; $x = $n * $i; $f = $movie->getFrame($x); $gd_image = $f->toGDImage(); imagepng($gd_image, $img); imagedestroy($gd_image); echo " \n"; } $extension = "ffmpeg"; $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX; $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname; // load extension if (!extension_loaded($extension)) { dl($extension_soname) or die("Can't load extension $extension_fullname\n"); } if (php_sapi_name() != 'cli') { echo ' '; } printf("ffmpeg-php version string: %s\n", FFMPEG_PHP_VERSION_STRING); printf("ffmpeg-php build date string: %s\n", FFMPEG_PHP_BUILD_DATE_STRING); printf("libavcodec build number: %d\n", LIBAVCODEC_BUILD_NUMBER); printf("libavcodec version number: %d\n", LIBAVCODEC_VERSION_NUMBER); print_class_methods("ffmpeg_movie"); print_class_methods("ffmpeg_frame"); // get an array for movies from the test media directory $movies = getDirFiles(dirname(__FILE__) . '/tests/test_media'); echo "--------------------\n\n"; foreach($movies as $movie) { $mov = new ffmpeg_movie($movie); printf("file name = %s\n", $mov->getFileName()); printf("duration = %s seconds\n", $mov->getDuration()); printf("frame count = %s\n", $mov->getFrameCount()); printf("frame rate = %0.3f fps\n", $mov->getFrameRate()); printf("comment = %s\n", $mov->getComment()); printf("title = %s\n", $mov->getTitle()); printf("author = %s\n", $mov->getAuthor()); printf("copyright = %s\n", $mov->getCopyright()); printf("get bit rate = %d\n", $mov->getBitRate()); printf("has audio = %s\n", $mov->hasAudio() == 0 "get audio stream id= %s\n", $mov->getAudioStreamId()); printf("get audio codec = %s\n", $mov->getAudioCodec()); printf("get audio bit rate = %d\n", $mov->getAudioBitRate()); printf("get audio sample rate = %d \n", $mov->getAudioSampleRate()); printf("get audio channels = %s\n", $mov->getAudioChannels()); } printf("has video = %s\n", $mov->hasVideo() == 0 "frame height = %d pixels\n", $mov->getFrameHeight()); printf("frame width = %d pixels\n", $mov->getFrameWidth()); printf("get video stream id= %s\n", $mov->getVideoStreamId()); printf("get video codec = %s\n", $mov->getVideoCodec()); printf("get video bit rate = %d\n", $mov->getVideoBitRate()); printf("get pixel format = %s\n", $mov->getPixelFormat()); printf("get pixel aspect ratio = %s\n", $mov->getPixelAspectRatio()); $frame = $mov->getFrame(10); printf("get frame = %s\n", is_object($frame) " get frame number = %d\n", $mov->getFrameNumber()); printf(" get frame width = %d\n", $frame->getWidth()); printf(" get frame height = %d\n", $frame->getHeight()); } echo "\n--------------------\n\n"; } if (php_sapi_name() != 'cli') { echo ''; } /* FUNCTIONS */ function print_class_methods($class) { echo "\nMethods available in class '$class':\n"; $methods = get_class_methods($class); if (is_array($methods)) { foreach($methods as $method) { echo $method . "\n"; } } else { echo "No Methods Defined\n"; } } function getDirFiles($dirPath) { if ($handle = opendir($dirPath)) { while (false !== ($file = readdir($handle))) { $fullpath = $dirPath . '/' . $file; if (!is_dir($fullpath) && $file != "CVS" && $file != "." && $file != "..") $filesArr[] = trim($fullpath); } closedir($handle); } return $filesArr; } "//img.jbzj.com/file_images/article/201605/20165395825072.png" alt="" />更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP图形与图片操作技巧汇总》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]