Continued development
This commit is contained in:
parent
16f900dc21
commit
6840166086
|
@ -0,0 +1,46 @@
|
|||
package ffmpeg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
FFPROBE = "/usr/bin/ffprobe"
|
||||
)
|
||||
|
||||
// Remove executes mega-rm src
|
||||
func Duration(fn string) (duration float64, err error) {
|
||||
// ffprobe -i "KatyDid's Channel, The JACK Show Reads Graham Nolans Chuck Dixon Tweet.mp3" -show_entries format=duration -v quiet -of csv="p=0"
|
||||
//"\"" + fn + "\"",
|
||||
args := []string{
|
||||
"-i",
|
||||
`""` + fn + `""`,
|
||||
"-show_entries",
|
||||
"format=duration",
|
||||
"-v",
|
||||
"quiet",
|
||||
"-of",
|
||||
"csv=\"p=0\"",
|
||||
}
|
||||
fmt.Println("[ffmpeg]", FFPROBE, args)
|
||||
//_duration, err := exec.Command(FFPROBE, args...).Output()
|
||||
cmd := exec.Command(FFPROBE, args...)
|
||||
cmd.Stderr = os.Stderr
|
||||
data, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Println("[ffmpeg] error[0]:", err)
|
||||
fmt.Println(data)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
duration, err = strconv.ParseFloat(string(data), 64)
|
||||
if err != nil {
|
||||
fmt.Println("[ffmpeg] error[1]:", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
|||
module cd.cdmnky.dev/cdmnky/go
|
||||
module cdmnky.dev/cdmnky/go
|
||||
|
||||
go 1.20
|
||||
|
|
18
img/img.go
18
img/img.go
|
@ -1,18 +1,34 @@
|
|||
package img
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/anthonynsimon/bild/adjust"
|
||||
)
|
||||
|
||||
const (
|
||||
StyleDark = 0.70
|
||||
StyleDark = -0.70
|
||||
|
||||
ffmpegBin = "/usr/bin/ffmpeg"
|
||||
)
|
||||
|
||||
var ErrorFFMPEGBinaryNotFound = fmt.Errorf("ffmpeg binary not found: %s", ffmpegBin)
|
||||
|
||||
func CreateThumbnail(videoFile, thumbFilename string) (err error) {
|
||||
// ffmpeg -i videoFile -ss 00:00:01.000 -vframes 1 output.png
|
||||
cmd := exec.Command(ffmpegBin, "-i", videoFile, "-ss", "00:05:00.000", "-vframes", "1", thumbFilename)
|
||||
_, err = cmd.Output()
|
||||
if err != nil {
|
||||
return ErrorFFMPEGBinaryNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Overlay(inputFile, overlayFile string, style float64) (err error) {
|
||||
thumb, err := os.Open(inputFile)
|
||||
if err != nil {
|
||||
|
|
46
mega/mega.go
46
mega/mega.go
|
@ -74,27 +74,41 @@ func Files(dir string, filetypes []string, sortorder string) (files []FileInfo,
|
|||
return List(dir, filetypes, sortorder)
|
||||
}
|
||||
|
||||
// Find returns an array of mega.FileInfo restricted by specified filetype. Pass an empty
|
||||
// string array for all files. The array will be sorted by name based on the sortorder parameter.
|
||||
// Valid values are:
|
||||
// Find returns an array of mega.FileInfo
|
||||
//
|
||||
// "asc|desc"
|
||||
// To specify a sort order pass either of the following:
|
||||
//
|
||||
// Passing an empty string will default to "asc"
|
||||
func Find(dir, pattern, sortorder string) (files []FileInfo, err error) {
|
||||
// --sort=asc | --sort=desc
|
||||
//
|
||||
// If sort order is not specified it will default to "asc"
|
||||
func Find(dir string, patterns ...string) (files []FileInfo, err error) {
|
||||
|
||||
pattern = "--pattern=" + pattern
|
||||
|
||||
fmt.Println("cmd:", FIND, dir, pattern)
|
||||
out, err := exec.Command(FIND, dir, pattern).Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
sortorder := "asc"
|
||||
_params := []string{}
|
||||
for _, pattern := range patterns {
|
||||
if strings.HasPrefix(pattern, "--sort=") {
|
||||
_toks := strings.Split(pattern, "=")
|
||||
if len(_toks) == 2 && (_toks[1] == "asc" || _toks[1] == "desc") {
|
||||
sortorder = _toks[1]
|
||||
}
|
||||
continue
|
||||
}
|
||||
_params = append(_params, "--pattern="+pattern)
|
||||
}
|
||||
|
||||
lines := strings.Split(string(out), "\n")
|
||||
for _, line := range lines {
|
||||
files = append(files, FileInfo{filepath.Dir(line), filepath.Base(line), line})
|
||||
//files = append(files, FileInfo{filepath.Dir(line), filepath.Base(line), filepath.Join(dir, line)})
|
||||
for _, param := range _params {
|
||||
params := []string{dir, param}
|
||||
fmt.Printf("cmd: %s %s\n", FIND, params)
|
||||
out, err := exec.Command(FIND, params...).Output()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lines := strings.Split(string(out), "\n")
|
||||
for _, line := range lines {
|
||||
files = append(files, FileInfo{filepath.Dir(line), filepath.Base(line), line})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(sortorder) == 0 {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 074bf53d3e8588a20411e944315e43dbc6b94de8
|
Loading…
Reference in New Issue