| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- set_time_limit(0);
- require '../../vendor/autoload.php';
- use Streaming\Representation;
- $ffmpeg = Streaming\FFMpeg::create([
- 'ffmpeg.binaries' => 'C:\FFmpeg\bin\ffmpeg.exe',
- 'ffprobe.binaries' => 'C:\FFmpeg\bin\ffprobe.exe',
- 'timeout' => 3600,
- ]);
- $GLOBALS["ffmpeg"] = $ffmpeg;
- $root = '../../assets';
- $folder = 'videos';
- FindPath($root, $folder, $ffmpeg);
- function Convert($file_path, $ffmpeg)
- {
- $r_1080p = (new Representation)->setKiloBitrate(4096)->setResize(1920, 1080);
- if (!file_exists("../." . substr($file_path, 0, -4) . ".m3u8")) {
- $video = $ffmpeg->open("../." . $file_path);
- $video->hls()
- ->x264()
- ->setHlsTime(300)
- ->addRepresentations([$r_1080p])
- ->save("../." . substr($file_path, 0, -4) . ".m3u8");
- $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(40))
- ->save("../." . substr($file_path, 0, -4) . ".jpg");
- $video
- ->gif(FFMpeg\Coordinate\TimeCode::fromSeconds(40), new FFMpeg\Coordinate\Dimension(640, 480), 5)
- ->save("../." . substr($file_path, 0, -4) . ".gif");
- }
- }
- function FindPath($root, $folder, $ffmpeg)
- {
- $rootPath = $root . '/' . $folder;
- $paths = array_diff(scandir($root . '/' . $folder), array('.', '..', 'Thumbs.db'));
- natsort($paths);
- echo ("<ul>");
- foreach ($paths as $path) {
- if (str_contains($path, '.')) {
- if (str_contains(strtolower($path), '.mp4') || str_contains(strtolower($path), '.wmv')) {
- echo ("<li data-jstree='{ " . '"type" : "file"' . " }' >");
- $title = explode(".", $path)[0];
- $file_path = substr($rootPath, 4) . "/" . $path;
- $path = "title:" . $title . "path:" . $file_path . " dir_id:" . $folder;
- echo ($path);
- echo ("</li>");
- Convert($file_path, $ffmpeg);
- }
- } else {
- echo ("<li>");
- echo ("dir_name: " . $path . "parent: " . $folder);
- FindPath($rootPath, $path, $ffmpeg);
- echo ("</li>");
- }
- }
- echo ("</ul>");
- }
|