FIX: no se podia subir los videos

This commit is contained in:
2020-06-18 02:16:32 -04:00
parent 0f26b53546
commit ef453fef56
9 changed files with 317 additions and 79 deletions

View File

@ -123,4 +123,38 @@ class Eventos {
->withHeader('Content-Type', 'application/json')
->withStatus(201);
}
public function addVideo(Request $request, Response $response, Container $container, DataHandler $handler, MediaLoader $loader, $evento): Response {
$post = $request->getParsedBody();
$files = $request->getUploadedFiles();
if (count($files) == 0) {
$output = [
'informacion' => '',
'evento' => $evento,
'estado' => false
];
$response->getBody()->write(json_encode($output));
return $response->withHeader('Location', implode('/', [
$container->get('urls')['admin'],
'evento',
$evento
]));
}
$file = $files['video'];
$eventos = $handler->load('eventos');
$e = $eventos[$evento];
if (is_array($file)) {
$status = false;
foreach ($file as $f) {
$status |= $loader->add($e, $f);
}
} else {
$status = $loader->add($e, $file);
}
$response->getBody()->write(json_encode($output));
return $response->withHeader('Location', implode('/', [
$container->get('urls')['admin'],
'evento',
$evento
]));
}
}

View File

@ -11,10 +11,6 @@ class MediaLoader {
$this->folder = $media_folder;
$this->media_url = $media_assets_url;
}
protected $ffmpeg;
public function setFFMpeg(FFMpeg $ffmpeg) {
$this->ffmpeg = $ffmpeg;
}
protected function getFolder($event) {
return implode(DIRECTORY_SEPARATOR, [
$this->folder,
@ -40,7 +36,7 @@ class MediaLoader {
case 'avi':
case 'ogg':
case 'webm':
return implode(PHP_EOL, [
return implode('', [
'<video class="media" controls="controls">',
implode('', [
'<source src="',
@ -104,6 +100,9 @@ class MediaLoader {
$medias[$name]->{$type} = $obj;
}
array_walk($medias, function(&$item) {
if ($item->media === null) {
$item->media = $item->original;
}
if ($item->thumb === null) {
$item->thumb = $item->media;
}
@ -259,10 +258,6 @@ class MediaLoader {
]);
$file->moveTo($filename);
if ($this->ffmpeg === null) {
return file_exists($filename);
}
$thumb = implode(DIRECTORY_SEPARATOR, [
$folder,
implode('.', [
@ -274,23 +269,32 @@ class MediaLoader {
])
]);
$video = $this->ffmpeg->open($filename);
$video
->filters()
->resize(new FFMpeg\Coordinate\Dimension(320, 240))
->synchronize();
$video
->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(1))
->save($thumb);
$media = implode(DIRECTORY_SEPARATOR, [
$folder,
implode('.', [
$base_name,
$extension
])
$image = imagecreatetruecolor(300, 300);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $black);
$pfile = implode(DIRECTORY_SEPARATOR, [
dirname($this->folder, 3),
'resources',
'data',
'play.png'
]);
$video
->save(new FFMpeg\Format\Video\X264(), $media);
$play = imagecreatefrompng($pfile);
list($w, $h) = getimagesize($pfile);
$r = $w / $h;
$w = 100;
$h = $r * $w;
$play = imagescale($play, $w, $h);
$x = (300 - $w) / 2;
$y = (300 - $h) / 2;
$x2 = (300 + $w) / 2 - $x;
$y2 = (300 + $h) / 2 - $y;
imagecopyresampled($image, $play, $x, $y, 0, 0, $x2, $y2, $w, $h);
imagejpeg($image, $thumb, 50);
return file_exists($filename);
}
public function delete($event, $filename) {