62,16 → 62,14 |
# * [[x2]] Find out if egrep is safe to use or grep -E is more commonplace. => |
#+ SUS v2: egrep is deprecated, grep -E replaces it |
# * Change default DVD_TITLE to 0 |
# * Deprecations: |
# OPTION/VAR -> ALTERNATIVE DEPRECATED FROM VERSION REMOVAL ETA |
# --funky -> --profile ? ?+1 |
# --end_offset -> --end-offset 1.13 1.14 |
# (new var names introduced in 1.12) 1.12 1.14 |
# > Usage of ./vcs.conf is also deprecated since it doesn't mesh well with profiles |
# (and it was a bad placeholder for them). Will remain to be loadable with |
# -C:pwd. |
# Loaded by default up to 1.13 (with warning in 1.13). |
# Not loaded from 1.14 onwards |
# * Deprecation schedule: |
# DEPRECATED FROM | EXPECTED REMOVAL | DESCRIPTION |
# 1.12 1.14 New setting names introduced in 1.12 |
# In 1.13 the new names start to be used internally |
# 1.13 1.14 --end_offset -> --end-offset |
# 1.13 1.14 auto-loading ./vcs.conf (lesser version of profiles) |
# -C :pwd will stay |
# ? ?+1 --funky -> --profile |
# * Variables cleanup: |
# Variables will use a more uniform scheme, with prefixes where appropriate: |
# - INTERNAL_*: Used internally to adapt messages and the like to the input |
79,6 → 77,9 |
# - USR_*: Holds values of variables as set by the user, either from overrides or from the |
# command-line. |
# implementation |
# - Global variables will be capitalised while local variables will be lowercase |
# - Setting names (configuration file variables) will be case insensitive, but always |
# displayed and documented in lowercase |
# * Optimisations: |
# - Reduce the number of forks/subshells |
# }}} # TO-DO |
85,8 → 86,8 |
|
# {{{ # Constants |
|
# Configuration file, please, use this file to modify the behaviour of the |
# script. Using this allows overriding some variables (see below) |
# Use configuration files to modify the behaviour of the |
# script. Using them allows overriding some variables (see below) |
# to your liking. Only lines with a variable assignment are evaluated, |
# it should follow bash syntax, note though that ';' can't be used |
# currently in the variable values; e.g.: |
98,18 → 99,18 |
# There is a total of three configuration files than are loaded if the exist: |
# * /etc/vcs.conf: System wide conf, least precedence |
# * ~/.vcs.conf: Per-user conf, second least precedence |
# * ./vcs.conf: Per-dir config, most precedence |
# * ./vcs.conf: Per-dir config, most precedence (deprecated) |
# |
# The variables that can be overriden are below the block of constants ahead. |
|
# Default values, use interval, numcaps and cols to override |
# Default values, use INTERVAL, NUMCAPS and COLUMNS to override |
declare -ri DEFAULT_INTERVAL=300 |
declare -ri DEFAULT_NUMCAPS=16 |
declare -ri DEFAULT_COLS=2 |
declare -ri DEFAULT_COLUMNS=2 |
|
# see $decoder |
declare -ri DEC_MPLAYER=1 DEC_FFMPEG=3 |
# See $timecode_from |
# See $TIMECODE_FROM |
declare -ri TC_INTERVAL=4 TC_NUMCAPS=8 |
# These can't be overriden, modify this line if you feel the need |
declare -r PROGRAM_SIGNATURE="Video Contact Sheet *NIX ${VERSION} <http://p.outlyer.net/vcs/>" |
125,7 → 126,7 |
declare -r SAFE_RENAME_PATTERN="%b-%N.%e" |
# see $extended_factor |
declare -ri DEFAULT_EXT_FACTOR=4 |
# see $verbosity |
# see $VERBOSITY |
declare -ri V_ALL=5 V_NONE=-1 V_ERROR=1 V_WARN=2 V_INFO=3 |
# Indexes in $VID |
declare -ri W=0 H=1 FPS=2 LEN=3 VCODEC=4 ACODEC=5 VDEC=6 CHANS=7 ASPECT=8 VCNAME=9 ACNAME=10 |
152,11 → 153,11 |
# Set to 1 to print function calls |
declare -i DEBUG=0 |
# Text before the user name in the signature |
declare user_signature="Preview created by" |
declare SIGNATURE="Preview created by" |
# By default sign as the system's username (see -u, -U) |
declare user=$(id -un) |
declare USERNAME=$(id -un) |
# Which of the two methods should be used to guess the number of thumbnails |
declare -i timecode_from=$TC_INTERVAL |
declare -i TIMECODE_FROM=$TC_INTERVAL |
# Which of the two vidcappers should be used (see -F, -M) |
# mplayer seems to fail for mpeg or WMV9 files, at least on my system |
# also, ffmpeg allows better seeking: ffmpeg allows exact second.fraction |
168,8 → 169,8 |
declare preferred_capturer=ffmpeg |
# Options used in imagemagick, these options set the final aspect |
# of the contact sheet |
declare output_format=png # ImageMagick decides the type from the extension |
declare -i output_quality=92 # Output image quality (only affects the final |
declare FORMAT=png # ImageMagick decides the type from the extension |
declare -i QUALITY=92 # Output image quality (only affects the final |
# image and obviously only in lossy formats) |
# Colours, see convert -list color to get the list |
declare bg_heading='#afcd7a' # Background for meta info (size, codec...) |
193,7 → 194,7 |
declare -i pts_meta=14 # Used for the meta info heading |
declare -i pts_sign=10 # Used for the signature |
declare -i pts_title=33 # Used for the title (see -T) |
# See -E / $end_offset |
# See -E / $END_OFFSET |
declare -r DEFAULT_END_OFFSET="5.5%" |
# Controls how many extra captures will be created in the extended mode |
# (see -e), 0 is the same as disabling the extended mode |
202,59 → 203,59 |
declare extended_factor=0 |
# Verbosity level so far from the command line can only be muted (see -q) |
# it can be overridden, though |
declare -i verbosity=$V_ALL |
declare -i VERBOSITY=$V_ALL |
# Set to 1 to disable colours in console output |
declare -i plain_messages=0 |
declare -i SIMPLE_FEEDBACK=0 |
# See coherence_check for more details |
declare -i DISABLE_SHADOWS=0 |
declare -i DISABLE_TIMESTAMPS=0 |
|
# Introduced in 1.0.7b, revamped in 1.11: |
# This font is used to display international names (i.e. CJK names) correctly |
# Help from users actually needing this would be appreciated :) |
# Help from users who actually need this would be appreciated :) |
# This variable is filled either automatically through the set_extended_font() |
#+function (and option -Ij) or manually (with option -Ij=MyFontName) |
# The automatic picks a semi-random one from the fonts believed to support CJK/Cyrillic |
#+characters. |
declare FONT_MINCHO= # Filename or font name as known to ImageMagick (identify -list font) |
declare NONLATIN_FONT= # Filename or font name as known to ImageMagick (identify -list font) |
# Introduced in 1.12.2: |
# When true (1) uses $FONT_MINCHO to print the filename, otherwise the same |
# When true (1) uses $NONLATIN_FONT to print the filename, otherwise the same |
#+font as the heading is used. |
# See -I and --nonlatin |
declare -i NONLATIN_FILENAMES=0 |
# Output of capturing programs is redirected here |
declare stdout=/dev/null stderr=/dev/null |
declare STDOUT=/dev/null STDERR=/dev/null |
|
# Override-able since 1.11: |
# Height of the thumbnails, by default use same as input |
declare th_height='100%' |
declare interval=$DEFAULT_INTERVAL # Interval of captures (~length/numcaps) |
declare -i numcaps=$DEFAULT_NUMCAPS # Number of captures (~length/interval) |
# This is the horizontal padding added to each capture. |
declare HEIGHT='100%' |
declare INTERVAL=$DEFAULT_INTERVAL # Interval of captures (~length/$NUMCAPS) |
declare -i NUMCAPS=$DEFAULT_NUMCAPS # Number of captures (~length/$INTERVAL) |
# This is the padding added to each capture. |
# Beware when changing this since extended set's alignment might break. |
# When shadows are enabled this is ignored since they already add padding. |
declare -i HPAD=2 # *WILL CHANGE NAME* |
declare -i cols=$DEFAULT_COLS # Number of output columns |
|
declare -i PADDING=2 |
declare -i COLUMNS=$DEFAULT_COLUMNS # Number of output columns |
# This amount of time is *not* captured from the end of the video |
declare END_OFFSET=$DEFAULT_END_OFFSET |
# }}} # End of override-able variables |
|
# {{{ # Variables |
|
# Options and other internal usage variables, no need to mess with this! |
declare title="" |
declare fromtime=0 # Starting second (see -f) |
declare totime=-1 # Ending second (see -t) |
declare -a initial_stamps # Manually added stamps (see -S) |
declare -i manual_mode=0 # if 1, only command line timestamps will be used |
declare aspect_ratio=0 # If 0 no transformations done (see -a) |
declare TITLE="" |
declare FROMTIME=0 # Starting second (see -f) |
declare TOTIME=-1 # Ending second (see -t) |
declare -a INITIAL_STAMPS # Manually added stamps (see -S) |
declare -i MANUAL_MODE=0 # if 1, only command line timestamps will be used |
declare ASPECT_RATIO=0 # If 0 no transformations done (see -a) |
# If -1 try to guess (see -A) |
|
declare -a TEMPSTUFF # Temporal files |
declare -a TEMPSTUFF # Temporary files |
declare -a TIMECODES # Timestamps of the video captures |
declare -a HLTIMECODES # Timestamps of the highlights (see -l) |
|
declare VCSTEMPDIR= # Temporal directory, all temporal files |
# go there |
declare VCSTEMPDIR= # Temporary directory, all temporary files go there |
|
# Identification output from ffmpeg and mplayer for the current video |
declare FFMPEG_CACHE= |
declare MPLAYER_CACHE= |
275,8 → 276,6 |
# e.g.: for second 50 '-ss ' will become '-ss 50' while '' will stay empty |
# By default -ss goes before -i. |
declare wa_ss_af="" wa_ss_be="-ss " |
# This amount of time is *not* captured from the end of the video |
declare end_offset=$DEFAULT_END_OFFSET |
|
# Transformations/filters |
# Operations are decomposed into independent optional steps, this allows |
479,17 → 478,17 |
# TODO: Allow 'y', 'n' in booleans |
# TODO: Remove extra coherence_check()'s once constraints are implemented |
declare -ra OVERRIDE_MAP=( |
"user:::" |
"user:USERNAME::" |
"extended_factor:=:=:f" |
"stdout::" |
"stderr::" |
"STDOUT::" |
"STDERR::" |
"DEBUG:=:=:b" |
"interval:=:=:t" |
"numcaps:=:=:p" |
"captures:numcaps:alias:n" # Alias |
"INTERVAL:=:=:t" |
"NUMCAPS:=:=:p" |
"CAPTURES:NUMCAPS:alias:n" # Alias |
"GETOPT::" # Note it makes no sense as command-line override |
"columns:cols:=:p" |
"cols:=:alias:p" # Alias |
"COLUMNS:=:=:p" |
"COLS:COLUMNS:alias:p" # Traditional name |
|
"DISABLE_SHADOWS:=:=:b" |
"DISABLE_TIMESTAMPS:=:=:b" |
531,46 → 530,46 |
"pts_signature:pts_sign:alias" |
"pts_footer:pts_sign:alias" |
|
"signature:user_signature:" |
"user_signature::deprecated=signature" |
"SIGNATURE:=:" |
"USER_SIGNATURE:SIGNATURE:deprecated=SIGNATURE" |
|
"quality:output_quality:=:n" |
"output_quality::deprecated=quality:n" |
"QUALITY:=:=:n" |
"OUTPUT_QUALITY:QUALITY:deprecated=QUALITY:n" |
|
# TODO: These variables are evaluated to constants, would be better to |
# use some symbolic system (e.g. decoder=f instead of decoder=$DEC_FFMPEG) |
"decoder:=:=:D" |
#"capture_mode:timecode_from:alias:T" |
"timecode_from:=:=:T" |
"verbosity:=:=:V" |
#"capture_mode:TIMECODE_FROM:alias:T" |
"TIMECODE_FROM:=:=:T" |
"VERBOSITY:=:=:V" |
"preferred_capturer:=:=:x" |
"capturer:preferred_capturer:=:x" |
|
"format:output_format:" |
"output_format:=:deprecated=format" |
"FORMAT::" |
"OUTPUT_FORMAT:FORMAT:deprecated=FORMAT" |
|
"simple_feedback:plain_messages:=:b" |
"plain_messages::deprecated=simple_feedback:b" |
"SIMPLE_FEEDBACK:=:=:b" |
"PLAIN_MESSAGES:SIMPLE_FEEDBACK:deprecated=SIMPLE_FEEDBACK:b" |
|
"height:th_height:=:h" |
"th_height::deprecated=height:h" |
"HEIGHT:=:=:h" |
"TH_HEIGHT:HEIGHT:deprecated=HEIGHT:h" |
|
"padding:HPAD:=:n" |
"HPAD:=:deprecated=padding:n" |
"PADDING:=:=:n" |
"HPAD:PADDING:deprecated=PADDING:n" |
|
"nonlatin_font:FONT_MINCHO:" |
"FONT_MINCHO::deprecated=nonlatin_font" |
"NONLATIN_FONT::" |
"FONT_MINCHO:NONLATIN_FONT:deprecated=NONLATIN_FONT" |
"NONLATIN_FILENAMES:=:=:b" |
|
"end_offset:=:=:I" # New, used to have a two-variables assignment before USR_* |
"END_OFFSET:=:=:I" # New, used to have a two-variables assignment before USR_* |
|
# TODO TBA: |
#"noboldfeedback::" # Colour but not bold |
|
"shoehorned::gone" |
"safe_rename_pattern::gone" |
"MIN_LENGTH_FOR_END_OFFSET::gone:" |
"DEFAULT_END_OFFSET::gone:" |
"MIN_LENGTH_FOR_END_OFFSET::gone:" # Gone since 1.12 |
"SHOEHORNED::gone" # Gone since 1.13 |
"SAFE_RENAME_PATTERN::gone" # Gone since 1.13 |
"DEFAULT_END_OFFSET::gone:" # Gone since 1.13 |
) |
|
# Load a configuration file |
795,15 → 794,15 |
local ERE='^deprecated=' |
if [[ $flags =~ $ERE ]]; then |
local new=$(echo "$flags" | sed 's/^deprecated=//') |
buffered warn "Variable '$varname' will be removed in the future,$NL please use '$new' instead." |
buffered warn "Setting '$varname' will be removed in the future,$NL please use '$new' instead." |
else |
case "$flags" in |
gone) |
buffered error "Variable '$varname' has been removed." |
buffered error "Setting '$varname' has been removed." |
return 0 |
;; |
striked) |
buffered error "Variable '$varname' is scheduled to be removed in the next release." |
buffered error "Setting '$varname' is scheduled to be removed in the next release." |
buffered error " Please contact the author if you absolutely need it." |
;; |
meta) |
1194,7 → 1193,7 |
# aspect ratio |
# compute_width($1 = height) (=AR*height) (rounded) |
compute_width() { |
rmultiply $aspect_ratio,$1 |
rmultiply $ASPECT_RATIO,$1 |
} |
|
# Parse an interval and print the corresponding value in seconds |
1539,11 → 1538,11 |
# |
# error($1 = text) |
error() { |
if [[ $verbosity -ge $V_ERROR ]]; then |
[[ $plain_messages -eq 0 ]] && echo -n "$prefix_err" |
if [[ $VERBOSITY -ge $V_ERROR ]]; then |
[[ $SIMPLE_FEEDBACK -eq 0 ]] && echo -n "$prefix_err" |
# sgr0 is always used, this way if |
# a) something prints inbetween messages it isn't affected |
# b) if plain_messages is overridden colour stops after the override |
# b) if SIMPLE_FEEDBACK is overridden colour stops after the override |
echo "$1$suffix_fback" |
fi >&2 |
# It is important to redirect both tput and echo to stderr. Otherwise |
1553,8 → 1552,8 |
# Print a non-fatal error or warning |
# warning($1 = text) |
warn() { |
if [[ $verbosity -ge $V_WARN ]]; then |
[[ $plain_messages -eq 0 ]] && echo -n "$prefix_warn" |
if [[ $VERBOSITY -ge $V_WARN ]]; then |
[[ $SIMPLE_FEEDBACK -eq 0 ]] && echo -n "$prefix_warn" |
echo "$1$suffix_fback" |
fi >&2 |
} |
1562,8 → 1561,8 |
# Print an informational message |
# inf($1 = text) |
inf() { |
if [[ $verbosity -ge $V_INFO ]]; then |
[[ $plain_messages -eq 0 ]] && echo -n "$prefix_inf" |
if [[ $VERBOSITY -ge $V_INFO ]]; then |
[[ $SIMPLE_FEEDBACK -eq 0 ]] && echo -n "$prefix_inf" |
echo "$1$suffix_fback" |
fi >&2 |
} |
1572,7 → 1571,7 |
# Same as inf but with no colour ever. |
# infplain($1 = text) |
infplain() { |
if [[ $verbosity -ge $V_INFO ]]; then |
if [[ $VERBOSITY -ge $V_INFO ]]; then |
echo "$1" >&2 |
fi |
} |
1753,11 → 1752,11 |
# Note to self: Don't change the -vc as it would affect $vdec |
if [[ $DVD_MODE -eq 0 ]]; then |
MPLAYER_CACHE=$("$MPLAYER_BIN" -benchmark -ao null -vo null -identify -frames 0 \ |
-quiet "$f" 2>"$stderr" | grep ^ID) |
-quiet "$f" 2>"$STDERR" | grep ^ID) |
else |
MPLAYER_CACHE=$("$MPLAYER_BIN" -benchmark -ao null -vo null -identify -frames 0 \ |
-quiet -dvd-device "$f" dvd://$DVD_TITLE \ |
2>"$stderr" | grep ^ID) |
2>"$STDERR" | grep ^ID) |
fi |
# Note the head -1! |
mi[$VCODEC]=$(grep ID_VIDEO_FORMAT <<<"$MPLAYER_CACHE" | head -1 | cut -d'=' -f2) # FourCC |
1829,7 → 1828,7 |
|
assert '[[ $DVD_MODE -ne 1 ]]' |
"$MPLAYER_BIN" -sws 9 -ao null -benchmark -vo "png:z=0" -quiet \ |
-frames 5 -ss "$ts" $4 "$f" >"$stdout" 2>"$stderr" |
-frames 5 -ss "$ts" $4 "$f" >"$STDOUT" 2>"$STDERR" |
rm -f 0000000{1,2,3,4}.png # Remove the first four |
[[ ( -f $cap ) && ( '0' != "$(du "$cap" | cut -f1)" ) ]] && { |
[[ $cap = $o ]] || mvq "$cap" "$o" |
1852,7 → 1851,7 |
assert '[[ $DVD_MODE -eq 1 ]]' |
"$MPLAYER_BIN" -sws 9 -ao null -benchmark -vo "png:z=0" -quiet \ |
-frames 5 -ss "$ts" -dvd-device "$f" \ |
$4 "dvd://$DVD_TITLE" >"$stdout" 2>"$stderr" |
$4 "dvd://$DVD_TITLE" >"$STDOUT" 2>"$STDERR" |
rm -f 0000000{1,2,3,4}.png # Remove the first four |
[[ ( -f $cap ) && ( '0' != "$(du "$cap" | cut -f1)" ) ]] && { |
[[ $cap = $o ]] || mvq "$cap" "$o" |
2031,7 → 2030,7 |
# See wa_ss_* declarations at the start of the file for details |
"$FFMPEG_BIN" -y ${wa_ss_be/ / $ts} -i "$f" ${wa_ss_af/ / $ts} -an \ |
-dframes 1 -vframes 1 -vcodec png \ |
-f rawvideo $4 "$o" >"$stdout" 2>"$stderr" |
-f rawvideo $4 "$o" >"$STDOUT" 2>"$STDERR" |
[[ ( -f $o ) && ( '0' != "$(du "$o" | cut -f1)" ) ]] |
} |
|
2169,25 → 2168,25 |
local st=0 end=${VID[$LEN]} tcfrom=$1 tcint=$2 tcnumcaps=$3 eo=0 |
local eff_eo= # Effective end_offset (for percentages) |
|
# globals: fromtime, totime, timecode_from, TIMECODES, end_offset |
if fptest $st -lt $fromtime ; then |
st=$fromtime |
# globals: $FROMTIME, $TOTIME, $TIMECODE_FROM, $TIMECODES, $END_OFFSET |
if fptest $st -lt $FROMTIME ; then |
st=$FROMTIME |
fi |
if fptest $totime -gt 0 && fptest $end -gt $totime ; then |
end=$totime |
if fptest $TOTIME -gt 0 && fptest $end -gt $TOTIME ; then |
end=$TOTIME |
fi |
if is_percentage $end_offset ; then |
eff_eo=$(percent $end $end_offset) |
if is_percentage $END_OFFSET ; then |
eff_eo=$(percent $end $END_OFFSET) |
else |
eff_eo=$(get_interval "$end_offset") |
eff_eo=$(get_interval "$END_OFFSET") |
fi |
if fptest $totime -le 0 ; then # If no totime is set, use end_offset |
if fptest $TOTIME -le 0 ; then # If no totime is set, use END_OFFSET |
eo=$eff_eo |
|
local runlen=$(awkexf "$end - $st") |
|
if fptest "($end-$eo-$st)" -le 0 ; then |
if fptest "$eo" -gt 0 && [[ -z $USR_end_offset ]] ; then |
if fptest "$eo" -gt 0 && [[ -z $USR_END_OFFSET ]] ; then |
warn "Default end offset was too high for the video, ignoring it." |
eo=0 |
else |
2590,8 → 2589,8 |
vpad=0 |
splice=5x10 |
else |
hpad=$HPAD |
vpad=$HPAD |
hpad=$PADDING |
vpad=$PADDING |
splice=0x8 |
fi |
|
3260,9 → 3259,9 |
shopt -s nocasematch |
local ERE='sazanami' |
if [[ $candidates =~ $ERE ]]; then |
FONT_MINCHO=$(grep -i 'sazanami' <<<"$candidates" | head -1) |
NONLATIN_FONT=$(grep -i 'sazanami' <<<"$candidates" | head -1) |
else |
FONT_MINCHO=$(head -1 <<<"$candidates") |
NONLATIN_FONT=$(head -1 <<<"$candidates") |
fi |
shopt -u nocasematch |
} |
3273,7 → 3272,7 |
coherence_check() { |
trace $@ |
# If -m is used then -S must be used |
if [[ ( $manual_mode -eq 1 ) && ( -z $initial_stamps ) ]]; then |
if [[ ( $MANUAL_MODE -eq 1 ) && ( -z $INITIAL_STAMPS ) ]]; then |
error "You must provide timestamps (-S) when using manual mode (-m)" |
return $EX_USAGE |
fi |
3336,16 → 3335,16 |
FILTERS_IND=( "${filts[@]}" "${end_filts[@]}" ) |
|
# Interval=0 == default interval |
fptest "$interval" -eq 0 && interval=$DEFAULT_INTERVAL |
fptest "$INTERVAL" -eq 0 && interval=$DEFAULT_INTERVAL |
|
# If in non-latin mode and no nonlatin font has been picked try to pick one. |
# Should it fail, fallback to latin font. |
if [[ ( $NONLATIN_FILENAMES -eq 1 ) && ( -z $FONT_MINCHO ) ]]; then |
if [[ ( $NONLATIN_FILENAMES -eq 1 ) && ( -z $NONLATIN_FONT ) ]]; then |
set_extended_font || { |
# set_extended_font already warns about lack of fonts |
warn " Falling back to latin font" |
NONLATIN_FILENAMES=0 |
FONT_MINCHO="$font_heading" |
NONLATIN_FONT="$font_heading" |
} |
fi |
|
3404,8 → 3403,8 |
# Save variables that will be overwritten and must be reset with multiple files |
# pre_* will contain the user-supplied or default values |
local pre_quirks=$QUIRKS |
local pre_aspect_ratio=$aspect_ratio |
local pre_output_format="$output_format" |
local pre_aspect_ratio=$ASPECT_RATIO |
local pre_format="$FORMAT" |
INTERNAL_MAXREWIND_REACHED=0 # Reset for each file |
CAPTURES='' |
FILMSTRIP='' # Reset |
3482,10 → 3481,10 |
[[ $UNDFLAG_IDONLY ]] && dump_idinfo && return 0 |
|
# Vidcap/Thumbnail height |
local vidcap_height=$th_height |
if is_percentage "$th_height" && [[ $th_height != '100%' ]]; then |
vidcap_height=$(rpercent ${VID[$H]} ${th_height}) |
inf "Height: $th_height of ${VID[$H]} = $vidcap_height" |
local vidcap_height=$HEIGHT |
if is_percentage "$HEIGHT" && [[ $HEIGHT != '100%' ]]; then |
vidcap_height=$(rpercent ${VID[$H]} ${HEIGHT}) |
inf "Height: $HEIGHT of ${VID[$H]} = $vidcap_height" |
fi |
if ! is_number "$vidcap_height" || [[ $vidcap_height -eq 0 ]]; then |
vidcap_height=${VID[$H]} |
3492,33 → 3491,33 |
fi |
# -2: DVD Mode autodetection => If ffmpeg/mplayer was unable autodetect, otherwise |
#+ honor detected value |
if [[ $aspect_ratio -eq -2 ]]; then |
[[ ${VID[$ASPECT]} ]] && aspect_ratio=0 || aspect_ratio=-1 |
elif [[ $aspect_ratio -eq 0 ]]; then |
if [[ $ASPECT_RATIO -eq -2 ]]; then |
[[ ${VID[$ASPECT]} ]] && ASPECT_RATIO=0 || ASPECT_RATIO=-1 |
elif [[ $ASPECT_RATIO -eq 0 ]]; then |
if [[ ${VID[$ASPECT]} ]]; then |
# Aspect ratio in file headers, honor it |
aspect_ratio=$(awkexf "${VID[$ASPECT]}") |
ASPECT_RATIO=$(awkexf "${VID[$ASPECT]}") |
else |
aspect_ratio=$(awkexf "${VID[$W]} / ${VID[$H]}") |
ASPECT_RATIO=$(awkexf "${VID[$W]} / ${VID[$H]}") |
fi |
elif [[ $aspect_ratio -eq -1 ]]; then |
aspect_ratio=$(guess_aspect ${VID[$W]} ${VID[$H]}) |
inf "Aspect ratio set to $aspect_ratio." |
elif [[ $ASPECT_RATIO -eq -1 ]]; then |
ASPECT_RATIO=$(guess_aspect ${VID[$W]} ${VID[$H]}) |
inf "Aspect ratio set to $ASPECT_RATIO." |
fi |
local vidcap_width=$(compute_width $vidcap_height) |
|
local nc=$numcaps |
local nc=$NUMCAPS |
|
unset TIMECODES |
# Compute the stamps (if in auto mode)... |
if [[ $manual_mode -eq 1 ]]; then |
if [[ $MANUAL_MODE -eq 1 ]]; then |
# Note TIMECODES must be set as an array to get the correct count in |
# manual mode; in automatic mode it will be set correctly inside |
# compute_timecodes() |
TIMECODES=( "${initial_stamps[@]}" ) |
TIMECODES=( "${INITIAL_STAMPS[@]}" ) |
else |
TIMECODES=( "${initial_stamps[@]}" ) |
compute_timecodes $timecode_from $interval $numcaps || { |
TIMECODES=( "${INITIAL_STAMPS[@]}" ) |
compute_timecodes $TIMECODE_FROM $INTERVAL $NUMCAPS || { |
return $? |
} |
fi |
3565,10 → 3564,10 |
|
assert "[[ '"$n"' -gt 1 ]]" |
(( n-- )) # There's an extra inc |
if [[ $n -lt $cols ]]; then |
if [[ $n -lt $COLUMNS ]]; then |
numcols=$n |
else |
numcols=$cols |
numcols=$COLUMNS |
fi |
|
inf "Composing highlights contact sheet..." |
3600,10 → 3599,10 |
|
assert "[[ '"$n"' -gt 1 ]]" |
(( n-- )) # there's an extra inc |
if [[ $n -lt $cols ]]; then |
if [[ $n -lt $COLUMNS ]]; then |
numcols=$n |
else |
numcols=$cols |
numcols=$COLUMNS |
fi |
|
inf "Composing standard contact sheet..." |
3626,7 → 3625,7 |
local n=1 w= h= capfile= pretty= |
unset capfiles ; local -a capfiles |
# The image size of the extra captures is 1/4, adjusted to compensante the padding |
(( w=vidcap_width/2-HPAD, h=vidcap_height*w/vidcap_width ,1 )) |
(( w=vidcap_width/2-PADDING, h=vidcap_height*w/vidcap_width ,1 )) |
assert "[[ ( '"$w"' -gt 0 ) && ( '"$h"' -gt 0 ) ]]" |
for stamp in $(clean_timestamps "${TIMECODES[*]}"); do |
pretty=$(pretty_stamp $stamp) |
3640,10 → 3639,10 |
done |
|
(( n-- )) # There's an extra inc |
if [[ $n -lt 'cols*2' ]]; then |
if [[ $n -lt 'COLUMNS*2' ]]; then |
numcols=$n |
else |
numcols=$(( $cols * 2 )) |
numcols=$(( $COLUMNS * 2 )) |
fi |
|
inf "Composing extended contact sheet..." |
3730,7 → 3729,7 |
meta2="$meta2${NL}Format: $vcodec / $acodec${NL}FPS: ${VID[$FPS]}" |
local signature |
if [[ $anonymous_mode -eq 0 ]]; then |
signature="$user_signature $user${NL}with $PROGRAM_SIGNATURE" |
signature="$SIGNATURE $USERNAME${NL}with $PROGRAM_SIGNATURE" |
else |
signature="Created with $PROGRAM_SIGNATURE" |
fi |
3737,7 → 3736,7 |
local headwidth=$(imw "$output") headheight= |
local heading=$(new_temp_file .png) |
# Add the title if any |
if [[ $title ]]; then |
if [[ $TITLE ]]; then |
local tlheight=$(line_height "$font_title" "$pts_title") |
convert \ |
\( \ |
3744,7 → 3743,7 |
-size ${headwidth}x$tlheight "xc:$bg_title" \ |
-font "$font_title" -pointsize "$pts_title" \ |
-background "$bg_title" -fill "$fg_title" \ |
-gravity Center -annotate 0 "$title" \ |
-gravity Center -annotate 0 "$TITLE" \ |
\) \ |
-flatten \ |
"$output" -append "$output" |
3754,7 → 3753,7 |
if [[ $NONLATIN_FILENAMES -ne 1 ]]; then |
fn_font="$font_heading" |
else |
fn_font="$FONT_MINCHO" |
fn_font="$NONLATIN_FONT" |
fi |
# Create a small image to see how tall are characters. In my tests, no matter |
#+which character is used it's always the same height. |
3855,17 → 3854,17 |
if [[ -n $wanted_name ]]; then |
local ERE='\.[^.]+$' |
if [[ $wanted_name =~ $ERE ]]; then |
output_format=$(filext "$wanted_name") |
FORMAT=$(filext "$wanted_name") |
inf "Output format set from output filename" |
else # No file extension in wanted_name |
wanted_name="$wanted_name.$output_format" |
wanted_name="$wanted_name.$FORMAT" |
fi |
fi |
[[ -n $wanted_name ]] || wanted_name="$(basename "$f").$output_format" |
[[ -n $wanted_name ]] || wanted_name="$(basename "$f").$FORMAT" |
|
if [[ $output_format != 'png' ]]; then |
local newout="$(dirname "$output")/$(basename "$output" .png).$output_format" |
convert -quality $output_quality "$output" "$newout" |
if [[ $FORMAT != 'png' ]]; then |
local newout="$(dirname "$output")/$(basename "$output" .png).$FORMAT" |
convert -quality $QUALITY "$output" "$newout" |
output="$newout" |
fi |
|
3889,8 → 3888,8 |
|
# Re-set variables (for multi-file input) |
QUIRKS=$pre_quirks |
aspect_ratio=$pre_aspect_ratio |
output_format="$pre_output_format" |
ASPECT_RATIO=$pre_aspect_ratio |
FORMAT="$pre_format" |
} |
|
# }}} # Core functionality |
4253,7 → 4252,7 |
eval v=\$USR_$t |
[[ -z $v ]] || { |
# Symbolic values: |
case "$t" in |
case $( tolower "$t" ) in |
timecode_from) |
x='$TC_NUMCAPS' |
[[ $v -eq $TC_NUMCAPS ]] || x='$TC_INTERVAL' |
4274,6 → 4273,12 |
esac # verbosity |
;; |
esac |
[[ -z $v ]] || { |
# Don't print unnecessary decimals |
if [[ $v =~ ^[0-9][0-9]*\.[0-9][0-9]*$ ]]; then |
v=$(sed -e 's/0*$//' -e 's/\.$//' <<<"$v") |
fi |
} |
# Print all names in lowercase |
echo "$(tolower "$f")=$v" |
} |
4328,18 → 4333,18 |
case "$1" in |
-i|--interval) |
check_constraint 'interval' "$2" "$1" || die |
interval=$(get_interval $2) |
timecode_from=$TC_INTERVAL |
USR_interval=$interval |
USR_timecode_from=$TC_INTERVAL |
INTERVAL=$(get_interval $2) |
TIMECODE_FROM=$TC_INTERVAL |
USR_INTERVAL=$INTERVAL |
USR_TIMECODE_FROM=$TC_INTERVAL |
shift # Option arg |
;; |
-n|--numcaps) |
check_constraint 'numcaps' "$2" "$1" || die |
numcaps=$2 |
timecode_from=$TC_NUMCAPS |
USR_numcaps=$2 |
USR_timecode_from=$TC_NUMCAPS |
NUMCAPS=$2 |
TIMECODE_FROM=$TC_NUMCAPS |
USR_NUMCAPS=$2 |
USR_TIMECODE_FROM=$TC_NUMCAPS |
shift # Option arg |
;; |
-o|--output) |
4346,7 → 4351,7 |
current=${#OUTPUT_FILES[@]} |
OUTPUT_FILES[$current]="$2" |
shift ;; |
-u|--username) user="$2" ; USR_user="$user" ; shift ;; |
-u|--username) USERNAME="$2" ; USR_USERNAME="$USERNAME" ; shift ;; |
-U|--fullname) |
# -U accepts an optional argument, 0, to make an anonymous signature |
# --fullname accepts no argument |
4361,55 → 4366,56 |
fi |
shift |
else # No argument, default handling (try to guess real name) |
username=$(id -un) |
idname=$(id -un) |
if type -p getent >/dev/null ; then |
user=$(getent passwd "$username" | cut -d':' -f5 |sed 's/,.*//g') |
USERNAME=$(getent passwd "$idname" | cut -d':' -f5 |sed 's/,.*//g') |
else |
user=$(grep "^$username:" /etc/passwd | cut -d':' -f5 |sed 's/,.*//g') |
USERNAME=$(grep "^$idname:" /etc/passwd | cut -d':' -f5 |sed 's/,.*//g') |
fi |
if [[ -z $user ]]; then |
user=$username |
error "No fullname found, falling back to default ($user)" |
USERNAME=$idname |
error "No fullname found, falling back to default ($USERNAME)" |
fi |
unset idname |
fi |
;; |
--anonymous) anonymous_mode=1 ;; # Same as -U0 |
-T|--title) title="$2" ; USR_title="$2" ; shift ;; |
-T|--title) TITLE="$2" ; USR_TITLE="$2" ; shift ;; |
-f|--from) |
if ! fromtime=$(get_interval "$2") ; then |
if ! FROMTIME=$(get_interval "$2") ; then |
error "Starting timestamp must be a valid timecode. Got '$2'." |
exit $EX_USAGE |
fi |
USR_fromtime="$fromtime" |
USR_FROMTIME="$FROMTIME" |
shift |
;; |
-E|--end_offset|--end-offset) |
if [[ $1 == '--end_offset' ]]; then |
warn "Option --end_offset is deprecated and will be removed, please use" |
warn " --end-offset instead" |
warn "Option --end_offset is deprecated and will be removed in the" |
warn " next version, please use --end-offset instead" |
fi |
check_constraint 'end_offset' "$2" "$1" || die |
is_p='y' |
is_percentage "$2" || is_p='' |
if [[ $is_p ]]; then |
end_offset="$2" |
END_OFFSET="$2" |
else |
end_offset=$(get_interval "$2") |
END_OFFSET=$(get_interval "$2") |
fi |
USR_end_offset="$end_offset" |
USR_END_OFFSET="$END_OFFSET" |
unset is_i |
shift |
;; |
-t|--to) |
if ! totime=$(get_interval "$2") ; then |
if ! TOTIME=$(get_interval "$2") ; then |
error "Ending timestamp must be a valid timecode. Got '$2'." |
exit $EX_USAGE |
fi |
if fptest "$totime" -eq 0 ; then |
if fptest "$TOTIME" -eq 0 ; then |
error "Ending timestamp was set to 0, set to movie length." |
totime=-1 |
fi |
USR_totime=$totime |
USR_TOTIME=$TOTIME |
shift |
;; |
-S|--stamp) |
4417,7 → 4423,7 |
error "Timestamps must be a valid timecode. Got '$2'." |
exit $EX_USAGE |
fi |
initial_stamps=( "${initial_stamps[@]}" "$temp" ) |
INITIAL_STAMPS=( "${INITIAL_STAMPS[@]}" "$temp" ) |
shift |
;; |
-l|--highlight) |
4429,8 → 4435,8 |
shift |
;; |
--jpeg2) # Note --jpeg 2 is also accepted |
output_format=jp2 |
USR_output_format=jp2 |
FORMAT=jp2 |
USR_FORMAT=jp2 |
;; |
-j|--jpeg) |
if [[ $2 ]]; then # Arg is optional, 2 is for JPEG 2000 |
4439,11 → 4445,11 |
error "Use -j for jpeg output or -j2 for JPEG 2000 output. Got '-j$2'." |
exit $EX_USAGE |
fi |
output_format=jp2 |
FORMAT=jp2 |
else |
output_format=jpg |
FORMAT=jpg |
fi |
USR_output_format="$output_format" |
USR_FORMAT="$FORMAT" |
shift |
;; |
-h|--help) show_help ; exit $EX_OK ;; |
4454,8 → 4460,8 |
preferred_capturer=mplayer ; USR_preferred_capturer=mplayer ;; |
-H|--height) |
check_constraint 'height' "$2" "$1" || die |
th_height="$2" |
USR_th_height="$2" |
HEIGHT="$2" |
USR_HEIGHT="$2" |
shift |
;; |
-a|--aspect) |
4464,18 → 4470,18 |
error " point number or a fraction (ie: 1, 1.33, 4/3, 2.5). Got '$2'." |
exit $EX_USAGE |
fi |
aspect_ratio="$2" |
USR_aspect_ratio="$2" |
ASPECT_RATIO="$2" |
USR_ASPECT_RATIO="$2" |
shift |
;; |
-A|--autoaspect) aspect_ratio=-1 ; USR_aspect_ratio=-1 ;; |
-A|--autoaspect) ASPECT_RATIO=-1 ; USR_ASPECT_RATIO=-1 ;; |
-c|--columns) |
check_constraint 'columns' "$2" "$1" || die |
cols="$2" |
USR_cols="$2" |
COLUMNS="$2" |
USR_COLUMNS="$2" |
shift |
;; |
-m|--manual) manual_mode=1 ;; |
-m|--manual) MANUAL_MODE=1 ;; |
-e|--extended) |
# Optional argument quirks: $2 is always present, set to '' if unused |
# from the commandline it MUST be directly after the -e (-e2 not -e 2) |
4491,11 → 4497,11 |
;; |
# Unlike -I, --nonlatin does not accept a font name |
--nonlatin) |
if [[ -z $USR_FONT_MINCHO ]]; then |
if [[ -z $USR_NONLATIN_FONT ]]; then |
NONLATIN_FILENAMES=1 |
USR_NONLATIN_FILENAMES=1 |
set_extended_font |
inf "Filename font set to '$FONT_MINCHO'" |
inf "Filename font set to '$NONLATIN_FONT'" |
fi |
;; |
-I) |
4517,14 → 4523,14 |
USR_NONLATIN_FILENAMES=1 |
if [[ ${#2} -gt 1 ]]; then |
# j=, k= syntax |
FONT_MINCHO="${2:2}" |
USR_FONT_MINCHO="$FONT_MINCHO" |
inf "Filename font set to '$FONT_MINCHO'" |
NONLATIN_FONT="${2:2}" |
USR_NONLATIN_FONT="$NONLATIN_FONT" |
inf "Filename font set to '$NONLATIN_FONT'" |
fi |
# If the user didn't pick one, try to select automatically |
if [[ -z $USR_FONT_MINCHO ]]; then |
if [[ -z $USR_NONLATIN_FONT ]]; then |
set_extended_font |
inf "Filename font set to '$FONT_MINCHO'" |
inf "Filename font set to '$NONLATIN_FONT'" |
fi |
shift |
;; |
4555,7 → 4561,7 |
# Twice: Disable prefixes too |
c) |
set_feedback_prefixes |
[[ -n $UNDFLAG_NOPREFIX ]] && plain_messages=1 |
[[ -n $UNDFLAG_NOPREFIX ]] && SIMPLE_FEEDBACK=1 |
UNDFLAG_NOPREFIX=1 |
;; |
# Double length of video probed in safe measuring |
4717,9 → 4723,9 |
fi |
;; |
p|padding) |
if [[ $HPAD -ne 0 ]] ; then |
if [[ $PADDING -ne 0 ]] ; then |
inf "Padding disabled." # Kinda... |
HPAD=0 |
PADDING=0 |
fi |
;; |
*) |
4747,17 → 4753,17 |
fi |
DVD_MODE=1 |
decoder=$DEC_MPLAYER |
aspect_ratio=-2 # Special value: Auto detect only if ffmpeg couldn't |
ASPECT_RATIO=-2 # Special value: Auto detect only if ffmpeg couldn't |
;; |
-q|--quiet) |
# -q to only show errors |
# -qq to be completely quiet |
if [[ $verbosity -gt $V_ERROR ]]; then |
verbosity=$V_ERROR |
if [[ $VERBOSITY -gt $V_ERROR ]]; then |
VERBOSITY=$V_ERROR |
else |
verbosity=$V_NONE |
VERBOSITY=$V_NONE |
fi |
USR_verbosity=$verbosity |
USR_VERBOSITY=$VERBOSITY |
;; |
-Z|--undocumented) |
# This is a container for, of course, undocumented functions |
4872,7 → 4878,7 |
internal_integrity_test && warn "All tests passed" || error "Some tests failed!" |
DEBUGGED=1 |
warn "Command line: $0 $ARGS" |
title="$(basename "$0") $ARGS" |
TITLE="$(basename "$0") $ARGS" |
;; |
--) shift ; break ;; |
*) error "Internal error! (remaining opts: $*)" ; exit $EX_SOFTWARE ; |
4883,7 → 4889,7 |
# Avoid coherence_check if there's no arguments and no cmdline post |
# processing |
[[ -n $1 || -n $POST_GETOPT_HOOKS ]] || { |
[[ $verbosity -eq $V_NONE ]] || show_help |
[[ $VERBOSITY -eq $V_NONE ]] || show_help |
exit $EX_USAGE |
} |
|
4906,7 → 4912,7 |
|
# Remaining arguments |
if [[ -z $1 ]]; then |
[[ $verbosity -eq $V_NONE ]] || show_help |
[[ $VERBOSITY -eq $V_NONE ]] || show_help |
exit $EX_USAGE |
fi |
|