diff options
| author | Marcin Łabanowski <marcin@6irc.net> | 2014-09-17 20:50:21 +0200 |
|---|---|---|
| committer | Marcin Łabanowski <marcin@6irc.net> | 2014-09-17 20:50:21 +0200 |
| commit | 4da5f4ec90b80efd0ebb4a163e6f3648d0709bc9 (patch) | |
| tree | f3244ae5ae92c90c86f650c84718b4f593c915e9 /inc/lib/webm/ffmpeg.php | |
| parent | c369377c84d370efe0da66e348cb337b33158e92 (diff) | |
| parent | 306f4ef46bcbede59b427268fe6d8b5e18c811b2 (diff) | |
Merge pull request #79 from marlencrabapple/master
FFmpeg support for WebM uploads
Diffstat (limited to 'inc/lib/webm/ffmpeg.php')
| -rw-r--r-- | inc/lib/webm/ffmpeg.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php new file mode 100644 index 00000000..edd2c73a --- /dev/null +++ b/inc/lib/webm/ffmpeg.php @@ -0,0 +1,62 @@ +<?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; + + $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(); + + 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); +} |
