photoprism/internal/ffmpeg/config.go
Michael Mayer 3cf1c699df Video: Refactor FFmpeg Transcoding Size Limit #3466 #3498 #3549
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-07-18 15:15:04 +02:00

23 lines
735 B
Go

package ffmpeg
import "fmt"
// Options represents transcoding options.
type Options struct {
Bin string
Encoder AvcEncoder
Size int
Bitrate string
MapVideo string
MapAudio string
}
// VideoFilter returns the FFmpeg video filter string based on the size limit in pixels and the pixel format.
func (o Options) VideoFilter(format PixelFormat) string {
// scale specifies the FFmpeg downscale filter, see http://trac.ffmpeg.org/wiki/Scaling.
if format == "" {
return fmt.Sprintf("scale='if(gte(iw,ih), min(%d, iw), -2):if(gte(iw,ih), -2, min(%d, ih))'", o.Size, o.Size)
} else {
return fmt.Sprintf("scale='if(gte(iw,ih), min(%d, iw), -2):if(gte(iw,ih), -2, min(%d, ih))',format=%s", o.Size, o.Size, format)
}
}