From 37795128008707c1cf8dc5a9954801bce5014ecc Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Thu, 6 Aug 2020 10:28:27 +0200 Subject: [PATCH] Fix bug points --- project.clj | 2 +- src/video_optimize/core.clj | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/project.clj b/project.clj index 47bedb9..5147db0 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject video-optimize "1.0.2-SNAPSHOT" +(defproject video-optimize "1.0.3-SNAPSHOT" :description "Watcher and optimize videos" :url "http://example.com/FIXME" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" diff --git a/src/video_optimize/core.clj b/src/video_optimize/core.clj index a7fb783..4bd42cd 100644 --- a/src/video_optimize/core.clj +++ b/src/video_optimize/core.clj @@ -14,19 +14,25 @@ (def audio_quality_thumbnail (:audio_quality_thumbnail 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 #"\/")))] + (prn path_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" (str width_thumbnail "kb") path_thumbnail_temp) + (shell/sh "mv" path_thumbnail_temp path_thumbnail) + (prn (str "Finish: " path_thumbnail)))))) + (defn -main [& args] ;; Watch (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)) - 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)) - ;; 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" (str width_thumbnail "kb") path_thumbnail_temp) - (shell/sh "mv" path_thumbnail_temp path_thumbnail) - (prn (str "Finish: " path_thumbnail))))))}]) + (convertVideo e))}]) (println "Running: Feed me!"))