Added HTML5 video support (closed #75)

This commit is contained in:
Marcin Kurczewski 2014-04-08 16:54:36 +02:00
parent 78d0b07c5c
commit af1828a9e8
3 changed files with 45 additions and 12 deletions

View file

@ -260,33 +260,47 @@ class PostEntity extends AbstractEntity
case 'image/gif': case 'image/gif':
$srcImage = imagecreatefromgif($srcPath); $srcImage = imagecreatefromgif($srcPath);
break; break;
case 'application/x-shockwave-flash': case 'application/x-shockwave-flash':
$srcImage = null; $srcImage = null;
exec('which dump-gnash', $tmp, $exitCode);
if ($exitCode == 0)
{
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png'; $tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
exec('dump-gnash --screenshot last --screenshot-file ' . $tmpPath . ' -1 -r1 --max-advances 15 ' . $srcPath); exec('dump-gnash --screenshot last --screenshot-file "' . $tmpPath . '" -1 -r1 --max-advances 15 "' . $srcPath . '"');
if (file_exists($tmpPath)) if (file_exists($tmpPath))
$srcImage = imagecreatefrompng($tmpPath); $srcImage = imagecreatefrompng($tmpPath);
}
if (!$srcImage) if (!$srcImage)
{
exec('which swfrender', $tmp, $exitCode);
if ($exitCode == 0)
{ {
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png'; $tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
exec('swfrender ' . $srcPath . ' -o ' . $tmpPath); exec('swfrender ' . $srcPath . ' -o ' . $tmpPath);
if (file_exists($tmpPath)) if (file_exists($tmpPath))
$srcImage = imagecreatefrompng($tmpPath); $srcImage = imagecreatefrompng($tmpPath);
} }
break;
case 'video/mp4':
case 'video/webm':
case 'video/ogg':
case 'application/ogg':
case 'video/x-flv':
case 'video/3gpp':
$srcImage = null;
$tmpPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
exec('ffmpegthumbnailer -i"' . $srcPath . '" -o"' . $tmpPath . '" -s0 -t"12%"');
if (file_exists($tmpPath))
$srcImage = imagecreatefrompng($tmpPath);
if (!$srcImage)
{
exec('ffmpeg -i "' . $srcPath . '" -vframes 1 "' . $tmpPath . '"');
if (file_exists($tmpPath))
$srcImage = imagecreatefrompng($tmpPath);
} }
break; break;
default: default:
break; break;
} }
if (isset($tmpPath)) if (isset($tmpPath) and file_exists($tmpPath))
unlink($tmpPath); unlink($tmpPath);
if (!isset($srcImage)) if (!isset($srcImage))
@ -339,6 +353,17 @@ class PostEntity extends AbstractEntity
$this->imageWidth = $imageWidth; $this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight; $this->imageHeight = $imageHeight;
break; break;
case 'video/webm':
case 'video/mp4':
case 'video/ogg':
case 'application/ogg':
case 'video/x-flv':
case 'video/3gpp':
list ($imageWidth, $imageHeight) = getimagesize($srcPath);
$this->type = PostType::Video;
$this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight;
break;
default: default:
throw new SimpleException('Invalid file type "' . $this->mimeType . '"'); throw new SimpleException('Invalid file type "' . $this->mimeType . '"');
} }

View file

@ -4,4 +4,5 @@ class PostType extends Enum
const Image = 1; const Image = 1;
const Flash = 2; const Flash = 2;
const Youtube = 3; const Youtube = 3;
const Video = 4;
} }

View file

@ -24,4 +24,11 @@
<iframe style="width: 800px; height: 600px; border: 0;" src="//www.youtube.com/embed/<?php echo $post->fileHash ?>?wmode=opaque" allowfullscreen></iframe> <iframe style="width: 800px; height: 600px; border: 0;" src="//www.youtube.com/embed/<?php echo $post->fileHash ?>?wmode=opaque" allowfullscreen></iframe>
<?php elseif ($post->type == PostType::Video): ?>
<video style="width: <?= $post->imageWidth ?>px; height: <?= $post->imageHeight ?>px" controls>
<source type="<?= $post->mimeType ?>" src="<?= \Chibi\UrlHelper::route('post', 'retrieve', ['name' => $post->name]) ?>">
Your browser doesn't support HTML5 &lt;video&gt; tag.
</video>
<?php endif ?> <?php endif ?>