Added patch to optimize WebM files

This commit is contained in:
Eduard Urbach 2018-11-08 19:12:49 +09:00
parent 9cc4cbed03
commit 3eda84067d
4 changed files with 96 additions and 6 deletions

View File

@ -0,0 +1,90 @@
package main
import (
"fmt"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
func main() {
color.Yellow("Optimizing all webm files in notify.moe AMV directory for fast streaming & seeking")
color.Yellow("DO NOT RUN THIS COMMAND MULTIPLE TIMES")
defer color.Green("Finished")
readFiles(path.Join(arn.Root, "videos", "amvs"), mkclean)
}
// Optimize a webm file
func mkclean(file string) error {
fmt.Println(file)
optimizedFile := file + ".optimized"
// Run mkclean
cmd := exec.Command(
"mkclean",
"--doctype", "4",
"--keep-cues",
"--optimize",
file,
optimizedFile,
)
// View mkclean output in terminal
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err := cmd.Start()
if err != nil {
return err
}
err = cmd.Wait()
if err != nil {
return err
}
// Now delete the original file and replace it with the optimized file
err = os.Remove(file)
if err != nil {
return err
}
return os.Rename(optimizedFile, file)
}
// Read files in a given directory and apply a function on them
func readFiles(root string, onFile func(string) error) {
filepath.Walk(root, func(name string, info os.FileInfo, err error) error {
if err != nil {
color.Red(err.Error())
return err
}
if info.IsDir() {
return nil
}
if !strings.HasSuffix(name, ".webm") {
return nil
}
err = onFile(name)
if err != nil {
color.Red(err.Error())
}
// Always continue traversing the directory
return nil
})
}

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:0ac6798a2fe44352cd2518dacb952d2ff6c5ee718a8d9c989d49e5a8590164e3 oid sha256:36eae9e8c891220ed57588460b898c8ff0d3dc30f64f4b893bebb5cec6131fc3
size 2562360 size 2562140

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:d963bd6500dadaf7a791e2df43ac4d6390ef178bab787591fd19a6219990a5c1 oid sha256:e38e4681ea4d00623abd350d0597d53803ca9c6e8ddc0db82bb3dde2bfae4633
size 197393 size 195652

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:6d83b77da8cfacaf02015354be020f7bc69dccf5dd901cf64d6d76a00f119b31 oid sha256:ea164221e6981f53d2c536c297df83d37a281585f98b2457a5ef803e1f8c601d
size 3583207 size 3583093