diff --git a/kittens/choose_files/ffmpeg.go b/kittens/choose_files/ffmpeg.go index 8d2898803..ebc6e564a 100644 --- a/kittens/choose_files/ffmpeg.go +++ b/kittens/choose_files/ffmpeg.go @@ -32,13 +32,13 @@ type ffmpeg_renderer int var ( video_width = 480 video_fps = 10 - video_duration = 5 + video_duration = 5.0 video_encoding_quality = 75 ) func ffmpeg_thumbnail_cmd(path, outpath string) *exec.Cmd { return exec.Command( - "ffmpeg", "-loglevel", "fatal", "-y", "-i", path, "-t", fmt.Sprintf("%d", video_duration), + "ffmpeg", "-loglevel", "fatal", "-y", "-i", path, "-t", fmt.Sprintf("%f", video_duration), "-vf", fmt.Sprintf("fps=%d,scale=%d:-1:flags=lanczos", video_fps, video_width), "-c:v", "libwebp", "-lossless", "0", "-compression_level", "0", "-q:v", fmt.Sprintf("%d", video_encoding_quality), "-loop", "0", "-f", "webp", outpath, diff --git a/kittens/choose_files/main.go b/kittens/choose_files/main.go index 99c9dc4ba..e3a1e9c7e 100644 --- a/kittens/choose_files/main.go +++ b/kittens/choose_files/main.go @@ -20,6 +20,7 @@ import ( "github.com/kovidgoyal/kitty/tools/tui/loop" "github.com/kovidgoyal/kitty/tools/tui/readline" "github.com/kovidgoyal/kitty/tools/utils" + "github.com/kovidgoyal/kitty/tools/utils/shlex" "golang.org/x/text/message" ) @@ -279,6 +280,35 @@ func load_config(opts *Options) (ans *Config, err error) { return nil, err } ans.KeyboardShortcuts = config.ResolveShortcuts(ans.KeyboardShortcuts) + parts, err := shlex.Split(ans.Video_preview) + if err != nil { + return nil, err + } + for _, x := range parts { + k, v, found := strings.Cut(x, "=") + if !found { + return nil, fmt.Errorf("invalid value %s in video_preview", x) + } + var i uint64 + switch k { + case "duration": + if video_duration, err = strconv.ParseFloat(v, 64); err != nil { + return nil, fmt.Errorf("invalid %s in video_preview: %s", k, v) + } + case "fps": + if i, err = strconv.ParseUint(v, 10, 0); err != nil { + return nil, fmt.Errorf("invalid %s in video_preview: %s", k, v) + } + video_fps = int(i) + case "width": + if i, err = strconv.ParseUint(v, 10, 0); err != nil { + return nil, fmt.Errorf("invalid %s in video_preview: %s", k, v) + } + video_width = int(i) + default: + return nil, fmt.Errorf("unrecognized key in video_preview: %s", k) + } + } return ans, nil } diff --git a/kittens/choose_files/main.py b/kittens/choose_files/main.py index 1868c6d59..22bc22275 100644 --- a/kittens/choose_files/main.py +++ b/kittens/choose_files/main.py @@ -77,6 +77,15 @@ File extension aliases for syntax highlight. For example, to syntax highlight Multiple aliases must be separated by spaces. ''') +opt('video_preview', 'width=480 fps=10 duration=5', long_text=''' +Control how videos are sampled for previwing. The width controls +the size of the generated thumbnail from the video. Duration controls +how long the generated thumbnail plays for, in seconds. Note that when +changing these you should also use :option:`--clear-cache` otherwise it will +not affect already cached previews. +''') + + egr() # }}} agr('shortcuts', 'Keyboard shortcuts') # {{{