From 0a9de3deb544e2e5f29e9db539298a8681087847 Mon Sep 17 00:00:00 2001 From: Ian Bradley Date: Mon, 15 Sep 2014 16:34:36 -0700 Subject: FFmpeg support for WebMs. Fixes threads with large amounts of WebM's causing crashes for some users. --- inc/lib/webm/ffmpeg.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 inc/lib/webm/ffmpeg.php (limited to 'inc/lib/webm/ffmpeg.php') 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 @@ + 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); +} -- cgit v1.3 From 306f4ef46bcbede59b427268fe6d8b5e18c811b2 Mon Sep 17 00:00:00 2001 From: Ian Bradley Date: Mon, 15 Sep 2014 16:57:06 -0700 Subject: Added escapeshellarg() for WebM thumbnail generation. --- inc/lib/webm/ffmpeg.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'inc/lib/webm/ffmpeg.php') diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php index 7b635b5c..edd2c73a 100644 --- a/inc/lib/webm/ffmpeg.php +++ b/inc/lib/webm/ffmpeg.php @@ -49,6 +49,10 @@ function is_valid_webm($ffprobe_out) { function make_webm_thumbnail($filename, $thumbnail, $width, $height) { global $board, $config; + $filename = escapeshellarg($filename); + $thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you + // can never be too safe. + $ffmpeg = $config['webm']['ffmpeg_path']; $ffmpeg_out = array(); -- cgit v1.3