Compare commits
3 Commits
v0.2.0-alp
...
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| cb75a2becf | |||
| e117522f3b | |||
| af6c7b3699 |
@@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
thumbnailgen "github.com/pablu23/thumbnail-gen"
|
thumbnailgen "git.pablu.de/pablu/thumbnail-gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
20
generator.go
20
generator.go
@@ -65,7 +65,7 @@ func (opts *Options) GetThumbnail(path string) ([][]byte, int, error) {
|
|||||||
if opts.UseSegments {
|
if opts.UseSegments {
|
||||||
interval = int(length / float64(opts.Segments))
|
interval = int(length / float64(opts.Segments))
|
||||||
} else {
|
} else {
|
||||||
interval = opts.Interval
|
interval = opts.Interval
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetThumbnailUnderlying(path, opts.MaxThumbnails, filters, length, interval, opts.EnableFilter, opts.Format, opts.Scale)
|
return GetThumbnailUnderlying(path, opts.MaxThumbnails, filters, length, interval, opts.EnableFilter, opts.Format, opts.Scale)
|
||||||
@@ -137,7 +137,7 @@ func GetImage(buf *bytes.Buffer, path string, timestamp int, format string, scal
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetVideoLength(path string) (float64, error) {
|
func GetVideoLength(path string) (float64, error) {
|
||||||
cmd := exec.Command("ffprobe", "-v", "quiet", "-select_streams", "v:0", "-show_entries", "stream=duration", "-of", "default=noprint_wrappers=1:nokey=1", path)
|
cmd := exec.Command("ffprobe", "-v", "quiet", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", path)
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
cmd.Stdout = buf
|
cmd.Stdout = buf
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
@@ -148,9 +148,23 @@ func GetVideoLength(path string) (float64, error) {
|
|||||||
return strconv.ParseFloat(strings.ReplaceAll(buf.String(), "\n", ""), 64)
|
return strconv.ParseFloat(strings.ReplaceAll(buf.String(), "\n", ""), 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func escapeFilterValue(value string) string {
|
||||||
|
return strings.NewReplacer(
|
||||||
|
"\\", "\\\\",
|
||||||
|
"'", "\\'",
|
||||||
|
":", "\\:",
|
||||||
|
",", "\\,",
|
||||||
|
";", "\\;",
|
||||||
|
"[", "\\[",
|
||||||
|
"]", "\\]",
|
||||||
|
).Replace(value)
|
||||||
|
}
|
||||||
|
|
||||||
func GetFilter(path string) ([]TimeFilter, error) {
|
func GetFilter(path string) ([]TimeFilter, error) {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
cmd := exec.Command("ffprobe", "-f", "lavfi", "-i", fmt.Sprintf("movie=%s,blackdetect[out0]", path), "-show_entries", "tags=lavfi.black_start,lavfi.black_end", "-of", "default=nw=1", "-v", "quiet")
|
filter := fmt.Sprintf("movie=filename='%s',blackdetect[out0]", escapeFilterValue(path))
|
||||||
|
|
||||||
|
cmd := exec.Command("ffprobe", "-f", "lavfi", "-i", filter, "-show_entries", "tags=lavfi.black_start,lavfi.black_end", "-of", "default=nw=1", "-v", "quiet")
|
||||||
cmd.Stdout = buf
|
cmd.Stdout = buf
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
// TODO: Replace with strings.Builder
|
// TODO: Replace with strings.Builder
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module github.com/pablu23/thumbnail-gen
|
module git.pablu.de/pablu/thumbnail-gen
|
||||||
|
|
||||||
go 1.22.4
|
go 1.22.4
|
||||||
|
|||||||
Reference in New Issue
Block a user