-
Notifications
You must be signed in to change notification settings - Fork 1
/
thumbnail.php
72 lines (52 loc) · 1.57 KB
/
thumbnail.php
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
<?php
/*=====================
* FFmpeg Tile Thumbnailer
/*=====================*/
require 'config.php';
if(isset($_POST['video']) && !empty($_POST['video'])) {
//Set 0 Limit Time
set_time_limit(0);
//Set FFmpeg installation Path
if (substr(php_uname(), 0, 7) == "Windows")
{
//windows
// $ffmpeg_path = BASE . '/ffmpeg.exe';
$ffmpeg_path = 'ffmpeg';
}
else {
//linux or others ( if the conversion operation did not work, edit this path )
$ffmpeg_path = 'bin/ffmpeg';
}
//========== Next Step =========>
//Get Video File
$inputVideo = trim( $_POST['video'] );
//Set Output Image name
$newName = STORAGE . basename($inputVideo) . rand() . '.jpg';
//Set Output Image path
$output = BASE . $newName;
//Set Tile Mode
$tile_1 = trim($_POST['tile_1']);
$tile_1 = intval($tile_1);
$tile_2 = trim($_POST['tile_2']);
$tile_2 = intval($tile_2);
$tile = $tile_1 . 'x' . $tile_2;
//Set Each Thumb Size
$size_1 = trim($_POST['size_1']);
$size_1 = intval($size_1);
$size_2 = trim($_POST['size_2']);
$size_2 = intval($size_2);
$size = $size_1 . 'x' . $size_2;
//Make Capture Every Below Time (default is 4 seconds)
$time = '00:00:04';
//Generate FFmpeg Command
$command = "$ffmpeg_path -ss $time -i $inputVideo -vf select=not(mod(n\,1000)),scale=$size,tile=$tile $output";
//Excute FFmpeg Command
shell_exec($command);
// ensure the output file is ready
if(!file_exists($output)) {
sleep(2);
}
//Response
exit(json_encode(['status' => true, 'image' => URI . $newName]));
}
else exit(json_encode(['status' => 'NOT']));