-
-
Notifications
You must be signed in to change notification settings - Fork 742
/
image.go
44 lines (33 loc) · 1006 Bytes
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package transcoder
import (
"errors"
"github.com/stashapp/stash/pkg/ffmpeg"
)
var ErrUnsupportedFormat = errors.New("unsupported image format")
type ImageThumbnailOptions struct {
InputFormat ffmpeg.ImageFormat
OutputFormat ffmpeg.ImageFormat
OutputPath string
MaxDimensions int
Quality int
}
func ImageThumbnail(input string, options ImageThumbnailOptions) ffmpeg.Args {
var videoFilter ffmpeg.VideoFilter
videoFilter = videoFilter.ScaleMaxSize(options.MaxDimensions)
var args ffmpeg.Args
args = append(args, "-hide_banner")
args = args.LogLevel(ffmpeg.LogLevelError)
args = args.Overwrite().
ImageFormat(options.InputFormat).
Input(input).
VideoFilter(videoFilter).
VideoCodec(ffmpeg.VideoCodecMJpeg)
args = append(args, "-frames:v", "1")
if options.Quality > 0 {
args = args.FixedQualityScaleVideo(options.Quality)
}
args = args.ImageFormat(ffmpeg.ImageFormatImage2Pipe).
Output(options.OutputPath).
ImageFormat(options.OutputFormat)
return args
}