This commit is contained in:
8chan 2014-11-19 00:53:35 -08:00
parent 4bf6c1ab8e
commit 0ba19e163b
6 changed files with 24 additions and 13 deletions

View File

@ -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';

View File

@ -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;

View File

@ -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;
}

View File

@ -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 {

View File

@ -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);
}
}
}

View File

@ -1,16 +1,16 @@
<a href="
{% if post.file|extension == 'webm' %}
{% if post.file|extension == 'webm' or post.file|extension == 'mp4' %}
{{ config.root }}player.php?v={{ config.uri_img }}{{ post.file }}&amp;t={{ post.filename|e('url') }}&amp;loop=1
{% else %}
{{ config.uri_img }}{{ post.file }}
{% endif %}
"
target="_blank"
{% if post.thumb == 'file' or post.modifiers['is_file'] == '1' or post.filename|extension == 'webm' %}
{% if post.thumb == 'file' or post.modifiers['is_file'] == '1' or post.filename|extension == 'webm' or post.file|extension == 'mp4' %}
class="file"
{% endif %}
>
{% if post.thumb|extension == 'webm' %}
{% if post.thumb|extension == 'webm' or post.thumb|extension == 'mp4' %}
<video autoplay class="post-image" src="{{ config.uri_thumb }}{{ post.thumb }}"
poster="
{{ config.root }}