mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 08:44:04 +01:00
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package ffmpeg
|
|
|
|
import (
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/photoprism/photoprism/internal/ffmpeg/encode"
|
|
)
|
|
|
|
// ExtractImageCmd extracts a still image from the specified source video file.
|
|
func ExtractImageCmd(videoName, imageName string, opt *encode.Options) *exec.Cmd {
|
|
imageExt := strings.ToLower(filepath.Ext(imageName))
|
|
|
|
switch imageExt {
|
|
case ".png":
|
|
return ExtractPngImageCmd(videoName, imageName, opt)
|
|
default:
|
|
return ExtractJpegImageCmd(videoName, imageName, opt)
|
|
}
|
|
}
|
|
|
|
// ExtractJpegImageCmd extracts a JPEG still image from the specified source video file.
|
|
func ExtractJpegImageCmd(videoName, imageName string, opt *encode.Options) *exec.Cmd {
|
|
// TODO: Adjust command flags for correct colors with HDR10-encoded HEVC videos,
|
|
// see https://github.com/photoprism/photoprism/issues/4488.
|
|
// Unfortunately, this filter would render thumbnails of non-HDR videos too dark:
|
|
// "-vf", "zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=gamma:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p",
|
|
return exec.Command(
|
|
opt.Bin,
|
|
"-hide_banner", "-y", "-strict", "-2", "-loglevel", "error",
|
|
"-ss", opt.TimeOffset, "-i", videoName,
|
|
"-skip_frame", "nokey", // skip non-keyframes
|
|
"-frames:v", "1",
|
|
imageName,
|
|
)
|
|
}
|
|
|
|
// ExtractPngImageCmd extracts a PNG still image from the specified source video file.
|
|
func ExtractPngImageCmd(videoName, imageName string, opt *encode.Options) *exec.Cmd {
|
|
return exec.Command(
|
|
opt.Bin,
|
|
"-hide_banner", "-y", "-strict", "-2", "-loglevel", "error",
|
|
"-ss", opt.TimeOffset, "-i", videoName,
|
|
"-skip_frame", "nokey", // skip non-keyframes
|
|
"-frames:v", "1",
|
|
imageName,
|
|
)
|
|
}
|