Skip to content

Commit

Permalink
Add seek-in value option for video thumbnails
Browse files Browse the repository at this point in the history
* Allows users to specify which percentage of the total video duration
to seek in instead of hardcoding 15%.
* Now defaults to 50%.
  • Loading branch information
glubsy committed Nov 29, 2020
1 parent 6d7ee93 commit 8280aff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/_h5ai/private/conf/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -366,6 +367,7 @@
"doc": ["x-pdf", "x-ps"],
"delay": 1,
"size": 240,
"seek": 50,
"exif": false,
"chunksize": 20
},
Expand Down
16 changes: 10 additions & 6 deletions src/_h5ai/private/php/ext/class-thumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,17 @@ private function compute_duration($cmdv, $source_path) {
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)
);
}
}

Expand Down

0 comments on commit 8280aff

Please sign in to comment.