@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/BasicTranscoder.php'; |
|
| 3 | +require_once __DIR__.'/BasicTranscoder.php'; |
|
| 4 | 4 | |
| 5 | 5 | class AudioTranscoder extends BasicTranscoder |
| 6 | 6 | { |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | * Script used to get a file in AWS S3 |
| 5 | 5 | **/ |
| 6 | 6 | |
| 7 | -require __DIR__ . "/../../vendor/autoload.php"; |
|
| 7 | +require __DIR__."/../../vendor/autoload.php"; |
|
| 8 | 8 | |
| 9 | 9 | use Aws\S3\S3Client; |
| 10 | 10 | |
| 11 | 11 | function usage() |
| 12 | 12 | { |
| 13 | - echo("Usage: php ". basename(__FILE__) . " [-h] [--force] --bucket <s3 bucket> --file <filename> --to <filepath>\n"); |
|
| 13 | + echo("Usage: php ".basename(__FILE__)." [-h] [--force] --bucket <s3 bucket> --file <filename> --to <filepath>\n"); |
|
| 14 | 14 | echo("--help, -h: Print this help\n"); |
| 15 | 15 | echo("--bucket <s3 bucket>: Name of the S3 bucket\n"); |
| 16 | 16 | echo("--file <filename>: Name of the file in the S3 bucket\n"); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | file_exists($options['to']) && |
| 42 | 42 | filesize($options['to'])) |
| 43 | 43 | { |
| 44 | - print json_encode([ "status" => "SUCCESS", |
|
| 45 | - "msg" => "[".__FILE__."] Using local copy: '" . $options['to'] . "'" ]); |
|
| 44 | + print json_encode(["status" => "SUCCESS", |
|
| 45 | + "msg" => "[".__FILE__."] Using local copy: '".$options['to']."'"]); |
|
| 46 | 46 | exit(0); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | )); |
| 59 | 59 | |
| 60 | 60 | // Print JSON error output |
| 61 | - print json_encode([ "status" => "SUCCESS", |
|
| 62 | - "msg" => "[".__FILE__."] Download '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
|
| 61 | + print json_encode(["status" => "SUCCESS", |
|
| 62 | + "msg" => "[".__FILE__."] Download '".$options['bucket']."/".$options['file']."' successful !"]); |
|
| 63 | 63 | } |
| 64 | 64 | catch (Exception $e) { |
| 65 | - $err = "Unable to get '" . $options['bucket'] . "/" . $options['file'] . "' file from S3 ! " . $e->getMessage(); |
|
| 65 | + $err = "Unable to get '".$options['bucket']."/".$options['file']."' file from S3 ! ".$e->getMessage(); |
|
| 66 | 66 | // Print JSON error output |
| 67 | - print json_encode([ "status" => "ERROR", |
|
| 68 | - "msg" => "[".__FILE__."] $err" ]); |
|
| 67 | + print json_encode(["status" => "ERROR", |
|
| 68 | + "msg" => "[".__FILE__."] $err"]); |
|
| 69 | 69 | |
| 70 | 70 | die("[".__FILE__."] $err"); |
| 71 | 71 | } |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | function check_input_parameters($options) |
| 23 | 23 | { |
| 24 | 24 | if (!count($options) || isset($options['h']) || |
| 25 | - isset($options['help'])) |
|
| 26 | - usage(); |
|
| 25 | + isset($options['help'])) { |
|
| 26 | + usage(); |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | if (!isset($options['bucket']) || !isset($options['file']) || |
| 29 | 30 | !isset($options['to'])) |
@@ -60,8 +61,7 @@ discard block |
||
| 60 | 61 | // Print JSON error output |
| 61 | 62 | print json_encode([ "status" => "SUCCESS", |
| 62 | 63 | "msg" => "[".__FILE__."] Download '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
| 63 | -} |
|
| 64 | -catch (Exception $e) { |
|
| 64 | +} catch (Exception $e) { |
|
| 65 | 65 | $err = "Unable to get '" . $options['bucket'] . "/" . $options['file'] . "' file from S3 ! " . $e->getMessage(); |
| 66 | 66 | // Print JSON error output |
| 67 | 67 | print json_encode([ "status" => "ERROR", |
@@ -4,13 +4,13 @@ discard block |
||
| 4 | 4 | * Script used to put a file in AWS S3 |
| 5 | 5 | **/ |
| 6 | 6 | |
| 7 | -require __DIR__ . "/../../vendor/autoload.php"; |
|
| 7 | +require __DIR__."/../../vendor/autoload.php"; |
|
| 8 | 8 | |
| 9 | 9 | use Aws\S3\S3Client; |
| 10 | 10 | |
| 11 | 11 | function usage() |
| 12 | 12 | { |
| 13 | - echo("Usage: php ". basename(__FILE__) . " [-h] [--rrs::] [--encrypt::] --bucket <s3 bucket> --file <filename> --from <filepath>\n"); |
|
| 13 | + echo("Usage: php ".basename(__FILE__)." [-h] [--rrs::] [--encrypt::] --bucket <s3 bucket> --file <filename> --from <filepath>\n"); |
|
| 14 | 14 | echo("--help, -h: Print this help\n"); |
| 15 | 15 | echo("--bucket <s3 bucket>: Name of the S3 bucket\n"); |
| 16 | 16 | echo("--file <filename>: Name of the file to create in bucket. You can override local filename.\n"); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | usage(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - $options['bucket'] = rtrim( $options['bucket'], "/"); |
|
| 36 | + $options['bucket'] = rtrim($options['bucket'], "/"); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $options = getopt("h", [ |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | $s3->putObject($params); |
| 67 | 67 | |
| 68 | 68 | // Print JSON error output |
| 69 | - print json_encode([ "status" => "SUCCESS", |
|
| 70 | - "msg" => "[".__FILE__."] Upload '" . $options['from'] . "' to '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
|
| 69 | + print json_encode(["status" => "SUCCESS", |
|
| 70 | + "msg" => "[".__FILE__."] Upload '".$options['from']."' to '".$options['bucket']."/".$options['file']."' successful !"]); |
|
| 71 | 71 | } |
| 72 | 72 | catch (Exception $e) { |
| 73 | - $err = "Unable to put file '" . $options['from'] . "' into S3: '" . $options['bucket'] . "/" . $options['file'] . "'! " . $e->getMessage(); |
|
| 73 | + $err = "Unable to put file '".$options['from']."' into S3: '".$options['bucket']."/".$options['file']."'! ".$e->getMessage(); |
|
| 74 | 74 | |
| 75 | 75 | // Print JSON error output |
| 76 | - print json_encode([ "status" => "ERROR", |
|
| 77 | - "msg" => "[".__FILE__."] $err" ]); |
|
| 76 | + print json_encode(["status" => "ERROR", |
|
| 77 | + "msg" => "[".__FILE__."] $err"]); |
|
| 78 | 78 | |
| 79 | 79 | die("[".__FILE__."] $err"); |
| 80 | 80 | } |
@@ -23,8 +23,9 @@ discard block |
||
| 23 | 23 | function check_input_parameters(&$options) |
| 24 | 24 | { |
| 25 | 25 | if (!count($options) || isset($options['h']) || |
| 26 | - isset($options['help'])) |
|
| 27 | - usage(); |
|
| 26 | + isset($options['help'])) { |
|
| 27 | + usage(); |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | if (!isset($options['bucket']) || !isset($options['file']) || |
| 30 | 31 | !isset($options['from'])) |
@@ -57,10 +58,12 @@ discard block |
||
| 57 | 58 | ); |
| 58 | 59 | |
| 59 | 60 | // StorageClass and Encryption ? |
| 60 | - if (isset($options['rrs'])) |
|
| 61 | - $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
| 62 | - if (isset($options['encrypt'])) |
|
| 63 | - $params['ServerSideEncryption'] = 'AES256'; |
|
| 61 | + if (isset($options['rrs'])) { |
|
| 62 | + $params['StorageClass'] = 'REDUCED_REDUNDANCY'; |
|
| 63 | + } |
|
| 64 | + if (isset($options['encrypt'])) { |
|
| 65 | + $params['ServerSideEncryption'] = 'AES256'; |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | // Upload and Save file to S3 |
| 66 | 69 | $s3->putObject($params); |
@@ -68,8 +71,7 @@ discard block |
||
| 68 | 71 | // Print JSON error output |
| 69 | 72 | print json_encode([ "status" => "SUCCESS", |
| 70 | 73 | "msg" => "[".__FILE__."] Upload '" . $options['from'] . "' to '" . $options['bucket'] . "/" . $options['file'] . "' successful !" ]); |
| 71 | -} |
|
| 72 | -catch (Exception $e) { |
|
| 74 | +} catch (Exception $e) { |
|
| 73 | 75 | $err = "Unable to put file '" . $options['from'] . "' into S3: '" . $options['bucket'] . "/" . $options['file'] . "'! " . $e->getMessage(); |
| 74 | 76 | |
| 75 | 77 | // Print JSON error output |
@@ -17,8 +17,9 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct($cpeLogger = null) |
| 19 | 19 | { |
| 20 | - if (!$cpeLogger) |
|
| 21 | - $this->cpeLogger = new CpeSdk\CpeLogger(null, 'CommandExecuter'); |
|
| 20 | + if (!$cpeLogger) { |
|
| 21 | + $this->cpeLogger = new CpeSdk\CpeLogger(null, 'CommandExecuter'); |
|
| 22 | + } |
|
| 22 | 23 | $this->cpeLogger = $cpeLogger; |
| 23 | 24 | } |
| 24 | 25 | |
@@ -112,10 +113,12 @@ discard block |
||
| 112 | 113 | if ($procStatus['exitcode'] > 0) |
| 113 | 114 | { |
| 114 | 115 | $this->cpeLogger->log_out("ERROR", basename(__FILE__), "Can't execute: $cmd. Exit Code: ".$procStatus['exitcode']); |
| 115 | - if ($allOut) |
|
| 116 | - $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDOUT: ".$allOut); |
|
| 117 | - if ($allOutErr) |
|
| 118 | - $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDERR: ".$allOutErr); |
|
| 116 | + if ($allOut) { |
|
| 117 | + $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDOUT: ".$allOut); |
|
| 118 | + } |
|
| 119 | + if ($allOutErr) { |
|
| 120 | + $this->cpeLogger->log_out("ERROR", basename(__FILE__), "COMMAND STDERR: ".$allOutErr); |
|
| 121 | + } |
|
| 119 | 122 | } |
| 120 | 123 | |
| 121 | 124 | if ($showProgress) { |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * The scripts are executed using the CommandExecuter |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -require_once __DIR__ . '/CommandExecuter.php'; |
|
| 8 | +require_once __DIR__.'/CommandExecuter.php'; |
|
| 9 | 9 | |
| 10 | 10 | use SA\CpeSdk; |
| 11 | 11 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $callback = null, |
| 36 | 36 | $callbackParams = null) |
| 37 | 37 | { |
| 38 | - $cmd = "php " . __DIR__ . self::GET_FROM_S3; |
|
| 38 | + $cmd = "php ".__DIR__.self::GET_FROM_S3; |
|
| 39 | 39 | $cmd .= " --bucket $bucket"; |
| 40 | 40 | $cmd .= " --file $filename"; |
| 41 | 41 | $cmd .= " --to $saveFileTo"; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $callback = null, |
| 58 | 58 | $callbackParams = null) |
| 59 | 59 | { |
| 60 | - $cmd = "php " . __DIR__ . self::PUT_IN_S3; |
|
| 60 | + $cmd = "php ".__DIR__.self::PUT_IN_S3; |
|
| 61 | 61 | $cmd .= " --bucket $bucket"; |
| 62 | 62 | $cmd .= " --file $filename"; |
| 63 | 63 | $cmd .= " --from $pathToFileToSend"; |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function __construct($cpeLogger = null) |
| 24 | 24 | { |
| 25 | - if (!$cpeLogger) |
|
| 26 | - $this->cpeLogger = new CpeSdk\CpeLogger(null, 'S3Utils'); |
|
| 25 | + if (!$cpeLogger) { |
|
| 26 | + $this->cpeLogger = new CpeSdk\CpeLogger(null, 'S3Utils'); |
|
| 27 | + } |
|
| 27 | 28 | $this->cpeLogger = $cpeLogger; |
| 28 | 29 | } |
| 29 | 30 | |
@@ -61,10 +62,12 @@ discard block |
||
| 61 | 62 | $cmd .= " --bucket $bucket"; |
| 62 | 63 | $cmd .= " --file $filename"; |
| 63 | 64 | $cmd .= " --from $pathToFileToSend"; |
| 64 | - if ($options['rrs']) |
|
| 65 | - $cmd .= " --rrs"; |
|
| 66 | - if ($options['encrypt']) |
|
| 67 | - $cmd .= " --encrypt"; |
|
| 65 | + if ($options['rrs']) { |
|
| 66 | + $cmd .= " --rrs"; |
|
| 67 | + } |
|
| 68 | + if ($options['encrypt']) { |
|
| 69 | + $cmd .= " --encrypt"; |
|
| 70 | + } |
|
| 68 | 71 | |
| 69 | 72 | // HAndle execution |
| 70 | 73 | return ($this->handle_s3_ops( |
@@ -91,21 +94,25 @@ discard block |
||
| 91 | 94 | true, |
| 92 | 95 | 5); |
| 93 | 96 | |
| 94 | - if ($out['outErr']) |
|
| 95 | - throw new CpeSdk\CpeException($out['outErr'], |
|
| 97 | + if ($out['outErr']) { |
|
| 98 | + throw new CpeSdk\CpeException($out['outErr'], |
|
| 96 | 99 | self::S3_OPS_FAILED); |
| 100 | + } |
|
| 97 | 101 | |
| 98 | - if (!$out['out']) |
|
| 99 | - throw new CpeSdk\CpeException("Script '$caller' didn't return any data !", |
|
| 102 | + if (!$out['out']) { |
|
| 103 | + throw new CpeSdk\CpeException("Script '$caller' didn't return any data !", |
|
| 100 | 104 | self::NO_OUTPUT_DATA); |
| 105 | + } |
|
| 101 | 106 | |
| 102 | - if (!($decoded = json_decode($out['out'], true))) |
|
| 103 | - throw new CpeSdk\CpeException($out['out'], |
|
| 107 | + if (!($decoded = json_decode($out['out'], true))) { |
|
| 108 | + throw new CpeSdk\CpeException($out['out'], |
|
| 104 | 109 | self::S3_OPS_FAILED); |
| 110 | + } |
|
| 105 | 111 | |
| 106 | - if ($decoded["status"] == "ERROR") |
|
| 107 | - throw new CpeSdk\CpeException($decoded["msg"], |
|
| 112 | + if ($decoded["status"] == "ERROR") { |
|
| 113 | + throw new CpeSdk\CpeException($decoded["msg"], |
|
| 108 | 114 | self::S3_OPS_FAILED); |
| 115 | + } |
|
| 109 | 116 | |
| 110 | 117 | return ($decoded); |
| 111 | 118 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * This class allows you to call the two S3 scripts |
| 4 | 4 | * to download and upload files. |
| 5 | 5 | * The scripts are executed using the CommandExecuter |
| 6 | - */ |
|
| 6 | + */ |
|
| 7 | 7 | |
| 8 | 8 | require_once __DIR__ . '/CommandExecuter.php'; |
| 9 | 9 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $cmd, |
| 86 | 86 | 2, |
| 87 | 87 | array(1 => array("pipe", "w"), |
| 88 | - 2 => array("pipe", "w")), |
|
| 88 | + 2 => array("pipe", "w")), |
|
| 89 | 89 | $callback, |
| 90 | 90 | $callbackParams, |
| 91 | 91 | true, |
@@ -40,6 +40,12 @@ |
||
| 40 | 40 | // $metadata should contain the ffprobe video stream array. |
| 41 | 41 | |
| 42 | 42 | // Start FFmpeg for output transcoding |
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param string $tmpPathInput |
|
| 46 | + * @param null|string $pathToInputFile |
|
| 47 | + * @param string $pathToOutputFiles |
|
| 48 | + */ |
|
| 43 | 49 | public function transcode_asset( |
| 44 | 50 | $tmpPathInput, |
| 45 | 51 | $pathToInputFile, |
@@ -65,13 +65,14 @@ discard block |
||
| 65 | 65 | $this->activityLogKey |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | - if ($metadata) |
|
| 69 | - $this->cpeLogger->log_out( |
|
| 68 | + if ($metadata) { |
|
| 69 | + $this->cpeLogger->log_out( |
|
| 70 | 70 | "INFO", |
| 71 | 71 | basename(__FILE__), |
| 72 | 72 | "Input Video metadata: " . print_r($metadata, true), |
| 73 | 73 | $this->activityLogKey |
| 74 | 74 | ); |
| 75 | + } |
|
| 75 | 76 | |
| 76 | 77 | try { |
| 77 | 78 | $ffmpegCmd = ""; |
@@ -138,8 +139,7 @@ discard block |
||
| 138 | 139 | // FFProbe the output file and return its information |
| 139 | 140 | $output_info = |
| 140 | 141 | $this->get_asset_info($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
| 141 | - } |
|
| 142 | - catch (\Exception $e) { |
|
| 142 | + } catch (\Exception $e) { |
|
| 143 | 143 | $this->cpeLogger->log_out( |
| 144 | 144 | "ERROR", |
| 145 | 145 | basename(__FILE__), |
@@ -289,8 +289,7 @@ discard block |
||
| 289 | 289 | $time = gmdate("H:i:s", $snapshot_sec) . ".000"; |
| 290 | 290 | $pathToOutputFiles .= "/" . $outputFileInfo['basename']; |
| 291 | 291 | $frameOptions = " -ss $time -vframes 1"; |
| 292 | - } |
|
| 293 | - else if ($outputWanted->{'mode'} == 'intervals') |
|
| 292 | + } else if ($outputWanted->{'mode'} == 'intervals') |
|
| 294 | 293 | { |
| 295 | 294 | $intervals = self::INTERVALS_DEFAULT; |
| 296 | 295 | if (isset($outputWanted->{'intervals'}) && |
@@ -343,8 +342,7 @@ discard block |
||
| 343 | 342 | array(1 => array("pipe", "w"), 2 => array("pipe", "w")), |
| 344 | 343 | false, false, |
| 345 | 344 | false, 1); |
| 346 | - } |
|
| 347 | - catch (\Exception $e) { |
|
| 345 | + } catch (\Exception $e) { |
|
| 348 | 346 | $this->cpeLogger->log_out( |
| 349 | 347 | "ERROR", |
| 350 | 348 | basename(__FILE__), |
@@ -604,8 +602,7 @@ discard block |
||
| 604 | 602 | foreach ($metadata->streams as $key => $value) { |
| 605 | 603 | if ($value->codec_type === 'video') { |
| 606 | 604 | $videoStreams = $value; |
| 607 | - } |
|
| 608 | - else if ($value->codec_type === 'audio') { |
|
| 605 | + } else if ($value->codec_type === 'audio') { |
|
| 609 | 606 | $audioStreams = $value; |
| 610 | 607 | } |
| 611 | 608 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * We use ffprobe, ffmpeg and convert to analyse, transcode and manipulate videos and images (watermark) |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -require_once __DIR__ . '/BasicTranscoder.php'; |
|
| 10 | +require_once __DIR__.'/BasicTranscoder.php'; |
|
| 11 | 11 | |
| 12 | 12 | use SA\CpeSdk; |
| 13 | 13 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $this->cpeLogger->log_out( |
| 70 | 70 | "INFO", |
| 71 | 71 | basename(__FILE__), |
| 72 | - "Input Video metadata: " . print_r($metadata, true), |
|
| 72 | + "Input Video metadata: ".print_r($metadata, true), |
|
| 73 | 73 | $this->activityLogKey |
| 74 | 74 | ); |
| 75 | 75 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $this->cpeLogger->log_out( |
| 144 | 144 | "ERROR", |
| 145 | 145 | basename(__FILE__), |
| 146 | - "Execution of command '".$ffmpegCmd."' failed: " . print_r($metadata, true). ". ".$e->getMessage(), |
|
| 146 | + "Execution of command '".$ffmpegCmd."' failed: ".print_r($metadata, true).". ".$e->getMessage(), |
|
| 147 | 147 | $this->activityLogKey |
| 148 | 148 | ); |
| 149 | 149 | return false; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Append output filename to path |
| 189 | - $pathToOutputFiles .= "/" . $outputWanted->{'output_file_info'}['basename']; |
|
| 189 | + $pathToOutputFiles .= "/".$outputWanted->{'output_file_info'}['basename']; |
|
| 190 | 190 | // Replace ${output_file} by output filename and path to local disk |
| 191 | 191 | $ffmpegCmd = preg_replace('/\$\{output_file\}/', $pathToOutputFiles, $ffmpegCmd); |
| 192 | 192 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Create FFMpeg arguments |
| 249 | - $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 249 | + $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 250 | 250 | $ffmpegArgs .= " -vf scale=$size"; |
| 251 | 251 | $ffmpegArgs .= " -vcodec $videoCodec"; |
| 252 | 252 | $ffmpegArgs .= " -acodec $audioCodec"; |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | $ffmpegArgs .= " $watermarkOptions"; |
| 258 | 258 | |
| 259 | 259 | // Append output filename to path |
| 260 | - $pathToOutputFiles .= "/" . $outputWanted->{'output_file_info'}['basename']; |
|
| 260 | + $pathToOutputFiles .= "/".$outputWanted->{'output_file_info'}['basename']; |
|
| 261 | 261 | // Final command |
| 262 | - $ffmpegCmd = "ffmpeg $ffmpegArgs $pathToOutputFiles"; |
|
| 262 | + $ffmpegCmd = "ffmpeg $ffmpegArgs $pathToOutputFiles"; |
|
| 263 | 263 | |
| 264 | 264 | return ($ffmpegCmd); |
| 265 | 265 | } |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | $snapshot_sec = $outputWanted->{'snapshot_sec'}; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - $time = gmdate("H:i:s", $snapshot_sec) . ".000"; |
|
| 290 | - $pathToOutputFiles .= "/" . $outputFileInfo['basename']; |
|
| 289 | + $time = gmdate("H:i:s", $snapshot_sec).".000"; |
|
| 290 | + $pathToOutputFiles .= "/".$outputFileInfo['basename']; |
|
| 291 | 291 | $frameOptions = " -ss $time -vframes 1"; |
| 292 | 292 | } |
| 293 | 293 | else if ($outputWanted->{'mode'} == 'intervals') |
@@ -298,14 +298,14 @@ discard block |
||
| 298 | 298 | $intervals = $outputWanted->{'intervals'}; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - $pathToOutputFiles .= "/" . $outputFileInfo['filename'] . "%06d." |
|
| 301 | + $pathToOutputFiles .= "/".$outputFileInfo['filename']."%06d." |
|
| 302 | 302 | . $outputFileInfo['extension']; |
| 303 | 303 | $frameOptions = " -vf fps=fps=1/$intervals"; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | // Create FFMpeg arguments |
| 307 | - $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 308 | - $ffmpegArgs .= " -vf scale=" . $outputWanted->{'size'}; |
|
| 307 | + $ffmpegArgs = " -i $pathToInputFile -y -threads 0"; |
|
| 308 | + $ffmpegArgs .= " -vf scale=".$outputWanted->{'size'}; |
|
| 309 | 309 | $ffmpegArgs .= " $frameOptions -f image2 -q:v 8"; |
| 310 | 310 | |
| 311 | 311 | // Final command |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | $this->activityLogKey); |
| 337 | 337 | |
| 338 | 338 | // Transform watermark for opacity |
| 339 | - $convertCmd = "convert $watermarkPath -alpha on -channel A -evaluate Multiply " . $watermarkOptions->{'opacity'} . " +channel $newWatermarkPath"; |
|
| 339 | + $convertCmd = "convert $watermarkPath -alpha on -channel A -evaluate Multiply ".$watermarkOptions->{'opacity'}." +channel $newWatermarkPath"; |
|
| 340 | 340 | |
| 341 | 341 | try { |
| 342 | 342 | $out = $this->executer->execute($convertCmd, 1, |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | // Format options for FFMpeg |
| 366 | 366 | $size = $watermarkOptions->{'size'}; |
| 367 | 367 | $positions = $this->get_watermark_position($watermarkOptions); |
| 368 | - $formattedOptions = "-vf \"movie=$newWatermarkPath, scale=$size [wm]; [in][wm] overlay=" . $positions['x'] . ':' . $positions['y'] . " [out]\""; |
|
| 368 | + $formattedOptions = "-vf \"movie=$newWatermarkPath, scale=$size [wm]; [in][wm] overlay=".$positions['x'].':'.$positions['y']." [out]\""; |
|
| 369 | 369 | |
| 370 | 370 | return ($formattedOptions); |
| 371 | 371 | } |
@@ -382,10 +382,10 @@ discard block |
||
| 382 | 382 | $positions['y'] = $watermarkOptions->{'y'}; |
| 383 | 383 | } |
| 384 | 384 | if ($watermarkOptions->{'x'} < 0) { |
| 385 | - $positions['x'] = 'main_w-overlay_w' . $watermarkOptions->{'x'}; |
|
| 385 | + $positions['x'] = 'main_w-overlay_w'.$watermarkOptions->{'x'}; |
|
| 386 | 386 | } |
| 387 | 387 | if ($watermarkOptions->{'y'} < 0) { |
| 388 | - $positions['y'] = 'main_h-overlay_h' . $watermarkOptions->{'y'}; |
|
| 388 | + $positions['y'] = 'main_h-overlay_h'.$watermarkOptions->{'y'}; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | return ($positions); |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - return (str_replace("x",":", $size)); |
|
| 463 | + return (str_replace("x", ":", $size)); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | // REad ffmpeg output and calculate % progress |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | // # finally, progress is easy |
| 498 | 498 | if ($done && $duration) { |
| 499 | - $progress = round(($done/$duration)*100); |
|
| 499 | + $progress = round(($done / $duration) * 100); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | $this->cpeLogger->log_out( |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | $preset = $output_wanted->{"preset"}; |
| 534 | - $presetPath = __DIR__ . '/../../../presets/'; |
|
| 534 | + $presetPath = __DIR__.'/../../../presets/'; |
|
| 535 | 535 | |
| 536 | 536 | if (!($presetContent = file_get_contents($presetPath.$preset.".json"))) { |
| 537 | 537 | throw new CpeSdk\CpeException("Can't open preset file !", |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | $preset = $output->{"preset"}; |
| 558 | - $presetPath = __DIR__ . '/../../../presets/'; |
|
| 558 | + $presetPath = __DIR__.'/../../../presets/'; |
|
| 559 | 559 | |
| 560 | 560 | if (!($files = scandir($presetPath))) { |
| 561 | 561 | throw new CpeSdk\CpeException("Unable to open preset directory '$presetPath' !", |
@@ -611,22 +611,22 @@ discard block |
||
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | $analyse = [ |
| 614 | - 'duration' => isset($metadata->format->duration) ? (float)$metadata->format->duration : 0, |
|
| 614 | + 'duration' => isset($metadata->format->duration) ? (float) $metadata->format->duration : 0, |
|
| 615 | 615 | 'video' => empty($videoStreams) ? null : [ |
| 616 | 616 | 'codec' => $videoStreams->codec_name, |
| 617 | 617 | 'color' => $videoStreams->color_space, |
| 618 | - 'resolution' => $videoStreams->width . 'x' . $videoStreams->height, |
|
| 618 | + 'resolution' => $videoStreams->width.'x'.$videoStreams->height, |
|
| 619 | 619 | 'sar' => $videoStreams->sample_aspect_ratio, |
| 620 | 620 | 'dar' => $videoStreams->display_aspect_ratio, |
| 621 | 621 | 'framerate' => $videoStreams->r_frame_rate, |
| 622 | - 'bitrate' => isset($videoStreams->bit_rate) ? (int)$videoStreams->bit_rate : null |
|
| 622 | + 'bitrate' => isset($videoStreams->bit_rate) ? (int) $videoStreams->bit_rate : null |
|
| 623 | 623 | ], |
| 624 | 624 | 'audio' => empty($audioStreams) ? null : [ |
| 625 | 625 | 'codec' => $audioStreams->codec_name, |
| 626 | 626 | 'frequency' => $audioStreams->sample_rate, |
| 627 | - 'channels' => (int)$audioStreams->channels, |
|
| 627 | + 'channels' => (int) $audioStreams->channels, |
|
| 628 | 628 | 'depth' => $audioStreams->bits_per_sample, |
| 629 | - 'bitrate' => (int)$audioStreams->bit_rate |
|
| 629 | + 'bitrate' => (int) $audioStreams->bit_rate |
|
| 630 | 630 | ] |
| 631 | 631 | ]; |
| 632 | 632 | |
@@ -67,8 +67,9 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | # If we have metadata, we expect the output of ffprobe |
| 69 | 69 | $metadata = null; |
| 70 | - if (isset($this->input->{'input_asset_metadata'})) |
|
| 71 | - $metadata = $this->input->{'input_asset_metadata'}; |
|
| 70 | + if (isset($this->input->{'input_asset_metadata'})) { |
|
| 71 | + $metadata = $this->input->{'input_asset_metadata'}; |
|
| 72 | + } |
|
| 72 | 73 | |
| 73 | 74 | // Perform transcoding |
| 74 | 75 | $result = $videoTranscoder->transcode_asset( |
@@ -90,8 +91,9 @@ discard block |
||
| 90 | 91 | |
| 91 | 92 | # If we have metadata, we expect the output of ffprobe |
| 92 | 93 | $metadata = null; |
| 93 | - if (isset($this->input->{'input_asset_metadata'})) |
|
| 94 | - $metadata = $this->input->{'input_asset_metadata'}; |
|
| 94 | + if (isset($this->input->{'input_asset_metadata'})) { |
|
| 95 | + $metadata = $this->input->{'input_asset_metadata'}; |
|
| 96 | + } |
|
| 95 | 97 | |
| 96 | 98 | // Perform transcoding |
| 97 | 99 | $result = $imageTranscoder->transcode_asset( |
@@ -194,16 +196,18 @@ discard block |
||
| 194 | 196 | |
| 195 | 197 | if (!file_exists($this->pathToOutputFiles)) |
| 196 | 198 | { |
| 197 | - if ($this->debug) |
|
| 198 | - $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
| 199 | + if ($this->debug) { |
|
| 200 | + $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
| 199 | 201 | "Creating TMP output folder '".$this->pathToOutputFiles."'", |
| 200 | 202 | $this->activityLogKey); |
| 203 | + } |
|
| 201 | 204 | |
| 202 | - if (!mkdir($this->pathToOutputFiles, 0750, true)) |
|
| 203 | - throw new CpeSdk\CpeException( |
|
| 205 | + if (!mkdir($this->pathToOutputFiles, 0750, true)) { |
|
| 206 | + throw new CpeSdk\CpeException( |
|
| 204 | 207 | "Unable to create temporary folder '$this->pathToOutputFiles' !", |
| 205 | 208 | self::TMP_FOLDER_FAIL |
| 206 | 209 | ); |
| 210 | + } |
|
| 207 | 211 | } |
| 208 | 212 | } |
| 209 | 213 | |
@@ -48,7 +48,9 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function is_dir_empty($dir) |
| 50 | 50 | { |
| 51 | - if (!is_readable($dir)) return null; |
|
| 51 | + if (!is_readable($dir)) { |
|
| 52 | + return null; |
|
| 53 | + } |
|
| 52 | 54 | $handle = opendir($dir); |
| 53 | 55 | while (false !== ($entry = readdir($handle))) { |
| 54 | 56 | if ($entry !== '.' && $entry !== '..') { |
@@ -83,8 +85,7 @@ discard block |
||
| 83 | 85 | false, false, |
| 84 | 86 | false, 1 |
| 85 | 87 | ); |
| 86 | - } |
|
| 87 | - catch (\Exception $e) { |
|
| 88 | + } catch (\Exception $e) { |
|
| 88 | 89 | $this->cpeLogger->log_out( |
| 89 | 90 | "ERROR", |
| 90 | 91 | basename(__FILE__), |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $this->cpeLogger->log_out( |
| 45 | 45 | "INFO", |
| 46 | 46 | basename(__FILE__), |
| 47 | - "Input Video metadata: " . print_r($metadata, true), |
|
| 47 | + "Input Video metadata: ".print_r($metadata, true), |
|
| 48 | 48 | $this->activityLogKey |
| 49 | 49 | ); |
| 50 | 50 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $this->cpeLogger->log_out( |
| 118 | 118 | "ERROR", |
| 119 | 119 | basename(__FILE__), |
| 120 | - "Execution of command '".$convertCmd."' failed: " . print_r($metadata, true). ". ".$e->getMessage(), |
|
| 120 | + "Execution of command '".$convertCmd."' failed: ".print_r($metadata, true).". ".$e->getMessage(), |
|
| 121 | 121 | $this->activityLogKey |
| 122 | 122 | ); |
| 123 | 123 | return false; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | // Append output filename to path |
| 163 | 163 | $pathToOutputFiles .= |
| 164 | - "/" . $outputWanted->{'output_file_info'}['basename']; |
|
| 164 | + "/".$outputWanted->{'output_file_info'}['basename']; |
|
| 165 | 165 | |
| 166 | 166 | $convertCmd = "convert $convertArgs $pathToOutputFiles"; |
| 167 | 167 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $pathToInputFile, $convertCmd); |
| 185 | 185 | |
| 186 | 186 | // Append output filename to path |
| 187 | - $pathToOutputFiles .= "/" . $outputWanted->{'output_file_info'}['basename']; |
|
| 187 | + $pathToOutputFiles .= "/".$outputWanted->{'output_file_info'}['basename']; |
|
| 188 | 188 | // Replace ${output_file} by output filename and path to local disk |
| 189 | 189 | $convertCmd = preg_replace('/\$\{output_file\}/', |
| 190 | 190 | $pathToOutputFiles, $convertCmd); |
@@ -40,13 +40,14 @@ discard block |
||
| 40 | 40 | $this->activityLogKey |
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | - if ($metadata) |
|
| 44 | - $this->cpeLogger->log_out( |
|
| 43 | + if ($metadata) { |
|
| 44 | + $this->cpeLogger->log_out( |
|
| 45 | 45 | "INFO", |
| 46 | 46 | basename(__FILE__), |
| 47 | 47 | "Input Video metadata: " . print_r($metadata, true), |
| 48 | 48 | $this->activityLogKey |
| 49 | 49 | ); |
| 50 | + } |
|
| 50 | 51 | |
| 51 | 52 | try { |
| 52 | 53 | $convertCmd = ""; |
@@ -67,8 +68,7 @@ discard block |
||
| 67 | 68 | $metadata, |
| 68 | 69 | $outputWanted |
| 69 | 70 | ); |
| 70 | - } |
|
| 71 | - else { |
|
| 71 | + } else { |
|
| 72 | 72 | $convertCmd = $this->craft_convert_cmd( |
| 73 | 73 | $tmpPathInput, |
| 74 | 74 | $pathToInputFile, |
@@ -112,8 +112,7 @@ discard block |
||
| 112 | 112 | // FFProbe the output file and return its information |
| 113 | 113 | $output_info = |
| 114 | 114 | $this->get_asset_info($pathToOutputFiles."/".$outputWanted->{'output_file_info'}['basename']); |
| 115 | - } |
|
| 116 | - catch (\Exception $e) { |
|
| 115 | + } catch (\Exception $e) { |
|
| 117 | 116 | $this->cpeLogger->log_out( |
| 118 | 117 | "ERROR", |
| 119 | 118 | basename(__FILE__), |
@@ -40,6 +40,12 @@ |
||
| 40 | 40 | // $metadata should contain the ffprobe video stream array. |
| 41 | 41 | |
| 42 | 42 | // Start FFmpeg for output transcoding |
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param string $tmpPathInput |
|
| 46 | + * @param null|string $pathToInputFile |
|
| 47 | + * @param string $pathToOutputFiles |
|
| 48 | + */ |
|
| 43 | 49 | public function transcode_asset( |
| 44 | 50 | $tmpPathInput, |
| 45 | 51 | $pathToInputFile, |