From b9a256b29367aeb8218d87b613c6ef99944fca46 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Tue, 14 Jul 2020 00:00:18 +0200 Subject: [PATCH] Add config --- .gitignore | 1 + CHANGELOG.md | 24 ------------------------ README.md | 31 ++++++++++++++++++++++++++++--- config.yaml | 3 +++ doc/intro.md | 3 --- project.clj | 5 ++++- src/video_optimize/core.clj | 20 ++++++++++++-------- 7 files changed, 48 insertions(+), 39 deletions(-) delete mode 100644 CHANGELOG.md create mode 100644 config.yaml delete mode 100644 doc/intro.md diff --git a/.gitignore b/.gitignore index d18f225..da73d48 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +videos/ diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 275e7b3..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,24 +0,0 @@ -# Change Log -All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). - -## [Unreleased] -### Changed -- Add a new arity to `make-widget-async` to provide a different widget shape. - -## [0.1.1] - 2020-07-13 -### Changed -- Documentation on how to make the widgets. - -### Removed -- `make-widget-sync` - we're all async, all the time. - -### Fixed -- Fixed widget maker to keep working when daylight savings switches over. - -## 0.1.0 - 2020-07-13 -### Added -- Files from the new template. -- Widget maker public API - `make-widget-sync`. - -[Unreleased]: https://github.com/your-name/video-optimize/compare/0.1.1...HEAD -[0.1.1]: https://github.com/your-name/video-optimize/compare/0.1.0...0.1.1 diff --git a/README.md b/README.md index 8e6a150..686cd2f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,32 @@ -# video-optimize +# Usage -## Usage +1) Create `config.yaml`. ``` bash -java $JVM_OPTS -cp deploy.jar clojure.main -m video-optimize.core +extension_thumbnail: "_thumbnail.mp4" +width_thumbnail: 600 +path_videos: "videos" ``` + +2) Make folder `path_videos`. + +``` bash +mkdir videos +``` + +3) Install `ffmpeg`. + +4) Download the latest version (`video-optimize-{version}-standalone.jar`). + +https://github.com/tanrax/auto-video-thumbnail/releases + + +5) Now you can execute. + +``` bash +java $JVM_OPTS -cp video-optimize-{version}-standalone.jar clojure.main -m video-optimize.core +``` + +6) Leave videos. + +Everything you leave in the videos folder will be optimized for web with the specified resolution (600 px in this example). diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..d288596 --- /dev/null +++ b/config.yaml @@ -0,0 +1,3 @@ +extension_thumbnail: "_thumbnail.mp4" +width_thumbnail: 600 +path_videos: "videos" diff --git a/doc/intro.md b/doc/intro.md deleted file mode 100644 index be2338f..0000000 --- a/doc/intro.md +++ /dev/null @@ -1,3 +0,0 @@ -# Introduction to video-optimize - -TODO: write [great documentation](http://jacobian.org/writing/what-to-write/) diff --git a/project.clj b/project.clj index d7e7b6f..d06813f 100644 --- a/project.clj +++ b/project.clj @@ -4,7 +4,10 @@ :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.10.1"] - [hawk "0.2.11"]] + ;; Watcher + [hawk "0.2.11"] + ;; Yaml + [clj-yaml "0.4.0"]] :main ^:skip-aot video-optimize.core :aot [video-optimize.core] :repl-options {:init-ns video-optimize.core}) diff --git a/src/video_optimize/core.clj b/src/video_optimize/core.clj index 1932983..865b277 100644 --- a/src/video_optimize/core.clj +++ b/src/video_optimize/core.clj @@ -2,25 +2,29 @@ (:require [clojure.java.io :as io] [clojure.string :as str] + [clj-yaml.core :as yaml] [hawk.core :as hawk] [clojure.java.shell :as shell])) -(def EXTENSION_THUMBNAIL "_thumbnail.mp4") -(def PATH_VIDEOS "videos") +;; VARIABLES +(def config (yaml/parse-string (slurp "config.yaml"))) +(def extension_thumbnail (:extension_thumbnail config)) +(def width_thumbnail (:width_thumbnail config)) +(def path_videos (:path_videos config)) (defn -main [& args] ;; Watch - (hawk/watch! [{:paths [PATH_VIDEOS] + (hawk/watch! [{:paths [path_videos] :handler (fn [ctx e] (let [path_raw (.getAbsolutePath (:file e)) - is_thumbnail (doall (re-find (re-pattern EXTENSION_THUMBNAIL) path_raw)) - path_thumbnail (str/join (concat (drop-last (str/split path_raw #"\.")) EXTENSION_THUMBNAIL))] + is_thumbnail (doall (re-find (re-pattern extension_thumbnail) path_raw)) + path_thumbnail (str/join (concat (drop-last (str/split path_raw #"\.")) extension_thumbnail))] (if (and (.exists (io/file path_raw)) (not is_thumbnail) (not (.exists (io/file path_thumbnail)))) (do (prn (str "Optimizing: " path_raw)) - ; Optimizing with ffmpeg - (shell/sh "ffmpeg" "-y" "-i" path_raw "-vf" "scale=600:-2" "-c:v" "libx264" "-crf" "23" "-profile:v" "high" "-pix_fmt" "yuv420p" "-color_primaries" "1" "-color_trc" "1" "-colorspace" "1" "-movflags" "+faststart" "-an" "-acodec" "aac" "-ab" "128kb" path_thumbnail) + ;; Optimizing with ffmpeg + (shell/sh "ffmpeg" "-y" "-i" path_raw "-vf" (str "scale=" width_thumbnail ":-2") "-c:v" "libx264" "-crf" "23" "-profile:v" "high" "-pix_fmt" "yuv420p" "-color_primaries" "1" "-color_trc" "1" "-colorspace" "1" "-movflags" "+faststart" "-an" "-acodec" "aac" "-ab" "128kb" path_thumbnail) (prn (str "Finish: " path_thumbnail)))) ) )}]) - (println "Run video converter")) + (println "Running: Feed me!"))