1
0
Fork 0
mirror of https://github.com/lrsjng/h5ai synced 2025-12-06 08:52:45 +01:00

Add seek-in value option for video thumbnails

* Allows users to specify which percentage of the total video duration
to seek in instead of hardcoding 15%.
* Now defaults to 50%.
This commit is contained in:
glubsy 2020-11-29 17:51:35 +00:00
parent 7cf18b60f9
commit 5a0c63056c
2 changed files with 12 additions and 6 deletions

View file

@ -356,6 +356,7 @@
- doc: array of strings
- delay: number, delay in milliseconds after "dom-ready" before thumb-requesting starts
- size: number, size in pixel of the generated thumbnails
- seek: number, percentage of total video duration to seek into
- exif: boolean, use included EXIF thumbs if possible
- chunksize: int, number of thumbs per request
*/
@ -366,6 +367,7 @@
"doc": ["x-pdf", "x-ps"],
"delay": 1,
"size": 240,
"seek": 50,
"exif": false,
"chunksize": 20
},

View file

@ -124,13 +124,17 @@ class Thumb {
foreach ($cmdv as &$arg) {
$arg = str_replace('[H5AI_SRC]', $source_path, $arg);
}
$result = Util::exec_cmdv($cmdv);
if (empty($result) || !is_numeric($result) || is_infinite($result)) {
// Force seeking at 1 second in
return "1";
$duration = Util::exec_cmdv($cmdv);
if (empty($duration) || !is_numeric($duration) || is_infinite($duration)) {
return "0.1";
}
// Seek at 15% of the total video duration
return strval(round(((floatval($result) * 15) / 100), 1, PHP_ROUND_HALF_UP));
// Seek at user-defined percentage of the total video duration
return strval(
round(
(floatval($duration) *
floatval($this->context->query_option('thumbnails.seek', 50)) / 100),
1, PHP_ROUND_HALF_UP)
);
}
}