Fix scrubber sprite creation for short video files (#2167)

* Fix scrubber sprite creation for small files
* accept only valid ffprobe nbReadFrames
This commit is contained in:
bnkai
2022-01-04 04:46:53 +02:00
committed by GitHub
parent bd784cdf96
commit 849c590b2a
5 changed files with 131 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ import (
type SpriteScreenshotOptions struct {
Time float64
Frame int
Width int
}
@@ -36,3 +37,31 @@ func (e *Encoder) SpriteScreenshot(probeResult VideoFile, options SpriteScreensh
return img, err
}
// SpriteScreenshotSlow uses the select filter to get a single frame from a videofile instead of seeking
// It is very slow and should only be used for files with very small duration in secs / frame count
func (e *Encoder) SpriteScreenshotSlow(probeResult VideoFile, options SpriteScreenshotOptions) (image.Image, error) {
args := []string{
"-v", "error",
"-i", probeResult.Path,
"-vsync", "0", // do not create/drop frames
"-vframes", "1",
"-vf", fmt.Sprintf("select=eq(n\\,%d),scale=%v:-1", options.Frame, options.Width), // keep only frame number options.Frame
"-c:v", "bmp",
"-f", "rawvideo",
"-",
}
data, err := e.run(probeResult.Path, args, nil)
if err != nil {
return nil, err
}
reader := strings.NewReader(data)
img, _, err := image.Decode(reader)
if err != nil {
return nil, err
}
return img, err
}