summaryrefslogtreecommitdiff
path: root/inc/lib/webm/ffmpeg.php
diff options
context:
space:
mode:
authorIan Bradley <marlen.crabapple@gmail.com>2014-09-15 16:34:36 -0700
committerIan Bradley <marlen.crabapple@gmail.com>2014-09-15 16:34:36 -0700
commit0a9de3deb544e2e5f29e9db539298a8681087847 (patch)
treea8a5fb041898041e2fc5c1e9c64b127b317495fa /inc/lib/webm/ffmpeg.php
parentc1ecef377229da3b6af65834109c8fc76508479c (diff)
FFmpeg support for WebMs. Fixes threads with large amounts of WebM's causing crashes for some users.
Diffstat (limited to 'inc/lib/webm/ffmpeg.php')
-rw-r--r--inc/lib/webm/ffmpeg.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php
new file mode 100644
index 00000000..7b635b5c
--- /dev/null
+++ b/inc/lib/webm/ffmpeg.php
@@ -0,0 +1,58 @@
+<?php
+/*
+* ffmpeg.php
+* A barebones ffmpeg based webm implementation for vichan.
+*/
+
+function get_webm_info($filename) {
+ global $board, $config;
+
+ $filename = escapeshellarg($filename);
+ $ffprobe = $config['webm']['ffprobe_path'];
+ $ffprobe_out = array();
+ $webminfo = array();
+
+ exec("$ffprobe -v quiet -print_format json -show_format -show_streams $filename", $ffprobe_out);
+ $ffprobe_out = json_decode(implode("\n", $ffprobe_out), 1);
+ $webminfo['error'] = is_valid_webm($ffprobe_out);
+
+ if(empty($webminfo['error'])) {
+ $webminfo['width'] = $ffprobe_out['streams'][0]['width'];
+ $webminfo['height'] = $ffprobe_out['streams'][0]['height'];
+ }
+
+ return $webminfo;
+}
+
+function is_valid_webm($ffprobe_out) {
+ global $board, $config;
+
+ if (empty($ffprobe_out))
+ return array('code' => 1, 'msg' => $config['error']['genwebmerror']);
+
+ if ($ffprobe_out['format']['format_name'] != 'matroska,webm')
+ return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
+
+ if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio']))
+ return array('code' => 3, 'msg' => $config['error']['webmhasaudio']);
+
+ if ($ffprobe_out['streams'][0]['codec_name'] != 'vp8')
+ return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
+
+ if (empty($ffprobe_out['streams'][0]['width']) || (empty($ffprobe_out['streams'][0]['height'])))
+ return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
+
+ if ($ffprobe_out['format']['duration'] > $config['webm']['max_length'])
+ return array('code' => 4, 'msg' => $config['error']['webmtoolong']);
+}
+
+function make_webm_thumbnail($filename, $thumbnail, $width, $height) {
+ global $board, $config;
+
+ $ffmpeg = $config['webm']['ffmpeg_path'];
+ $ffmpeg_out = array();
+
+ exec("$ffmpeg -i $filename -v quiet -ss 00:00:00 -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnail 2>&1");
+
+ return count($ffmpeg_out);
+}