h5ai
h5ai copied to clipboard
Short video files fail to generate thumbnails
Problem:
Video files with a duration shorter than 10 seconds fail to have their thumbnails generated by ffmpeg/avconv, as these programs are called with the argument -ss 0:00:10
(get the first frame after 10 seconds in).
The ffmpeg output clearly states:
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
Solution:
Two possible implementations:
- Iteration over the current way of doing things:
- call ffmpeg/avconv with a hardcoded '0:00:10' first (what is currently being done)
- capture the entire stderr output (not done properly currently, needs stderr redirection for capture, i.e.
2>&1
), - look for a specific string to see if there is any error, i.e.
nothing was encoded
- if so, store the duration reported by ffmpeg's output into a $duration variable
- call ffmpeg again with a new timestamp argument, which could be 10% of the duration, i.e.
($duration * 10) / 100
;
- A more thorough but perhaps slightly slower way:
- call ffprobe/avprobe for every single video file encountered,
- grab the duration reported by ffprobe into a $duration variable,
- compute a timestamp at 10% of the duration, ie.
$timestamp = ($duration * 10) / 100;
- call ffmpeg with the resulting timestamp
-ss $timestamp
and let it generate the thumbnail
I would go with the latter implementation which seems better than a hard coded value of 10 seconds, which would force us to get every single ffmpeg output to parse and get potential error messages. A merge request is on the way.