Compare commits

..

10 Commits

Author SHA1 Message Date
Andros Fenollosa
142ce46da8
Update README.md 2022-09-19 10:09:26 +02:00
Andros Fenollosa
899be289e6 Only optimize option 2022-01-31 22:38:58 +01:00
Andros Fenollosa
b6b8e06a11
Update README.md 2022-01-30 17:14:01 +01:00
Andros Fenollosa
3a66a39a72
Update README.md 2022-01-30 17:12:30 +01:00
Andros Fenollosa
8e20d8373e
Update README.md 2022-01-30 17:11:26 +01:00
Andros Fenollosa
2ee6ec0fde
Add files via upload 2022-01-30 17:08:25 +01:00
Andros Fenollosa
3779512800 Fix bug points 2020-08-06 10:28:27 +02:00
Andros Fenollosa
e06d5f1f24 Add temp folder and config quality audio 2020-07-15 11:28:31 +02:00
Andros Fenollosa
0763285918
Update project.clj 2020-07-14 11:39:54 +02:00
Andros Fenollosa
74a1083c32
Update README.md 2020-07-14 11:39:38 +02:00
6 changed files with 44 additions and 11 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ pom.xml.asc
.hgignore .hgignore
.hg/ .hg/
videos/ videos/
.DS_Store

View File

@ -1,3 +1,9 @@
# Auto video thumbnail
Watch and resize all the videos you deposit in one folder.
<img width="100%" src="demo.gif">
# Install # Install
1) Install Java. 1) Install Java.
@ -5,7 +11,7 @@
Debian/Ubuntu Debian/Ubuntu
``` bash ``` bash
sudo apt install default-jdk sudo apt install default-jdk ffmpeg
``` ```
Mac OS Mac OS
@ -20,6 +26,7 @@ brew install openjdk
extension_thumbnail: "_thumbnail.mp4" extension_thumbnail: "_thumbnail.mp4"
width_thumbnail: 600 width_thumbnail: 600
path_videos: "videos" path_videos: "videos"
audio_quality_thumbnail: 128
``` ```
3) Make folder `path_videos`. 3) Make folder `path_videos`.
@ -37,6 +44,12 @@ https://github.com/tanrax/auto-video-thumbnail/releases
6) Now you can execute. 6) Now you can execute.
``` bash
java -jar video-optimize-{version}-SNAPSHOT-standalone.jar
```
or
``` bash ``` bash
java $JVM_OPTS -cp video-optimize-{version}-SNAPSHOT-standalone.jar clojure.main -m video-optimize.core java $JVM_OPTS -cp video-optimize-{version}-SNAPSHOT-standalone.jar clojure.main -m video-optimize.core
``` ```
@ -46,3 +59,9 @@ java $JVM_OPTS -cp video-optimize-{version}-SNAPSHOT-standalone.jar clojure.main
Everything you leave in the videos folder will be optimized for web with the specified resolution (600px in this example). Everything you leave in the videos folder will be optimized for web with the specified resolution (600px in this example).
example.mp4 -> example_thumbnail.mp4 example.mp4 -> example_thumbnail.mp4
# Tricks
## I just want to optimise, without resizing
Delete from your settings `width_thumbnail`.

View File

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

BIN
demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -1,4 +1,4 @@
(defproject video-optimize "1.0.0-SNAPSHOT" (defproject video-optimize "1.0.4"
:description "Watcher and optimize videos" :description "Watcher and optimize videos"
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
: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"

View File

@ -11,19 +11,31 @@
(def config (yaml/parse-string (slurp "config.yaml"))) (def config (yaml/parse-string (slurp "config.yaml")))
(def extension_thumbnail (:extension_thumbnail config)) (def extension_thumbnail (:extension_thumbnail config))
(def width_thumbnail (:width_thumbnail config)) (def width_thumbnail (:width_thumbnail config))
(def audio_quality_thumbnail (:audio_quality_thumbnail config))
(def path_videos (:path_videos config)) (def path_videos (:path_videos config))
(defn convertVideo
;; Optimize video
[e]
(let [path_raw (.getAbsolutePath (:file e))
is_thumbnail (doall (re-find (re-pattern extension_thumbnail) path_raw))
path_thumbnail (str (str/join "." ( drop-last (str/split path_raw #"\."))) extension_thumbnail)
path_thumbnail_temp (str "/tmp/" (last (str/split path_thumbnail #"\/")))]
(if (and (.exists (io/file path_raw)) (not is_thumbnail) (not (.exists (io/file path_thumbnail))))
(do
(prn (str "Optimizing: " path_raw))
(if (nil? width_thumbnail)
;; Not width, not scale
(shell/sh "ffmpeg" "-y" "-i" path_raw "-c:v" "libx264" "-c:a" "aac" "-ab" (str audio_quality_thumbnail) "-strict" "-2" path_thumbnail_temp)
;; With width, scale
(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" "-c:a" "aac" "-ab" (str audio_quality_thumbnail) path_thumbnail_temp))
(shell/sh "mv" path_thumbnail_temp path_thumbnail)
(prn (str "Finish: " path_thumbnail))))))
(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)) (convertVideo 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))]
(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" (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 "Running: Feed me!")) (println "Running: Feed me!"))