@@ -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 | |