Add config

This commit is contained in:
Andros Fenollosa 2020-07-14 00:00:18 +02:00
parent 05dba25715
commit b9a256b293
7 changed files with 48 additions and 39 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ pom.xml.asc
/.nrepl-port /.nrepl-port
.hgignore .hgignore
.hg/ .hg/
videos/

View File

@ -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

View File

@ -1,7 +1,32 @@
# video-optimize # Usage
## Usage 1) Create `config.yaml`.
``` bash ``` 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).

3
config.yaml Normal file
View File

@ -0,0 +1,3 @@
extension_thumbnail: "_thumbnail.mp4"
width_thumbnail: 600
path_videos: "videos"

View File

@ -1,3 +0,0 @@
# Introduction to video-optimize
TODO: write [great documentation](http://jacobian.org/writing/what-to-write/)

View File

@ -4,7 +4,10 @@
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :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/"} :url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.1"] :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 :main ^:skip-aot video-optimize.core
:aot [video-optimize.core] :aot [video-optimize.core]
:repl-options {:init-ns video-optimize.core}) :repl-options {:init-ns video-optimize.core})

View File

@ -2,25 +2,29 @@
(:require (:require
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.string :as str] [clojure.string :as str]
[clj-yaml.core :as yaml]
[hawk.core :as hawk] [hawk.core :as hawk]
[clojure.java.shell :as shell])) [clojure.java.shell :as shell]))
(def EXTENSION_THUMBNAIL "_thumbnail.mp4") ;; VARIABLES
(def PATH_VIDEOS "videos") (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] (defn -main [& args]
;; Watch ;; Watch
(hawk/watch! [{:paths [PATH_VIDEOS] (hawk/watch! [{:paths [path_videos]
:handler (fn [ctx e] :handler (fn [ctx e]
(let [path_raw (.getAbsolutePath (:file e)) (let [path_raw (.getAbsolutePath (:file e))
is_thumbnail (doall (re-find (re-pattern EXTENSION_THUMBNAIL) path_raw)) is_thumbnail (doall (re-find (re-pattern extension_thumbnail) path_raw))
path_thumbnail (str/join (concat (drop-last (str/split path_raw #"\.")) EXTENSION_THUMBNAIL))] 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)))) (if (and (.exists (io/file path_raw)) (not is_thumbnail) (not (.exists (io/file path_thumbnail))))
(do (do
(prn (str "Optimizing: " path_raw)) (prn (str "Optimizing: " path_raw))
; Optimizing with ffmpeg ;; 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) (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)))) (prn (str "Finish: " path_thumbnail))))
) )
)}]) )}])
(println "Run video converter")) (println "Running: Feed me!"))