mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-07 17:43:53 +02:00
Allow configuring how video previews are generated
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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') # {{{
|
||||
|
||||
Reference in New Issue
Block a user