forked from GithubBackups/vichan
MP4 support, close ctrlcctrlv/8chan#243
This commit is contained in:
parent
4bf6c1ab8e
commit
0ba19e163b
@ -771,6 +771,7 @@
|
|||||||
$config['file_icons']['default'] = 'file.png';
|
$config['file_icons']['default'] = 'file.png';
|
||||||
$config['file_icons']['zip'] = 'zip.png';
|
$config['file_icons']['zip'] = 'zip.png';
|
||||||
$config['file_icons']['webm'] = 'video.png';
|
$config['file_icons']['webm'] = 'video.png';
|
||||||
|
$config['file_icons']['mp4'] = 'video.png';
|
||||||
// Example: Custom thumbnail for certain file extension.
|
// Example: Custom thumbnail for certain file extension.
|
||||||
// $config['file_icons']['extension'] = 'some_file.png';
|
// $config['file_icons']['extension'] = 'some_file.png';
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
$config['spoiler_images'] = true;
|
$config['spoiler_images'] = true;
|
||||||
$config['image_reject_repost'] = true;
|
$config['image_reject_repost'] = true;
|
||||||
$config['allowed_ext_files'][] = 'webm';
|
$config['allowed_ext_files'][] = 'webm';
|
||||||
|
$config['allowed_ext_files'][] = 'mp4';
|
||||||
$config['webm']['use_ffmpeg'] = true;
|
$config['webm']['use_ffmpeg'] = true;
|
||||||
$config['webm']['allow_audio'] = true;
|
$config['webm']['allow_audio'] = true;
|
||||||
$config['webm']['max_length'] = 60 * 15;
|
$config['webm']['max_length'] = 60 * 15;
|
||||||
|
@ -30,8 +30,17 @@ function is_valid_webm($ffprobe_out) {
|
|||||||
if (empty($ffprobe_out))
|
if (empty($ffprobe_out))
|
||||||
return array('code' => 1, 'msg' => $config['error']['genwebmerror']);
|
return array('code' => 1, 'msg' => $config['error']['genwebmerror']);
|
||||||
|
|
||||||
|
$extension = pathinfo($ffprobe_out['format']['filename'], PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
if ($extension === 'webm') {
|
||||||
if ($ffprobe_out['format']['format_name'] != 'matroska,webm')
|
if ($ffprobe_out['format']['format_name'] != 'matroska,webm')
|
||||||
return array('code' => 2, 'msg' => $config['error']['invalidwebm']);
|
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']))
|
if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio']))
|
||||||
return array('code' => 3, 'msg' => $config['error']['webmhasaudio']);
|
return array('code' => 3, 'msg' => $config['error']['webmhasaudio']);
|
||||||
@ -49,11 +58,11 @@ function make_webm_thumbnail($filename, $thumbnail, $width, $height) {
|
|||||||
$filename = escapeshellarg($filename);
|
$filename = escapeshellarg($filename);
|
||||||
$thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you
|
$thumbnail = escapeshellarg($thumbnail); // Should be safe by default but you
|
||||||
// can never be too safe.
|
// can never be too safe.
|
||||||
|
|
||||||
$ffmpeg = $config['webm']['ffmpeg_path'];
|
$ffmpeg = $config['webm']['ffmpeg_path'];
|
||||||
|
|
||||||
|
$ret = 0;
|
||||||
$ffmpeg_out = array();
|
$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 $ret;
|
||||||
|
|
||||||
return count($ffmpeg_out);
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
function postHandler($post) {
|
function postHandler($post) {
|
||||||
global $board, $config;
|
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']) {
|
if ($config['webm']['use_ffmpeg']) {
|
||||||
require_once dirname(__FILE__) . '/ffmpeg.php';
|
require_once dirname(__FILE__) . '/ffmpeg.php';
|
||||||
$webminfo = get_webm_info($file->file_path);
|
$webminfo = get_webm_info($file->file_path);
|
||||||
@ -21,7 +21,7 @@ function postHandler($post) {
|
|||||||
$file = set_thumbnail_dimensions($post, $file);
|
$file = set_thumbnail_dimensions($post, $file);
|
||||||
$tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg';
|
$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';
|
$file->thumb = $file->file_id . '.jpg';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -204,13 +204,13 @@ function setupVideo(thumb, url) {
|
|||||||
function setupVideosIn(element) {
|
function setupVideosIn(element) {
|
||||||
var thumbs = element.querySelectorAll("a.file");
|
var thumbs = element.querySelectorAll("a.file");
|
||||||
for (var i = 0; i < thumbs.length; i++) {
|
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);
|
setupVideo(thumbs[i], thumbs[i].href);
|
||||||
} else {
|
} else {
|
||||||
var m = thumbs[i].search.match(/\bv=([^&]*)/);
|
var m = thumbs[i].search.match(/\bv=([^&]*)/);
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
var url = decodeURIComponent(m[1]);
|
var url = decodeURIComponent(m[1]);
|
||||||
if (/\.webm$/.test(url)) setupVideo(thumbs[i], url);
|
if (/(\.webm)|(\.mp4)$/.test(url)) setupVideo(thumbs[i], url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
<a href="
|
<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 }}&t={{ post.filename|e('url') }}&loop=1
|
{{ config.root }}player.php?v={{ config.uri_img }}{{ post.file }}&t={{ post.filename|e('url') }}&loop=1
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ config.uri_img }}{{ post.file }}
|
{{ config.uri_img }}{{ post.file }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"
|
"
|
||||||
target="_blank"
|
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"
|
class="file"
|
||||||
{% endif %}
|
{% 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 }}"
|
<video autoplay class="post-image" src="{{ config.uri_thumb }}{{ post.thumb }}"
|
||||||
poster="
|
poster="
|
||||||
{{ config.root }}
|
{{ config.root }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user