php使用ffmpeg获取视频信息并截图的方法。具体如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
$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_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname;// load extensionif (!extension_loaded($extension)) { dl($extension_soname) or die("Can't load extension $extension_fullnamen");}if (php_sapi_name() != 'cli') { echo '';}printf("ffmpeg-php build date string: %sn", FFMPEG_PHP_BUILD_DATE_STRING);printf("libavcodec build number: %dn", LIBAVCODEC_BUILD_NUMBER);printf("libavcodec version number: %dn", 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 "--------------------nn";foreach($movies as $movie) { $mov = new ffmpeg_movie($movie); printf("file name = %sn", $mov->getFileName()); printf("duration = %s secondsn", $mov->getDuration()); printf("frame count = %sn", $mov->getFrameCount()); printf("frame rate = %0.3f fpsn", $mov->getFrameRate()); printf("comment = %sn", $mov->getComment()); printf("title = %sn", $mov->getTitle()); printf("author = %sn", $mov->getAuthor()); printf("copyright = %sn", $mov->getCopyright()); printf("get bit rate = %dn", $mov->getBitRate()); printf("has audio = %sn", $mov->hasAudio() == 0 ? 'No' : 'Yes'); if ($mov->hasAudio()) { printf("get audio stream id= %sn", $mov->getAudioStreamId()); printf("get audio codec = %sn", $mov->getAudioCodec()); printf("get audio bit rate = %dn", $mov->getAudioBitRate()); printf("get audio sample rate = %d n", $mov->getAudioSampleRate()); printf("get audio channels = %sn", $mov->getAudioChannels()); } printf("has video = %sn", $mov->hasVideo() == 0 ? 'No' : 'Yes'); if ($mov->hasVideo()) { printf("frame height = %d pixelsn", $mov->getFrameHeight()); printf("frame width = %d pixelsn", $mov->getFrameWidth()); printf("get video stream id= %sn", $mov->getVideoStreamId()); printf("get video codec = %sn", $mov->getVideoCodec()); printf("get video bit rate = %dn", $mov->getVideoBitRate()); printf("get pixel format = %sn", $mov->getPixelFormat()); printf("get pixel aspect ratio = %sn", $mov->getPixelAspectRatio()); $frame = $mov->getFrame(10); printf("get frame = %sn", is_object($frame) ? 'true' : 'false'); printf(" get frame number = %dn", $mov->getFrameNumber()); printf(" get frame width = %dn", $frame->getWidth()); printf(" get frame height = %dn", $frame->getHeight()); } echo "n--------------------nn";}if (php_sapi_name() != 'cli') { echo '';}/* FUNCTIONS */ 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 Definedn"; }}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;}?> |
© 版权声明
本文刊载的所有内容,包括文字、图片、音频、视频、软件、程序、以及网页版式设计等部门来源于互联网,版权均归原作者所有!本网站提供的内容服务于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利。
联系信息:邮箱aoxolcom@163.com或见网站底部。
联系信息:邮箱aoxolcom@163.com或见网站底部。
THE END















请登录后发表评论
注册
社交帐号登录