ffmpeg.php: do ffprobe checks early on

This commit is contained in:
Zankaria 2025-10-09 22:49:18 +02:00
parent 477485458e
commit 1a803170ca

View file

@ -59,6 +59,23 @@ function is_valid_webm($ffprobe_out) {
if (empty($ffprobe_out)) { if (empty($ffprobe_out)) {
return [ 'error' => [ 'code' => 1, 'msg' => $config['error']['genwebmerror'] ] ]; return [ 'error' => [ 'code' => 1, 'msg' => $config['error']['genwebmerror'] ] ];
} }
if ($ffprobe_out['format']['duration'] > $config['webm']['max_length']) {
return [
'error' => [
'code' => 4,
'msg' => sprintf($config['error']['webmtoolong'], $config['webm']['max_length']) . 'error 6'
]
];
}
if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio'])) {
return [
'error' => [
'code' => 3,
'msg' => $config['error']['webmhasaudio'] . 'error 4'
]
];
}
$trackmap = locate_webm_tracks($ffprobe_out); $trackmap = locate_webm_tracks($ffprobe_out);
// one video track // one video track
@ -72,8 +89,8 @@ function is_valid_webm($ffprobe_out) {
} }
// If there's more than one video, yolo it // If there's more than one video, yolo it
$videoidx = $trackmap['videoat'][0]; $videoidx = $trackmap['videoat'][0];
$extension = \pathinfo($ffprobe_out['format']['filename'], \PATHINFO_EXTENSION);
$extension = pathinfo($ffprobe_out['format']['filename'], PATHINFO_EXTENSION);
if ($extension === 'webm' && !stristr($ffprobe_out['format']['format_name'], 'mp4')) { if ($extension === 'webm' && !stristr($ffprobe_out['format']['format_name'], 'mp4')) {
if ($ffprobe_out['format']['format_name'] != 'matroska,webm') { if ($ffprobe_out['format']['format_name'] != 'matroska,webm') {
return [ return [
@ -101,14 +118,6 @@ function is_valid_webm($ffprobe_out) {
] ]
]; ];
} }
if ((count($ffprobe_out['streams']) > 1) && (!$config['webm']['allow_audio'])) {
return [
'error' => [
'code' => 3,
'msg' => $config['error']['webmhasaudio'] . 'error 4'
]
];
}
if ((count($trackmap['audioat']) > 0) && !$config['webm']['allow_audio']) { if ((count($trackmap['audioat']) > 0) && !$config['webm']['allow_audio']) {
return [ return [
'error' => [ 'error' => [
@ -117,14 +126,7 @@ function is_valid_webm($ffprobe_out) {
] ]
]; ];
} }
if ($ffprobe_out['format']['duration'] > $config['webm']['max_length']) {
return [
'error' => [
'code' => 4,
'msg' => sprintf($config['error']['webmtoolong'], $config['webm']['max_length']) . 'error 6'
]
];
}
return [ return [
'error' => [], 'error' => [],
'trackmap' => $trackmap 'trackmap' => $trackmap