if (! function_exists('postHandlerVideoThumb')) { function postHandlerVideoThumb($post) { # exclude mp4 and webm; 設定値. ffmpegが解釈出来る動画拡張子を列挙. $ffmpeg_extensions = ['flv', 'wmv', 'asf', 'mpeg', 'mpg', 'avi', 'ts', 'm2ts', 'mov', 'mkv']; global $board, $config; if (! $post->has_file) { return; }; if (! $config['webm']['use_ffmpeg']) { return; }; foreach ($post->files as &$file) { if (! in_array($file->extension, $ffmpeg_extensions)) { continue; }; if ($file->thumb == 'spoiler') { continue; } elseif ($file->thumb == 'file' || $file->thumb == '') { # do nothing; } else { continue; }; # ref: vichan/inc/lib/webm/ffmpeg.php: get_webm_info, require_once dirname(__FILE__) . '/lib/webm/ffmpeg.php'; $video_info = get_video_info($file->file_path); if (! empty($video_info['error'])) { return 'postHandlerVideoThumb:' . $video_info['error']['msg']; }; if ($config['spoiler_images'] && isset($_POST['spoiler'])) { $file = webm_set_spoiler($file); } else { $file->width = $video_info['width']; $file->height = $video_info['height']; $file = set_thumbnail_dimensions($post, $file); $tn_path = $board['dir'] . $config['dir']['thumb'] . $file->file_id . '.jpg'; if(0 == make_webm_thumbnail($file->file_path, $tn_path, $file->thumbwidth, $file->thumbheight, $video_info['duration'])) { $file->thumb = $file->file_id . '.jpg'; } else { # do nothing }; }; }; }; function get_video_info($filename) { global $board, $config; $filename = escapeshellarg($filename); $ffprobe = $config['webm']['ffprobe_path']; $ffprobe_out = array(); $info = array(); exec("$ffprobe -v quiet -print_format json -show_format -show_streams $filename", $ffprobe_out); $ffprobe_out = json_decode(implode("\n", $ffprobe_out), 1); $info['duration'] = $ffprobe_out['format']['duration']; foreach ($ffprobe_out['streams'] as $stream) { if ($stream['width'] != '' && $stream['height'] != '') { $info['width'] = $stream['width']; $info['height'] = $stream['height']; break; }; }; return $info; }; }; # mp4 と webm 以外の動画にもサムネイルを付ける(インラインプレイヤーとは別設定) # この行で設定が有効になる。 event_handler('post', function($post) { return postHandlerVideoThumb($post); });