GIF plugin: Fix the FPS detection and add webm creation as a future-looking feature.

pull/1126/head
Ira Abramov 2018-01-03 16:48:34 +02:00
parent 600838785f
commit 1620f2cc78
1 changed files with 16 additions and 6 deletions

View File

@ -20,6 +20,7 @@ function v2gif {
param '6: -t ; Optional: Tag the result with quality stamp for comparison use' param '6: -t ; Optional: Tag the result with quality stamp for comparison use'
param '7: -f <num> ; Optional: Change number of frames per second (default 10 or original FPS if mediainfo installed)' param '7: -f <num> ; Optional: Change number of frames per second (default 10 or original FPS if mediainfo installed)'
param '8: -a <num> ; Optional: Alert if resulting file is over <num> kilobytes (default is 5000, 0 turns off)' param '8: -a <num> ; Optional: Alert if resulting file is over <num> kilobytes (default is 5000, 0 turns off)'
param '9: -m ; Optional: Also create a WebM file (will one day replace GIF, Smaller and higher quality than mp4)'
example '$ v2gif foo.mov' example '$ v2gif foo.mov'
example '$ v2gif foo.mov -w 600' example '$ v2gif foo.mov -w 600'
example '$ v2gif -l 100 -d *.mp4' example '$ v2gif -l 100 -d *.mp4'
@ -27,7 +28,7 @@ function v2gif {
example '$ v2gif -thw 600 *.avi *.mov' example '$ v2gif -thw 600 *.avi *.mov'
# Parse the options # Parse the options
local args=$(getopt -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -o "a:l:w:f:dht" -- "$@") 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 use_gifski=""
local del_after="" local del_after=""
@ -39,6 +40,7 @@ function v2gif {
local defaultfps=10 local defaultfps=10
local infps="" local infps=""
local fps="" local fps=""
local make_webm=""
local alert=5000 local alert=5000
eval set -- "$args" eval set -- "$args"
while [ $# -ge 1 ]; do while [ $# -ge 1 ]; do
@ -87,6 +89,11 @@ function v2gif {
alert="$2" alert="$2"
shift 2 shift 2
;; ;;
-m|--webm)
# set size alert
make_webm="true"
shift
;;
esac esac
done done
@ -106,17 +113,20 @@ function v2gif {
local output_file="${file%.*}${giftag}.gif" local output_file="${file%.*}${giftag}.gif"
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
fi
# Set FPS to match the video if possible, otherwise fallback to default. # Set FPS to match the video if possible, otherwise fallback to default.
if [[ "$infps" ]] ; then if [[ "$infps" ]] ; then
fps=$infps fps=$infps
else else
fps=$defaultfps fps=$defaultfps
if [[ -x /usr/bin/mediainfo ]] ; then if [[ -x /usr/bin/mediainfo ]] ; then
if /usr/bin/mediainfo "$file" | grep -q "Frame rate mode *: Variable" ; then fps=$(/usr/bin/mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
fps=$(/usr/bin/mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1) [[ -z "$fps" ]] && fps=$(/usr/bin/mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
else
fps=$(/usr/bin/mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
fi
fi fi
fi fi