diff --git a/inc/config.php b/inc/config.php index 3adabcc9..de4fcfa7 100644 --- a/inc/config.php +++ b/inc/config.php @@ -771,6 +771,7 @@ $config['file_icons']['default'] = 'file.png'; $config['file_icons']['zip'] = 'zip.png'; $config['file_icons']['webm'] = 'video.png'; + $config['file_icons']['mp4'] = 'video.png'; // Example: Custom thumbnail for certain file extension. // $config['file_icons']['extension'] = 'some_file.png'; diff --git a/inc/instance-config.php b/inc/instance-config.php index da57903c..9c442fef 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -61,6 +61,7 @@ $config['spoiler_images'] = true; $config['image_reject_repost'] = true; $config['allowed_ext_files'][] = 'webm'; + $config['allowed_ext_files'][] = 'mp4'; $config['webm']['use_ffmpeg'] = true; $config['webm']['allow_audio'] = true; $config['webm']['max_length'] = 60 * 15; diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php index 935b5932..8e4076d1 100644 --- a/inc/lib/webm/ffmpeg.php +++ b/inc/lib/webm/ffmpeg.php @@ -30,8 +30,17 @@ function is_valid_webm($ffprobe_out) { 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']); + $extension = pathinfo($ffprobe_out['format']['filename'], PATHINFO_EXTENSION); + + if ($extension === 'webm') { + if ($ffprobe_out['format']['format_name'] != 'matroska,webm') + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + } elseif ($extension === 'mp4') { + if ($ffprobe_out['streams'][0]['codec_name'] != 'h264' && $ffprobe_out['streams'][1]['codec_name'] != 'aac') + return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + } else { + return array('code' => 1, 'msg' => $config['error']['genwebmerror']); + } if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio'])) return array('code' => 3, 'msg' => $config['error']['webmhasaudio']); @@ -49,11 +58,11 @@ function make_webm_thumbnail($filename, $thumbnail, $width, $height) { $filename = escapeshellarg($filename); $thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you // can never be too safe. - $ffmpeg = $config['webm']['ffmpeg_path']; + + $ret = 0; $ffmpeg_out = array(); + exec("$ffmpeg -strict -2 -i $filename -v quiet -ss 00:00:00 -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnail 2>&1", $ffmpeg_out, $ret); - exec("$ffmpeg -strict -2 -i $filename -v quiet -ss 00:00:00 -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnail 2>&1"); - - return count($ffmpeg_out); + return $ret; } diff --git a/inc/lib/webm/posthandler.php b/inc/lib/webm/posthandler.php index a5b7429b..18b4186f 100644 --- a/inc/lib/webm/posthandler.php +++ b/inc/lib/webm/posthandler.php @@ -5,7 +5,7 @@ function postHandler($post) { global $board, $config; - if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm') { + if ($post->has_file) foreach ($post->files as &$file) if ($file->extension == 'webm' || $file->extension == 'mp4') { if ($config['webm']['use_ffmpeg']) { require_once dirname(__FILE__) . '/ffmpeg.php'; $webminfo = get_webm_info($file->file_path); @@ -21,7 +21,7 @@ function postHandler($post) { $file = set_thumbnail_dimensions($post, $file); $tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg'; - if(false == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight)) { + if(0 == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight)) { $file->thumb = $file->file_id . '.jpg'; } else { diff --git a/js/expand-video.js b/js/expand-video.js index 79872510..6d04b858 100644 --- a/js/expand-video.js +++ b/js/expand-video.js @@ -204,13 +204,13 @@ function setupVideo(thumb, url) { function setupVideosIn(element) { var thumbs = element.querySelectorAll("a.file"); for (var i = 0; i < thumbs.length; i++) { - if (/\.webm$/.test(thumbs[i].pathname)) { + if (/(\.webm)|(\.mp4)$/.test(thumbs[i].pathname)) { setupVideo(thumbs[i], thumbs[i].href); } else { var m = thumbs[i].search.match(/\bv=([^&]*)/); if (m != null) { var url = decodeURIComponent(m[1]); - if (/\.webm$/.test(url)) setupVideo(thumbs[i], url); + if (/(\.webm)|(\.mp4)$/.test(url)) setupVideo(thumbs[i], url); } } } diff --git a/templates/post/image.html b/templates/post/image.html index 9b5449ad..3dd6b260 100644 --- a/templates/post/image.html +++ b/templates/post/image.html @@ -1,16 +1,16 @@ - {% if post.thumb|extension == 'webm' %} + {% if post.thumb|extension == 'webm' or post.thumb|extension == 'mp4' %}