Passed
Push — develop ( 799e1d...6426b3 )
by Andrew
09:12 queued 04:31
created
src/services/Transcode.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -124,20 +124,20 @@  discard block
 block discarded – undo
124 124
 
125 125
             // Build the basic command for ffmpeg
126 126
             $ffmpegCmd = $settings['ffmpegPath']
127
-                . ' -i ' . escapeshellarg($filePath)
128
-                . ' -vcodec ' . $thisEncoder['videoCodec']
129
-                . ' ' . $thisEncoder['videoCodecOptions']
127
+                . ' -i '.escapeshellarg($filePath)
128
+                . ' -vcodec '.$thisEncoder['videoCodec']
129
+                . ' '.$thisEncoder['videoCodecOptions']
130 130
                 . ' -bufsize 1000k'
131
-                . ' -threads ' . $thisEncoder['threads'];
131
+                . ' -threads '.$thisEncoder['threads'];
132 132
 
133 133
             // Set the framerate if desired
134 134
             if (!empty($videoOptions['videoFrameRate'])) {
135
-                $ffmpegCmd .= ' -r ' . $videoOptions['videoFrameRate'];
135
+                $ffmpegCmd .= ' -r '.$videoOptions['videoFrameRate'];
136 136
             }
137 137
 
138 138
             // Set the bitrate if desired
139 139
             if (!empty($videoOptions['videoBitRate'])) {
140
-                $ffmpegCmd .= ' -b:v ' . $videoOptions['videoBitRate'] . ' -maxrate ' . $videoOptions['videoBitRate'];
140
+                $ffmpegCmd .= ' -b:v '.$videoOptions['videoBitRate'].' -maxrate '.$videoOptions['videoBitRate'];
141 141
             }
142 142
 
143 143
             // Adjust the scaling if desired
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
                 $ffmpegCmd .= ' -c:a copy';
156 156
             } else {
157 157
                 // Do audio transcoding based on the settings
158
-                $ffmpegCmd .= ' -acodec ' . $thisEncoder['audioCodec'];
158
+                $ffmpegCmd .= ' -acodec '.$thisEncoder['audioCodec'];
159 159
                 if (!empty($videoOptions['audioBitRate'])) {
160
-                    $ffmpegCmd .= ' -b:a ' . $videoOptions['audioBitRate'];
160
+                    $ffmpegCmd .= ' -b:a '.$videoOptions['audioBitRate'];
161 161
                 }
162 162
                 if (!empty($videoOptions['audioSampleRate'])) {
163
-                    $ffmpegCmd .= ' -ar ' . $videoOptions['audioSampleRate'];
163
+                    $ffmpegCmd .= ' -ar '.$videoOptions['audioSampleRate'];
164 164
                 }
165 165
                 if (!empty($videoOptions['audioChannels'])) {
166
-                    $ffmpegCmd .= ' -ac ' . $videoOptions['audioChannels'];
166
+                    $ffmpegCmd .= ' -ac '.$videoOptions['audioChannels'];
167 167
                 }
168
-                $ffmpegCmd .= ' ' . $thisEncoder['audioCodecOptions'];
168
+                $ffmpegCmd .= ' '.$thisEncoder['audioCodecOptions'];
169 169
             }
170 170
 
171 171
             // Create the directory if it isn't there already
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
             $destVideoFile = $this->getFilename($filePath, $videoOptions);
181 181
 
182 182
             // File to store the video encoding progress in
183
-            $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.progress';
183
+            $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.progress';
184 184
 
185 185
             // Assemble the destination path and final ffmpeg command
186 186
             $destVideoPath .= $destVideoFile;
187 187
             $ffmpegCmd .= ' -f '
188 188
                 . $thisEncoder['fileFormat']
189
-                . ' -y ' . escapeshellarg($destVideoPath)
190
-                . ' 1> ' . $progressFile . ' 2>&1 & echo $!';
189
+                . ' -y '.escapeshellarg($destVideoPath)
190
+                . ' 1> '.$progressFile.' 2>&1 & echo $!';
191 191
 
192 192
             // Make sure there isn't a lockfile for this video already
193
-            $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.lock';
193
+            $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.lock';
194 194
             $oldPid = @file_get_contents($lockFile);
195 195
             if ($oldPid !== false) {
196 196
                 // See if the process is running, and empty result means the process is still running
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
             if (file_exists($destVideoPath) && (@filemtime($destVideoPath) >= @filemtime($filePath))) {
209 209
                 $url = $settings['transcoderUrls']['video'] ?? $settings['transcoderUrls']['default'];
210 210
                 $url .= $subfolder;
211
-                $result = Craft::parseEnv($url) . $destVideoFile;
211
+                $result = Craft::parseEnv($url).$destVideoFile;
212 212
             // skip encoding
213 213
             } elseif (!$generate) {
214 214
                 $result = "";
215 215
             } else {
216 216
                 // Kick off the transcoding
217 217
                 $pid = $this->executeShellCommand($ffmpegCmd);
218
-                Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
218
+                Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
219 219
 
220 220
                 // Create a lockfile in tmp
221 221
                 file_put_contents($lockFile, $pid);
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 
259 259
             // Build the basic command for ffmpeg
260 260
             $ffmpegCmd = $settings['ffmpegPath']
261
-                . ' -i ' . escapeshellarg($filePath)
261
+                . ' -i '.escapeshellarg($filePath)
262 262
                 . ' -vcodec mjpeg'
263 263
                 . ' -vframes 1';
264 264
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
             // Set the timecode to get the thumbnail from if desired
272 272
             if (!empty($thumbnailOptions['timeInSecs'])) {
273 273
                 $timeCode = gmdate('H:i:s', $thumbnailOptions['timeInSecs']);
274
-                $ffmpegCmd .= ' -ss ' . $timeCode . '.00';
274
+                $ffmpegCmd .= ' -ss '.$timeCode.'.00';
275 275
             }
276 276
 
277 277
             // Create the directory if it isn't there already
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 
288 288
             // Assemble the destination path and final ffmpeg command
289 289
             $destThumbnailPath .= $destThumbnailFile;
290
-            $ffmpegCmd .= ' -f image2 -y ' . escapeshellarg($destThumbnailPath) . ' >/dev/null 2>/dev/null &';
290
+            $ffmpegCmd .= ' -f image2 -y '.escapeshellarg($destThumbnailPath).' >/dev/null 2>/dev/null &';
291 291
 
292 292
             // If the thumbnail file already exists, return it.  Otherwise, generate it and return it
293 293
             if (!file_exists($destThumbnailPath)) {
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 
302 302
                     return false;
303 303
                 } else {
304
-                    Craft::info('Thumbnail does not exist, but not asked to generate it: ' . $filePath, __METHOD__);
304
+                    Craft::info('Thumbnail does not exist, but not asked to generate it: '.$filePath, __METHOD__);
305 305
 
306 306
                     // The file doesn't exist, and we weren't asked to generate it
307 307
                     return false;
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
             } else {
314 314
                 $url = $settings['transcoderUrls']['thumbnail'] ?? $settings['transcoderUrls']['default'];
315 315
                 $url .= $subfolder;
316
-                $result = Craft::parseEnv($url) . $destThumbnailFile;
316
+                $result = Craft::parseEnv($url).$destThumbnailFile;
317 317
             }
318 318
         }
319 319
 
@@ -357,33 +357,33 @@  discard block
 block discarded – undo
357 357
 
358 358
             // Build the basic command for ffmpeg
359 359
             $ffmpegCmd = $settings['ffmpegPath']
360
-                . ' -i ' . escapeshellarg($filePath)
361
-                . ' -acodec ' . $thisEncoder['audioCodec']
362
-                . ' ' . $thisEncoder['audioCodecOptions']
360
+                . ' -i '.escapeshellarg($filePath)
361
+                . ' -acodec '.$thisEncoder['audioCodec']
362
+                . ' '.$thisEncoder['audioCodecOptions']
363 363
                 . ' -bufsize 1000k'
364 364
                 . ' -vn'
365
-                . ' -threads ' . $thisEncoder['threads'];
365
+                . ' -threads '.$thisEncoder['threads'];
366 366
 
367 367
             // Set the bitrate if desired
368 368
             if (!empty($audioOptions['audioBitRate'])) {
369
-                $ffmpegCmd .= ' -b:a ' . $audioOptions['audioBitRate'];
369
+                $ffmpegCmd .= ' -b:a '.$audioOptions['audioBitRate'];
370 370
             }
371 371
             // Set the sample rate if desired
372 372
             if (!empty($audioOptions['audioSampleRate'])) {
373
-                $ffmpegCmd .= ' -ar ' . $audioOptions['audioSampleRate'];
373
+                $ffmpegCmd .= ' -ar '.$audioOptions['audioSampleRate'];
374 374
             }
375 375
             // Set the audio channels if desired
376 376
             if (!empty($audioOptions['audioChannels'])) {
377
-                $ffmpegCmd .= ' -ac ' . $audioOptions['audioChannels'];
377
+                $ffmpegCmd .= ' -ac '.$audioOptions['audioChannels'];
378 378
             }
379
-            $ffmpegCmd .= ' ' . $thisEncoder['audioCodecOptions'];
379
+            $ffmpegCmd .= ' '.$thisEncoder['audioCodecOptions'];
380 380
 
381 381
             if (!empty($audioOptions['seekInSecs'])) {
382
-                $ffmpegCmd .= ' -ss ' . $audioOptions['seekInSecs'];
382
+                $ffmpegCmd .= ' -ss '.$audioOptions['seekInSecs'];
383 383
             }
384 384
 
385 385
             if (!empty($audioOptions['timeInSecs'])) {
386
-                $ffmpegCmd .= ' -t ' . $audioOptions['timeInSecs'];
386
+                $ffmpegCmd .= ' -t '.$audioOptions['timeInSecs'];
387 387
             }
388 388
 
389 389
             // Create the directory if it isn't there already
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
             $destAudioFile = $this->getFilename($filePath, $audioOptions);
399 399
 
400 400
             // File to store the audio encoding progress in
401
-            $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destAudioFile . '.progress';
401
+            $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.progress';
402 402
 
403 403
             // Assemble the destination path and final ffmpeg command
404 404
             $destAudioPath .= $destAudioFile;
@@ -413,16 +413,16 @@  discard block
 block discarded – undo
413 413
             // Add the file format
414 414
             $ffmpegCmd .= ' -f '
415 415
                 . $thisEncoder['fileFormat']
416
-                . ' -y ' . escapeshellarg($destAudioPath);
416
+                . ' -y '.escapeshellarg($destAudioPath);
417 417
             // Handle the `synchronous` setting
418 418
             $synchronous = false;
419 419
             if (!empty($audioOptions['synchronous'])) {
420 420
                 $synchronous = $audioOptions['synchronous'];
421 421
             }
422 422
             if (!$synchronous) {
423
-                $ffmpegCmd .= ' 1> ' . $progressFile . ' 2>&1 & echo $!';
423
+                $ffmpegCmd .= ' 1> '.$progressFile.' 2>&1 & echo $!';
424 424
                 // Make sure there isn't a lockfile for this audio file already
425
-                $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destAudioFile . '.lock';
425
+                $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.lock';
426 426
                 $oldPid = @file_get_contents($lockFile);
427 427
                 if ($oldPid !== false) {
428 428
                     // See if the process is running, and empty result means the process is still running
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
             if (file_exists($destAudioPath) && (@filemtime($destAudioPath) >= @filemtime($filePath))) {
442 442
                 $url = $settings['transcoderUrls']['audio'] ?? $settings['transcoderUrls']['default'];
443 443
                 $url .= $subfolder;
444
-                $result = Craft::parseEnv($url) . $destAudioFile;
444
+                $result = Craft::parseEnv($url).$destAudioFile;
445 445
             } else {
446 446
                 // Kick off the transcoding
447 447
                 $pid = $this->executeShellCommand($ffmpegCmd);
@@ -450,9 +450,9 @@  discard block
 block discarded – undo
450 450
                     Craft::info($ffmpegCmd, __METHOD__);
451 451
                     $url = $settings['transcoderUrls']['audio'] ?? $settings['transcoderUrls']['default'];
452 452
                     $url .= $subfolder;
453
-                    $result = Craft::parseEnv($url) . $destAudioFile;
453
+                    $result = Craft::parseEnv($url).$destAudioFile;
454 454
                 } else {
455
-                    Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
455
+                    Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
456 456
                     // Create a lockfile in tmp
457 457
                     file_put_contents($lockFile, $pid);
458 458
                 }
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
             // Build the basic command for ffprobe
481 481
             $ffprobeOptions = $settings['ffprobeOptions'];
482 482
             $ffprobeCmd = $settings['ffprobePath']
483
-                . ' ' . $ffprobeOptions
484
-                . ' ' . escapeshellarg($filePath);
483
+                . ' '.$ffprobeOptions
484
+                . ' '.escapeshellarg($filePath);
485 485
 
486 486
             $shellOutput = $this->executeShellCommand($ffprobeCmd);
487 487
             Craft::info($ffprobeCmd, __METHOD__);
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
                     && (strpos($summaryResult['videoFrameRate'], '/') !== false)
528 528
                 ) {
529 529
                     $parts = explode('/', $summaryResult['videoFrameRate']);
530
-                    $summaryResult['videoFrameRate'] = (float)$parts[0] / (float)$parts[1];
530
+                    $summaryResult['videoFrameRate'] = (float) $parts[0] / (float) $parts[1];
531 531
                 }
532 532
                 $result = $summaryResult;
533 533
             }
@@ -662,9 +662,9 @@  discard block
 block discarded – undo
662 662
             // Build the basic command for ffmpeg
663 663
             $ffmpegCmd = $settings['ffmpegPath']
664 664
                 . ' -f gif'
665
-                . ' -i ' . escapeshellarg($filePath)
666
-                . ' -vcodec ' . $thisEncoder['videoCodec']
667
-                . ' ' . $thisEncoder['videoCodecOptions'];
665
+                . ' -i '.escapeshellarg($filePath)
666
+                . ' -vcodec '.$thisEncoder['videoCodec']
667
+                . ' '.$thisEncoder['videoCodecOptions'];
668 668
 
669 669
 
670 670
             // Create the directory if it isn't there already
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
             $destVideoFile = $this->getFilename($filePath, $gifOptions);
680 680
 
681 681
             // File to store the video encoding progress in
682
-            $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.progress';
682
+            $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.progress';
683 683
 
684 684
             // Assemble the destination path and final ffmpeg command
685 685
             $destVideoPath .= $destVideoFile;
686 686
             $ffmpegCmd .= ' '
687
-                . ' -y ' . escapeshellarg($destVideoPath)
688
-                . ' 1> ' . $progressFile . ' 2>&1 & echo $!';
687
+                . ' -y '.escapeshellarg($destVideoPath)
688
+                . ' 1> '.$progressFile.' 2>&1 & echo $!';
689 689
 
690 690
             // Make sure there isn't a lockfile for this video already
691
-            $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.lock';
691
+            $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.lock';
692 692
             $oldPid = @file_get_contents($lockFile);
693 693
             if ($oldPid !== false) {
694 694
                 // See if the process is running, and empty result means the process is still running
@@ -706,11 +706,11 @@  discard block
 block discarded – undo
706 706
             if (file_exists($destVideoPath) && (@filemtime($destVideoPath) >= @filemtime($filePath))) {
707 707
                 $url = $settings['transcoderUrls']['gif'] ?? $settings['transcoderUrls']['default'];
708 708
                 $url .= $subfolder;
709
-                $result = Craft::parseEnv($url) . $destVideoFile;
709
+                $result = Craft::parseEnv($url).$destVideoFile;
710 710
             } else {
711 711
                 // Kick off the transcoding
712 712
                 $pid = $this->executeShellCommand($ffmpegCmd);
713
-                Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
713
+                Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
714 714
 
715 715
                 // Create a lockfile in tmp
716 716
                 file_put_contents($lockFile, $pid);
@@ -751,16 +751,16 @@  discard block
 block discarded – undo
751 751
                     $suffix = self::SUFFIX_MAP[$key];
752 752
                 }
753 753
                 if (is_bool($value)) {
754
-                    $value = $value ? $key : 'no' . $key;
754
+                    $value = $value ? $key : 'no'.$key;
755 755
                 }
756 756
                 if (!in_array($key, self::EXCLUDE_PARAMS, true)) {
757
-                    $fileName .= '_' . $value . $suffix;
757
+                    $fileName .= '_'.$value.$suffix;
758 758
                 }
759 759
             }
760 760
         }
761 761
         // See if we should use a hash instead
762 762
         if ($settings['useHashedNames']) {
763
-            $fileName = $pathParts['filename'] . md5($fileName);
763
+            $fileName = $pathParts['filename'].md5($fileName);
764 764
         }
765 765
         $fileName .= $options['fileSuffix'];
766 766
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
                     }
801 801
                     $folderPath .= '' === $folderPath ? '' : DIRECTORY_SEPARATOR;
802 802
 
803
-                    $filePath = $sourcePath . $folderPath . $asset->filename;
803
+                    $filePath = $sourcePath.$folderPath.$asset->filename;
804 804
                 } else {
805 805
                     // Otherwise, get a URL
806 806
                     $filePath = $asset->getUrl();
@@ -842,16 +842,16 @@  discard block
 block discarded – undo
842 842
                     case 'letterbox':
843 843
                         $letterboxColor = '';
844 844
                         if (!empty($options['letterboxColor'])) {
845
-                            $letterboxColor = ':color=' . $options['letterboxColor'];
845
+                            $letterboxColor = ':color='.$options['letterboxColor'];
846 846
                         }
847 847
                         $aspectRatio = ':force_original_aspect_ratio=decrease'
848
-                            . ',pad=' . $options['width'] . ':' . $options['height'] . ':(ow-iw)/2:(oh-ih)/2'
848
+                            . ',pad='.$options['width'].':'.$options['height'].':(ow-iw)/2:(oh-ih)/2'
849 849
                             . $letterboxColor;
850 850
                         break;
851 851
                     // Scale to the appropriate aspect ratio, cropping
852 852
                     case 'crop':
853 853
                         $aspectRatio = ':force_original_aspect_ratio=increase'
854
-                            . ',crop=' . $options['width'] . ':' . $options['height'];
854
+                            . ',crop='.$options['width'].':'.$options['height'];
855 855
                         break;
856 856
                     // No aspect ratio scaling at all
857 857
                     default:
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
                 $sharpen = ',unsharp=5:5:1.0:5:5:0.0';
866 866
             }
867 867
             $ffmpegCmd .= ' -vf "scale='
868
-                . $options['width'] . ':' . $options['height']
868
+                . $options['width'].':'.$options['height']
869 869
                 . $aspectRatio
870 870
                 . $sharpen
871 871
                 . '"';
Please login to merge, or discard this patch.