diff options
| author | Appleman1234 <applemansigloo@gmail.com> | 2022-09-25 13:30:13 +1000 |
|---|---|---|
| committer | Appleman1234 <applemansigloo@gmail.com> | 2022-09-25 13:30:13 +1000 |
| commit | 2c69095a1edf7474073451285238659d0f62ce3f (patch) | |
| tree | 5dee476605402c66dc2853d0836b29f6aedae62b /inc/lib/webm/ffmpeg.php | |
| parent | e9a61e2fbbd930eaa80d6a5f33420cedc59d748c (diff) | |
PHP8.1 fixes from Rector
Diffstat (limited to 'inc/lib/webm/ffmpeg.php')
| -rw-r--r-- | inc/lib/webm/ffmpeg.php | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/inc/lib/webm/ffmpeg.php b/inc/lib/webm/ffmpeg.php index 0747b420..56339cff 100644 --- a/inc/lib/webm/ffmpeg.php +++ b/inc/lib/webm/ffmpeg.php @@ -5,12 +5,12 @@ */ function get_webm_info($filename) { global $board, $config; - $filename = escapeshellarg($filename); + $filename = escapeshellarg((string) $filename); $ffprobe = $config['webm']['ffprobe_path']; - $ffprobe_out = array(); - $webminfo = array(); + $ffprobe_out = []; + $webminfo = []; exec("$ffprobe -v quiet -print_format json -show_format -show_streams $filename", $ffprobe_out); - $ffprobe_out = json_decode(implode("\n", $ffprobe_out), 1); + $ffprobe_out = json_decode(implode("\n", $ffprobe_out), 1, 512, JSON_THROW_ON_ERROR); $webminfo['error'] = is_valid_webm($ffprobe_out); if(empty($webminfo['error'])) { $webminfo['width'] = $ffprobe_out['streams'][0]['width']; @@ -22,34 +22,34 @@ function get_webm_info($filename) { function is_valid_webm($ffprobe_out) { global $board, $config; if (empty($ffprobe_out)) - return array('code' => 1, 'msg' => $config['error']['genwebmerror']); - $extension = pathinfo($ffprobe_out['format']['filename'], PATHINFO_EXTENSION); + return ['code' => 1, 'msg' => $config['error']['genwebmerror']]; + $extension = pathinfo((string) $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']); + return ['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']); + return ['code' => 2, 'msg' => $config['error']['invalidwebm']]; } else { - return array('code' => 1, 'msg' => $config['error']['genwebmerror']); + return ['code' => 1, 'msg' => $config['error']['genwebmerror']]; } - if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio'])) - return array('code' => 3, 'msg' => $config['error']['webmhasaudio']); + if (((is_countable($ffprobe_out['streams']) ? count($ffprobe_out['streams']) : 0) > 1) && (!$config['webm']['allow_audio'])) + return ['code' => 3, 'msg' => $config['error']['webmhasaudio']]; if (empty($ffprobe_out['streams'][0]['width']) || (empty($ffprobe_out['streams'][0]['height']))) - return array('code' => 2, 'msg' => $config['error']['invalidwebm']); + return ['code' => 2, 'msg' => $config['error']['invalidwebm']]; if ($ffprobe_out['format']['duration'] > $config['webm']['max_length']) - return array('code' => 4, 'msg' => sprintf($config['error']['webmtoolong'], $config['webm']['max_length'])); + return ['code' => 4, 'msg' => sprintf($config['error']['webmtoolong'], $config['webm']['max_length'])]; } function make_webm_thumbnail($filename, $thumbnail, $width, $height, $duration) { global $board, $config; - $filename = escapeshellarg($filename); - $thumbnailfc = escapeshellarg($thumbnail); // Should be safe by default but you + $filename = escapeshellarg((string) $filename); + $thumbnailfc = escapeshellarg((string) $thumbnail); // Should be safe by default but you // can never be too safe. - $width = escapeshellarg($width); - $height = escapeshellarg($height); // Same as above. + $width = escapeshellarg((string) $width); + $height = escapeshellarg((string) $height); // Same as above. $ffmpeg = $config['webm']['ffmpeg_path']; $ret = 0; - $ffmpeg_out = array(); + $ffmpeg_out = []; exec("$ffmpeg -strict -2 -ss " . floor($duration / 2) . " -i $filename -v quiet -an -vframes 1 -f mjpeg -vf scale=$width:$height $thumbnailfc 2>&1", $ffmpeg_out, $ret); // Work around for https://trac.ffmpeg.org/ticket/4362 if (filesize($thumbnail) === 0) { |
