summaryrefslogtreecommitdiff
path: root/inc/lib/webm/posthandler.php
diff options
context:
space:
mode:
authorMarcin Łabanowski <marcin@6irc.net>2014-09-17 20:50:21 +0200
committerMarcin Łabanowski <marcin@6irc.net>2014-09-17 20:50:21 +0200
commit4da5f4ec90b80efd0ebb4a163e6f3648d0709bc9 (patch)
treef3244ae5ae92c90c86f650c84718b4f593c915e9 /inc/lib/webm/posthandler.php
parentc369377c84d370efe0da66e348cb337b33158e92 (diff)
parent306f4ef46bcbede59b427268fe6d8b5e18c811b2 (diff)
Merge pull request #79 from marlencrabapple/master
FFmpeg support for WebM uploads
Diffstat (limited to 'inc/lib/webm/posthandler.php')
-rw-r--r--inc/lib/webm/posthandler.php72
1 files changed, 60 insertions, 12 deletions
diff --git a/inc/lib/webm/posthandler.php b/inc/lib/webm/posthandler.php
index 1f831f5a..308c7507 100644
--- a/inc/lib/webm/posthandler.php
+++ b/inc/lib/webm/posthandler.php
@@ -6,6 +6,34 @@ function postHandler($post) {
global $board, $config;
if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') {
+ if ($config['webm']['use_ffmpeg']) {
+ require_once dirname(__FILE__) . '/ffmpeg.php';
+ $webminfo = get_webm_info($file->file_path);
+
+ if (empty($webminfo['error'])) {
+ $file->width = $webminfo['width'];
+ $file->height = $webminfo['height'];
+
+ if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
+ $file = webm_set_spoiler($file);
+ }
+ else {
+ $file = set_thumbnail_dimensions($post, $file);
+ $tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg';
+
+ if(empty(make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight))) {
+ $file->thumb = $file->file_id . '.jpg';
+ }
+ else {
+ $file->thumb = 'file';
+ }
+ }
+ }
+ else {
+ return $webminfo['error']['msg'];
+ }
+ }
+ else {
require_once dirname(__FILE__) . '/videodata.php';
$videoDetails = videoData($file->file_path);
if (!isset($videoDetails['container']) || $videoDetails['container'] != 'webm') return "not a WebM file";
@@ -14,10 +42,7 @@ function postHandler($post) {
$thumbName = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.webm';
if ($config['spoiler_images'] && isset($_POST['spoiler'])) {
// Use spoiler thumbnail
- $file->thumb = 'spoiler';
- $size = @getimagesize($config['spoiler_image']);
- $file->thumbwidth = $size[0];
- $file->thumbheight = $size[1];
+ $file = webm_set_spoiler($file);
} elseif (isset($videoDetails['frame']) && $thumbFile = fopen($thumbName, 'wb')) {
// Use single frame from video as pseudo-thumbnail
fwrite($thumbFile, $videoDetails['frame']);
@@ -33,17 +58,40 @@ function postHandler($post) {
if (isset($videoDetails['width']) && isset($videoDetails['height'])) {
$file->width = $videoDetails['width'];
$file->height = $videoDetails['height'];
+
if ($file->thumb != 'file' && $file->thumb != 'spoiler') {
- $thumbMaxWidth = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
- $thumbMaxHeight = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
- if ($videoDetails['width'] > $thumbMaxWidth || $videoDetails['height'] > $thumbMaxHeight) {
- $file->thumbwidth = min($thumbMaxWidth, intval(round($videoDetails['width'] * $thumbMaxHeight / $videoDetails['height'])));
- $file->thumbheight = min($thumbMaxHeight, intval(round($videoDetails['height'] * $thumbMaxWidth / $videoDetails['width'])));
- } else {
- $file->thumbwidth = $videoDetails['width'];
- $file->thumbheight = $videoDetails['height'];
+ $file = set_thumbnail_dimensions($post, $file);
}
}
}
}
}
+
+function set_thumbnail_dimensions($post,$file) {
+ global $board, $config;
+
+ $tn_dimensions = array();
+ $tn_maxw = $post->op ? $config['thumb_op_width'] : $config['thumb_width'];
+ $tn_maxh = $post->op ? $config['thumb_op_height'] : $config['thumb_height'];
+
+ if ($file->width > $tn_maxw || $file->height > $tn_maxh) {
+ $file->thumbwidth = min($tn_maxw, intval(round($file->width * $tn_maxh / $file->height)));
+ $file->thumbheight = min($tn_maxh, intval(round($file->height * $tn_maxw / $file->width)));
+ } else {
+ $file->thumbwidth = $file->width;
+ $file->thumbheight = $file->height;
+ }
+
+ return $file;
+}
+
+function webm_set_spoiler($file) {
+ global $board, $config;
+
+ $file->thumb = 'spoiler';
+ $size = @getimagesize($config['spoiler_image']);
+ $file->thumbwidth = $size[0];
+ $file->thumbheight = $size[1];
+
+ return $file;
+}