@@ -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 | } |
@@ -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, |
@@ -109,7 +109,7 @@ |
||
109 | 109 | else if (isset($this->input->{'input_asset'}->{'http'})) |
110 | 110 | { |
111 | 111 | // Pad HTTP input so it is cached in case of full encodes |
112 | - $this->pathToInputFile = 'cache:' . $this->input->{'input_asset'}->{'http'}; |
|
112 | + $this->pathToInputFile = 'cache:'.$this->input->{'input_asset'}->{'http'}; |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 |
@@ -74,22 +74,25 @@ discard block |
||
74 | 74 | |
75 | 75 | $inputFileInfo = null; |
76 | 76 | // Create TMP storage to store input file to transcode |
77 | - if (isset($this->input->{'input_asset'}->{'file'})) |
|
78 | - $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); |
|
77 | + if (isset($this->input->{'input_asset'}->{'file'})) { |
|
78 | + $inputFileInfo = pathinfo($this->input->{'input_asset'}->{'file'}); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | // Create the tmp folder if doesn't exist |
81 | 82 | if (!file_exists($this->tmpPathInput)) |
82 | 83 | { |
83 | - if ($this->debug) |
|
84 | - $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
84 | + if ($this->debug) { |
|
85 | + $this->cpeLogger->log_out("INFO", basename(__FILE__), |
|
85 | 86 | "Creating TMP input folder '".$this->tmpPathInput."'", |
86 | 87 | $this->activityLogKey); |
88 | + } |
|
87 | 89 | |
88 | - if (!mkdir($this->tmpPathInput, 0750, true)) |
|
89 | - throw new CpeSdk\CpeException( |
|
90 | + if (!mkdir($this->tmpPathInput, 0750, true)) { |
|
91 | + throw new CpeSdk\CpeException( |
|
90 | 92 | "Unable to create temporary folder '$this->tmpPathInput' !", |
91 | 93 | self::TMP_FOLDER_FAIL |
92 | 94 | ); |
95 | + } |
|
93 | 96 | } |
94 | 97 | |
95 | 98 | $this->pathToInputFile = null; |
@@ -105,8 +108,7 @@ discard block |
||
105 | 108 | $this->input->{'input_asset'}->{'file'}, |
106 | 109 | $saveFileTo |
107 | 110 | ); |
108 | - } |
|
109 | - else if (isset($this->input->{'input_asset'}->{'http'})) |
|
111 | + } else if (isset($this->input->{'input_asset'}->{'http'})) |
|
110 | 112 | { |
111 | 113 | // Pad HTTP input so it is cached in case of full encodes |
112 | 114 | $this->pathToInputFile = 'cache:' . $this->input->{'input_asset'}->{'http'}; |