@@ -32,27 +32,27 @@ discard block |
||
32 | 32 | 'ffprobePath' => '/usr/bin/ffprobe', |
33 | 33 | |
34 | 34 | // The options to use for ffprobe |
35 | - 'ffprobeOptions' => '-v quiet -print_format json -show_format -show_streams', |
|
35 | + 'ffprobeOptions' => '-v quiet -print_format json -show_format -show_streams', |
|
36 | 36 | |
37 | 37 | // The path where the transcoded videos are stored; must have a trailing / |
38 | 38 | // Yii2 aliases are supported here |
39 | - 'transcoderPaths' => [ |
|
40 | - 'default' => '@webroot/transcoder/', |
|
41 | - 'video' => '@webroot/transcoder/video/', |
|
42 | - 'audio' => '@webroot/transcoder/audio/', |
|
43 | - 'thumbnail' => '@webroot/transcoder/thumbnail/', |
|
44 | - 'gif' => '@webroot/transcoder/gif/' |
|
45 | - ], |
|
39 | + 'transcoderPaths' => [ |
|
40 | + 'default' => '@webroot/transcoder/', |
|
41 | + 'video' => '@webroot/transcoder/video/', |
|
42 | + 'audio' => '@webroot/transcoder/audio/', |
|
43 | + 'thumbnail' => '@webroot/transcoder/thumbnail/', |
|
44 | + 'gif' => '@webroot/transcoder/gif/' |
|
45 | + ], |
|
46 | 46 | |
47 | 47 | // The URL where the transcoded videos are stored; must have a trailing / |
48 | 48 | // Yii2 aliases are supported here |
49 | - 'transcoderUrls' => [ |
|
50 | - 'default' => '@web/transcoder/', |
|
51 | - 'video' => '@web/transcoder/video/', |
|
52 | - 'audio' => '@web/transcoder/audio/', |
|
53 | - 'thumbnail' => '@web/transcoder/thumbnail/', |
|
54 | - 'gif' => '@web/transcoder/gif/' |
|
55 | - ], |
|
49 | + 'transcoderUrls' => [ |
|
50 | + 'default' => '@web/transcoder/', |
|
51 | + 'video' => '@web/transcoder/video/', |
|
52 | + 'audio' => '@web/transcoder/audio/', |
|
53 | + 'thumbnail' => '@web/transcoder/thumbnail/', |
|
54 | + 'gif' => '@web/transcoder/gif/' |
|
55 | + ], |
|
56 | 56 | |
57 | 57 | // Use a md5 hash for the filenames instead of parameterized naming |
58 | 58 | 'useHashedNames' => false, |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | 'audioCodecOptions' => '-async 1000', |
77 | 77 | ], |
78 | 78 | 'gif' => [ |
79 | - 'fileSuffix' => '.mp4', |
|
80 | - 'fileFormat' => 'mp4', |
|
81 | - 'videoCodec' => 'libx264', |
|
82 | - 'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ', |
|
79 | + 'fileSuffix' => '.mp4', |
|
80 | + 'fileFormat' => 'mp4', |
|
81 | + 'videoCodec' => 'libx264', |
|
82 | + 'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ', |
|
83 | 83 | ] |
84 | 84 | ], |
85 | 85 | |
@@ -145,12 +145,12 @@ discard block |
||
145 | 145 | 'audioChannels' => '2', |
146 | 146 | ], |
147 | 147 | |
148 | - // Default options for Gif encoding |
|
149 | - 'defaultGifOptions' => [ |
|
150 | - 'videoEncoder' => 'gif', |
|
151 | - 'fileSuffix' => '.mp4', |
|
152 | - 'fileFormat' => 'gif', |
|
153 | - 'videoCodec' => 'libx264', |
|
154 | - 'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ', |
|
155 | - ], |
|
148 | + // Default options for Gif encoding |
|
149 | + 'defaultGifOptions' => [ |
|
150 | + 'videoEncoder' => 'gif', |
|
151 | + 'fileSuffix' => '.mp4', |
|
152 | + 'fileFormat' => 'gif', |
|
153 | + 'videoCodec' => 'libx264', |
|
154 | + 'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ', |
|
155 | + ], |
|
156 | 156 | ]; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } else { |
187 | 187 | |
188 | 188 | // Kick off the transcoding |
189 | - $pid = $this->executeShellCommand($ffmpegCmd); |
|
189 | + $pid = $this->executeShellCommand($ffmpegCmd); |
|
190 | 190 | Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__); |
191 | 191 | |
192 | 192 | // Create a lockfile in tmp |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | |
756 | 756 | if (!empty($filePath)) { |
757 | 757 | |
758 | - // Dest path |
|
758 | + // Dest path |
|
759 | 759 | $destVideoPath = Craft::getAlias($settings['transcoderPaths']['gif']); |
760 | 760 | |
761 | 761 | // Options |
@@ -768,13 +768,13 @@ discard block |
||
768 | 768 | |
769 | 769 | // Build the basic command for ffmpeg |
770 | 770 | $ffmpegCmd = $settings['ffmpegPath'] |
771 | - . ' -f gif' |
|
771 | + . ' -f gif' |
|
772 | 772 | . ' -i ' . escapeshellarg($filePath) |
773 | 773 | . ' -vcodec ' . $thisEncoder['videoCodec'] |
774 | 774 | . ' ' . $thisEncoder['videoCodecOptions']; |
775 | 775 | |
776 | 776 | |
777 | - // Create the directory if it isn't there already |
|
777 | + // Create the directory if it isn't there already |
|
778 | 778 | if (!file_exists($destVideoPath)) { |
779 | 779 | mkdir($destVideoPath); |
780 | 780 | } |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | } else { |
810 | 810 | |
811 | 811 | // Kick off the transcoding |
812 | - $pid = $this->executeShellCommand($ffmpegCmd); |
|
812 | + $pid = $this->executeShellCommand($ffmpegCmd); |
|
813 | 813 | Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__); |
814 | 814 | |
815 | 815 | // Create a lockfile in tmp |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @var string |
53 | 53 | */ |
54 | - public $transcoderPaths = []; |
|
54 | + public $transcoderPaths = []; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * The URL where the transcoded videos are stored; must have a trailing / |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | 'audioCodecOptions' => '-async 1000', |
92 | 92 | ], |
93 | 93 | 'gif' => [ |
94 | - 'fileSuffix' => '.mp4', |
|
95 | - 'fileFormat' => 'mp4', |
|
96 | - 'videoCodec' => 'libx264', |
|
97 | - 'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ', |
|
94 | + 'fileSuffix' => '.mp4', |
|
95 | + 'fileFormat' => 'mp4', |
|
96 | + 'videoCodec' => 'libx264', |
|
97 | + 'videoCodecOptions' => '-pix_fmt yuv420p -movflags +faststart -filter:v crop=\'floor(in_w/2)*2:floor(in_h/2)*2\' ', |
|
98 | 98 | ] |
99 | 99 | ]; |
100 | 100 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @var array |
183 | 183 | */ |
184 | 184 | public $defaultGifOptions = [ |
185 | - 'videoEncoder' => 'gif', |
|
185 | + 'videoEncoder' => 'gif', |
|
186 | 186 | 'fileSuffix' => '', |
187 | 187 | 'fileFormat' => '', |
188 | 188 | 'videoCodec' => '', |
@@ -85,20 +85,20 @@ discard block |
||
85 | 85 | |
86 | 86 | if(count($matches) > 0) { |
87 | 87 | |
88 | - $rawDuration = $matches[1]; |
|
88 | + $rawDuration = $matches[1]; |
|
89 | 89 | |
90 | - // rawDuration is in 00:00:00.00 format. This converts it to seconds. |
|
91 | - $ar = array_reverse(explode(":", $rawDuration)); |
|
92 | - $duration = floatval($ar[0]); |
|
93 | - if (!empty($ar[1])) { |
|
94 | - $duration += intval($ar[1]) * 60; |
|
95 | - } |
|
96 | - if (!empty($ar[2])) { |
|
97 | - $duration += intval($ar[2]) * 60 * 60; |
|
98 | - } |
|
99 | - } else { |
|
100 | - $duration = 'unknown'; // with GIF as input, duration is unknown |
|
101 | - } |
|
90 | + // rawDuration is in 00:00:00.00 format. This converts it to seconds. |
|
91 | + $ar = array_reverse(explode(":", $rawDuration)); |
|
92 | + $duration = floatval($ar[0]); |
|
93 | + if (!empty($ar[1])) { |
|
94 | + $duration += intval($ar[1]) * 60; |
|
95 | + } |
|
96 | + if (!empty($ar[2])) { |
|
97 | + $duration += intval($ar[2]) * 60 * 60; |
|
98 | + } |
|
99 | + } else { |
|
100 | + $duration = 'unknown'; // with GIF as input, duration is unknown |
|
101 | + } |
|
102 | 102 | |
103 | 103 | // Get the time in the file that is already encoded |
104 | 104 | preg_match_all("/time=(.*?) bitrate/", $content, $matches); |
@@ -121,28 +121,28 @@ discard block |
||
121 | 121 | |
122 | 122 | //calculate the progress |
123 | 123 | if($duration != 'unknown') { |
124 | - $progress = round(($time / $duration) * 100); |
|
124 | + $progress = round(($time / $duration) * 100); |
|
125 | 125 | } else { |
126 | - $progress = 'unknown'; |
|
126 | + $progress = 'unknown'; |
|
127 | 127 | } |
128 | 128 | |
129 | - // return results |
|
129 | + // return results |
|
130 | 130 | if($progress != "unknown" && $progress < 100) { |
131 | - $result = [ |
|
132 | - 'filename' => $filename, |
|
133 | - 'duration' => $duration, |
|
134 | - 'time' => $time, |
|
135 | - 'progress' => $progress, |
|
136 | - ]; |
|
137 | - } elseif($progress == "unknown") { |
|
138 | - $result = [ |
|
139 | - 'filename' => $filename, |
|
140 | - 'duration' => 'unknown', |
|
141 | - 'time' => $time, |
|
142 | - 'progress' => 'unknown', |
|
143 | - 'message' => 'encoding GIF, can\'t determine duration' |
|
144 | - ]; |
|
145 | - } |
|
131 | + $result = [ |
|
132 | + 'filename' => $filename, |
|
133 | + 'duration' => $duration, |
|
134 | + 'time' => $time, |
|
135 | + 'progress' => $progress, |
|
136 | + ]; |
|
137 | + } elseif($progress == "unknown") { |
|
138 | + $result = [ |
|
139 | + 'filename' => $filename, |
|
140 | + 'duration' => 'unknown', |
|
141 | + 'time' => $time, |
|
142 | + 'progress' => 'unknown', |
|
143 | + 'message' => 'encoding GIF, can\'t determine duration' |
|
144 | + ]; |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 |