From bb27aafee5fea2b16be19938f36a82821f8a599d Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sun, 7 Jan 2018 15:19:26 +0200 Subject: [PATCH 1/3] Fix a minute logic bug - if one file deletion is skipped, not all the following deletions will be skipped --- plugins/available/gif.plugin.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index 9e7e95c0..acc40609 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -34,7 +34,7 @@ function v2gif { local args=$(getopt -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") local use_gifski="" - local del_after="" + local opt_del_after="" local maxsize="" local lossiness="" local maxwidthski="" @@ -55,7 +55,7 @@ function v2gif { ;; -d|--del|--delete) # Delete after - del_after="true" + opt_del_after="true" shift ;; -h|--high) @@ -115,6 +115,7 @@ function v2gif { for file in $movies ; do local output_file="${file%.*}${giftag}.gif" + local del_after=$opt_del_after if [[ "$make_webm" ]] ; then ffmpeg -loglevel panic -i "$file" \ @@ -151,7 +152,8 @@ function v2gif { if [[ $alert -gt 0 ]] ; then local out_size=$(wc --bytes < "$output_file") if [[ $out_size -gt $(( alert * 1000 )) ]] ; then - echo "$(tput setaf 3)Warning: '$output_file' is $((out_size/1000))kb, keeping '$file' even if --del requested.$(tput sgr 0)" + echo "$(tput setaf 3)Warning: '$output_file' is $((out_size/1000))kb.$(tput sgr 0)" + [[ "$del_after" == "true" ]] && echo "$(tput setaf 3)Warning: Keeping '$file' even though --del requested.$(tput sgr 0)" del_after="" fi fi @@ -179,7 +181,7 @@ function any2webm() { # Parse the options local args=$(getopt -l alert -l "bandwidth:" -l "width:" -l del,delete -l tag -l "fps:" -l webm -o "a:b:w:f:dt" -- "$@") - local del_after="" + local opt_del_after="" local size="" local webmtagopt="" local webmtag="" @@ -197,7 +199,7 @@ function any2webm() { ;; -d|--del|--delete) # Delete after - del_after="true" + opt_del_after="true" shift ;; -s|--size) @@ -245,6 +247,7 @@ function any2webm() { for file in $movies ; do local output_file="${file%.*}${webmtag}.webm" + local del_after=$opt_del_after echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)" @@ -256,7 +259,8 @@ function any2webm() { if [[ $alert -gt 0 ]] ; then local out_size=$(wc --bytes < "$output_file") if [[ $out_size -gt $(( alert * 1000 )) ]] ; then - echo "$(tput setaf 3)Warning: '$output_file' is $((out_size/1000))kb, keeping '$file' even if --del requested.$(tput sgr 0)" + echo "$(tput setaf 3)Warning: '$output_file' is $((out_size/1000))kb.$(tput sgr 0)" + [[ "$del_after" == "true" ]] && echo "$(tput setaf 3)Warning: Keeping '$file' even though --del requested.$(tput sgr 0)" del_after="" fi fi From af3ca28430c896787dba419e9b192fb90bd02d6d Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Sun, 7 Jan 2018 15:30:25 +0200 Subject: [PATCH 2/3] Just in case - make sure WebM output is marked to loop. --- plugins/available/gif.plugin.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index acc40609..85cdf673 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -119,8 +119,8 @@ function v2gif { if [[ "$make_webm" ]] ; then ffmpeg -loglevel panic -i "$file" \ - -c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 -quality best \ - "${file%.*}.webm" || return 2 + -c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \ + -quality best -loop 0 "${file%.*}.webm" || return 2 fi # Set FPS to match the video if possible, otherwise fallback to default. @@ -253,7 +253,7 @@ function any2webm() { ffmpeg -loglevel panic -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v $bandwidth -auto-alt-ref 0 \ - -quality best $fps $size -pix_fmt yuva420p "$output_file" || return 2 + -quality best $fps $size -loop 0 -pix_fmt yuva420p "$output_file" || return 2 # Checking if the file is bigger than Twitter likes and warn if [[ $alert -gt 0 ]] ; then From 19a2dd8bb8aa3fdc35d29922292eed2086c1f12d Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 18 Jan 2018 12:24:10 +0200 Subject: [PATCH 3/3] Support filenames with spaces. Bash is magic sometimes. --- plugins/available/gif.plugin.bash | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index 85cdf673..bdfa4f4b 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -33,6 +33,12 @@ function v2gif { # Parse the options local args=$(getopt -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") + if [ $? -ne 0 ]; then + echo 'Terminating...' >&2 + return 2 + fi + + eval set -- "$args" local use_gifski="" local opt_del_after="" local maxsize="" @@ -45,7 +51,6 @@ function v2gif { local fps="" local make_webm="" local alert=5000 - eval set -- "$args" while [ $# -ge 1 ]; do case "$1" in --) @@ -100,10 +105,7 @@ function v2gif { esac done - # Done Parsing, all that's left are the filenames - local movies="$*" - - if [[ -z "$movies" ]]; then + if [[ -z "$*" ]]; then echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w ] [-l ] < $(tput sgr 0)" return 1 fi @@ -112,7 +114,7 @@ function v2gif { [[ -z "$giftag" ]] && giftag="-default" [[ -z "$giftagopt" ]] && giftag="" - for file in $movies ; do + for file ; do local output_file="${file%.*}${giftag}.gif" local del_after=$opt_del_after @@ -181,6 +183,12 @@ function any2webm() { # Parse the options local args=$(getopt -l alert -l "bandwidth:" -l "width:" -l del,delete -l tag -l "fps:" -l webm -o "a:b:w:f:dt" -- "$@") + if [ $? -ne 0 ]; then + echo 'Terminating...' >&2 + return 2 + fi + + eval set -- "$args" local opt_del_after="" local size="" local webmtagopt="" @@ -189,7 +197,6 @@ function any2webm() { local fps="" local bandwidth="2M" local alert=5000 - eval set -- "$args" while [ $# -ge 1 ]; do case "$1" in --) @@ -232,10 +239,7 @@ function any2webm() { esac done - # Done Parsing, all that's left are the filenames - local movies="$*" - - if [[ -z "$movies" ]]; then + if [[ -z "$*" ]]; then echo "$(tput setaf 1)No input files given. Example: any2webm file [file...] [-w ] < $(tput sgr 0)" return 1 fi @@ -244,7 +248,7 @@ function any2webm() { [[ -z "$webmtag" ]] && webmtag="-default" [[ -z "$webmtagopt" ]] && webmtag="" - for file in $movies ; do + for file ; do local output_file="${file%.*}${webmtag}.webm" local del_after=$opt_del_after