stash/pkg/ffmpeg/transcoder/image.go
yoshnopa a2e477e1a7
Support image clips/gifs (#3583)
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2023-05-17 09:30:51 +10:00

44 lines
1,006 B
Go

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
}