Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow homarus to use faststart for video conversion #162

17 changes: 9 additions & 8 deletions Homarus/src/Controller/HomarusController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
namespace Islandora\Homarus\Controller;

use GuzzleHttp\Psr7\StreamWrapper;
use Islandora\Crayfish\Commons\CmdExecuteService;
use Islandora\Crayfish\Commons\ApixFedoraResourceRetriever;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;

/**
* Class HomarusController
Expand Down Expand Up @@ -117,9 +114,12 @@ public function convert(Request $request)
if ($format == "mp4") {
jordandukart marked this conversation as resolved.
Show resolved Hide resolved
$cmd_params = " -vcodec libx264 -preset medium -acodec aac " .
"-strict -2 -ab 128k -ac 2 -async 1 -movflags " .
"frag_keyframe+empty_moov ";
"faststart ";
}

$temp_file_path = __DIR__ . "/../../static/" . basename($source) . "." . $format;
$this->log->debug('Tempfile: ' . $temp_file_path);

// Arguments to ffmpeg command are sent as a custom header.
$args = $request->headers->get('X-Islandora-Args');

Expand All @@ -139,16 +139,17 @@ public function convert(Request $request)
$this->log->debug("X-Islandora-Args:", ['args' => $args]);
$token = $request->headers->get('Authorization');
$headers = "'Authorization: $token'";
$cmd_string = "$this->executable -headers $headers -i $source $args $cmd_params -f $format -";
$cmd_string = "$this->executable -headers $headers -i $source $args $cmd_params -f $format $temp_file_path";
$this->log->debug('Ffmpeg Command:', ['cmd' => $cmd_string]);

// Return response.
try {
return new StreamedResponse(
$this->cmd->execute($cmd_string, $source),
$this->cmd->execute($cmd_string, $source);
return (new BinaryFileResponse(
jordandukart marked this conversation as resolved.
Show resolved Hide resolved
$temp_file_path,
200,
['Content-Type' => $content_type]
);
))->deleteFileAfterSend(true);
jordandukart marked this conversation as resolved.
Show resolved Hide resolved
} catch (\RuntimeException $e) {
$this->log->error("RuntimeException:", ['exception' => $e]);
return new Response($e->getMessage(), 500);
Expand Down