-
-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in-memory screenshot generation for sprites and phash (#1316)
- Loading branch information
InfiniteTF
authored
May 5, 2021
1 parent
08c2944
commit 31981d4
Showing
6 changed files
with
82 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ffmpeg | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"strings" | ||
) | ||
|
||
type SpriteScreenshotOptions struct { | ||
Time float64 | ||
Width int | ||
} | ||
|
||
func (e *Encoder) SpriteScreenshot(probeResult VideoFile, options SpriteScreenshotOptions) (image.Image, error) { | ||
args := []string{ | ||
"-v", "error", | ||
"-ss", fmt.Sprintf("%v", options.Time), | ||
"-i", probeResult.Path, | ||
"-vframes", "1", | ||
"-vf", fmt.Sprintf("scale=%v:-1", options.Width), | ||
"-c:v", "bmp", | ||
"-f", "rawvideo", | ||
"-", | ||
} | ||
data, err := e.run(probeResult, args) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
reader := strings.NewReader(data) | ||
|
||
img, _, err := image.Decode(reader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return img, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters