Skip to content

Commit 1bcc80b

Browse files
committed
fix(previews): ffprobe hangs
Signed-off-by: Andrey Dyakov <adduxa@gmail.com>
1 parent 1a43e65 commit 1bcc80b

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- Andreas Pflug <dev@admin4.org>
3333
- Andrew Brown <andrew@casabrown.com>
3434
- Andrey Borysenko <andrey.borysenko@nextcloud.com>
35+
- Andrey Dyakov <adduxa@gmail.com>
3536
- André Gaul <gaul@web-yard.de>
3637
- Andy Xheli <axheli@axtsolutions.com>
3738
- Anna Larch <anna@nextcloud.com>

lib/private/Preview/Movie.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,39 @@ private function useHdr(string $absPath): bool {
289289
if ($test_hdr_proc === false) {
290290
return false;
291291
}
292-
$test_hdr_stdout = trim(stream_get_contents($test_hdr_pipes[1]));
293-
$test_hdr_stderr = trim(stream_get_contents($test_hdr_pipes[2]));
292+
293+
stream_set_blocking($test_hdr_pipes[1], false);
294+
stream_set_blocking($test_hdr_pipes[2], false);
295+
296+
$test_hdr_stdout = '';
297+
$test_hdr_stderr = '';
298+
299+
while (!feof($test_hdr_pipes[1]) || !feof($test_hdr_pipes[2])) {
300+
$read = array_filter([
301+
!feof($test_hdr_pipes[1]) ? $test_hdr_pipes[1] : null,
302+
!feof($test_hdr_pipes[2]) ? $test_hdr_pipes[2] : null,
303+
]);
304+
$write = $except = [];
305+
if (stream_select($read, $write, $except, 5) === false) {
306+
break;
307+
}
308+
foreach ($read as $pipe) {
309+
$chunk = fread($pipe, 8192);
310+
if ($chunk === false) continue;
311+
if ($pipe === $test_hdr_pipes[1]) {
312+
$test_hdr_stdout .= $chunk;
313+
} else {
314+
$test_hdr_stderr .= $chunk;
315+
}
316+
}
317+
}
318+
319+
fclose($test_hdr_pipes[1]);
320+
fclose($test_hdr_pipes[2]);
294321
proc_close($test_hdr_proc);
322+
323+
$test_hdr_stdout = trim($test_hdr_stdout);
324+
$test_hdr_stderr = trim($test_hdr_stderr);
295325
// search build options for libzimg (provides zscale filter)
296326
$ffmpeg_libzimg_installed = strpos($test_hdr_stderr, '--enable-libzimg');
297327
// Only values of "smpte2084" and "arib-std-b67" indicate an HDR video.

0 commit comments

Comments
 (0)