added basic thumbnail support

This commit is contained in:
overflowerror 2021-01-06 18:34:58 +01:00
parent 106126452a
commit 54e6adb420
5 changed files with 43 additions and 6 deletions

6
scripts/thumbnail.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
dir="content/$1/"
mkdir -p "$dir"
ffmpeg -i "landingzone/$1.vid" -vf "thumbnail,scale=640:360" -frames:v 1 "$dir/thumb.png"

View file

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
dir="content/$1/" dir="content/$1/"
mkdir "$dir" mkdir -p "$dir"
mkdir "$dir/360p/" mkdir "$dir/360p/"
mkdir "$dir/480p/" mkdir "$dir/480p/"
mkdir "$dir/720p/" mkdir "$dir/720p/"

View file

@ -42,16 +42,28 @@ class TranscodeCommand extends Command
private function handleVideo(Video $video, OutputInterface $output) private function handleVideo(Video $video, OutputInterface $output)
{ {
$this->videoService->setVideoState($video, Video::PROCESSING_TRANSCODE); $output->writeln("starting creation of thumbnail...");
$this->videoService->setVideoState($video, Video::PROCESSING_THUMBNAIL);
if ($this->callScript("thumbnail.sh", [$video->getId()->toString()])) {
$output->writeln("thumbnail creation successful");
} else {
$output->writeln("thumbnail creation failed");
$this->videoService->setVideoState($video, Video::FAIL);
return;
}
$output->writeln("starting transcoding..."); $output->writeln("starting transcoding...");
$this->videoService->setVideoState($video, Video::PROCESSING_TRANSCODE);
if ($this->callScript("transcode.sh", [$video->getId()->toString()])) { if ($this->callScript("transcode.sh", [$video->getId()->toString()])) {
$output->writeln("transcoding successful"); $output->writeln("transcoding successful");
$this->videoService->setVideoState($video, Video::DONE);
} else { } else {
$output->writeln("transcoding failed"); $output->writeln("transcoding failed");
$this->videoService->setVideoState($video, Video::FAIL); $this->videoService->setVideoState($video, Video::FAIL);
return;
} }
$this->videoService->setVideoState($video, Video::DONE);
} }
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int

View file

@ -26,6 +26,7 @@ class WatchController extends AbstractController
private const PLAYLIST_MIME_TYPE = "application/x-mpegURL"; private const PLAYLIST_MIME_TYPE = "application/x-mpegURL";
private const TS_FILE_MIME_TYPE = "video/MP2T"; private const TS_FILE_MIME_TYPE = "video/MP2T";
private const THUMBNAIL_MIME_TYPE = "image/png";
private const TS_FILE_FORMAT = "seg-%06d-ts"; private const TS_FILE_FORMAT = "seg-%06d-ts";
@ -122,7 +123,7 @@ class WatchController extends AbstractController
/** /**
* @Route("/{linkId}/{videoId}/{quality}/seg-{tsFileId}-ts", name="app_watch_segment", requirements={"quality"="360|480|720|1080", "tsFileId"="\d+"}) * @Route("/{linkId}/{videoId}/{quality}/seg-{tsFileId}-ts", name="app_watch_segment", requirements={"quality"="360|480|720|1080", "tsFileId"="\d+"})
*/ */
public function tsFiles($videoId, $linkId, int $quality, int $tsFileId): Response public function tsFile($videoId, $linkId, int $quality, int $tsFileId): Response
{ {
$data = $this->checkRequestData($videoId, $linkId); $data = $this->checkRequestData($videoId, $linkId);
@ -134,6 +135,21 @@ class WatchController extends AbstractController
return $response; return $response;
} }
/**
* @Route("/{linkId}/{videoId}/thumb", name="app_watch_thumbnail")
*/
public function thumbnail($videoId, $linkId): Response
{
$data = $this->checkRequestData($videoId, $linkId);
$file = self::CONTENT_DIRECTORY . $data["video"]->getId() . "/" . "thumb.png";
$response = new BinaryFileResponse($file);
$response->headers->set("Content-Type", self::THUMBNAIL_MIME_TYPE);
return $response;
}
/** /**
* @Route("/{linkId}/{videoId}/", name="app_watch_page") * @Route("/{linkId}/{videoId}/", name="app_watch_page")
*/ */
@ -142,7 +158,10 @@ class WatchController extends AbstractController
$data = $this->checkRequestData($videoId, $linkId); $data = $this->checkRequestData($videoId, $linkId);
return $this->render("watch/watch.html.twig", [ return $this->render("watch/watch.html.twig", [
"thumbnail" => "thumbnail.jpg", "thumbnail" => $this->generateUrl("app_watch_thumbnail", [
"linkId" => $linkId,
"videoId" => $videoId
]),
"global" => $this->generateUrl("app_watch_global", [ "global" => $this->generateUrl("app_watch_global", [
"linkId" => $linkId, "linkId" => $linkId,
"videoId" => $videoId "videoId" => $videoId

View file

@ -5,7 +5,7 @@
{% block stylesheets %} {% block stylesheets %}
<link rel="stylesheet" href="{{ asset("css/video-js.css") }}"> <link rel="stylesheet" href="{{ asset("css/video-js.css") }}">
<link href="{{ assert("css/video-js-fantasy.css") }}" rel="stylesheet"> <link href="{{ asset("css/video-js-fantasy.css") }}" rel="stylesheet">
<link rel="stylesheet" href="{{ asset("css/watch.css") }}" <link rel="stylesheet" href="{{ asset("css/watch.css") }}"
{% endblock %} {% endblock %}