Subversion Repositories pub

Compare Revisions

Ignore whitespace Rev 340 → Rev 339

/video-contact-sheet/branches/1.0.11/vcs
46,19 → 46,13
# {{{ # CHANGELOG
# History (The full changelog can be found at <http://p.outlyer.net/vcs/files/CHANGELOG>).
#
# 1.0.11:
# * BUGFIX: (brown bag bug) Corrected typo in variable name that made vcs
# fail when setting the default timecode derivation to number of
# captures instead of interval (i.e. when including timecode_from=8 in
# the config file) (thanks to Chris Hills for the bug report)
# * RETROCOMPATIBILITY: Older bash syntax for appending and initialising
# arrays (contributed by Phil Grundig)
# * COMPATIBILITY: Support alternative du syntax for compatibility with
# busybox (based on Phil Grundig's contribution)
# * COSMETIC: Don't print milliseconds when using mplayer as capturer
# (they're not really meaningful then) (suggested by Phil Grundig)
# * DEBUGGING: Added optional function call trace (by setting variable DEBUG
# to 1)
# 1.0.11: (?) the Grundig release :)
# * RETROCOMPATIBILITY: Older bash syntax for appending and initialising arrays
# (contributed by Phil Grundig)
# * COMPATIBILITY: Support alternative du syntax for compatibility with busybox
# (based on Phil Grundig's contribution)
# * COSMETIC: Don't print milliseconds when using mplayer as capturer (they're not
# really meaningful then) (suggested by Phil Grundig)
# }}} # CHANGELOG
 
set -e
121,8 → 115,6
 
# {{{ # Override-able variables
 
# Set to 1 to print function calls
declare -i DEBUG=0
declare -i DEFAULT_INTERVAL=300
declare -i DEFAULT_NUMCAPS=16
declare -i DEFAULT_COLS=2
352,7 → 344,7
# Override-able hack, this won't work with command line overrides, though
end_offset=$DEFAULT_END_OFFSET
interval=$DEFAULT_INTERVAL
numcaps=$DEFAULT_NUMCAPS
numcaps=$DEAFULT_NUMCAPS
}
 
# Do an override
750,18 → 742,6
fi
}
 
#
# trace($1 = function name = $FUNCNAME, function arguments...)
if [ "$DEBUG" -eq "1" ]; then
trace() {
echo "[TRACE]: $@" >&2
}
else
trace() {
return
}
fi
 
# }}} # Convenience functions
 
# {{{ # Core functionality
769,7 → 749,6
# Creates a new temporary directory
# create_temp_dir()
create_temp_dir() {
trace $FUNCNAME $@
# Try to use /dev/shm if available, this provided a very small
# benefit on my system but me of help for huge files. Or maybe won't.
if [ -d /dev/shm ] && [ -w /dev/shm ]; then
787,7 → 766,6
# Create a new temporal file and print its filename
# new_temp_file($1 = suffix)
new_temp_file() {
trace $FUNCNAME $@
local r=$(mktemp -p "$VCSTEMPDIR" "vcs-XXXXXX")
if [ ! -f "$r" ]; then
error "Failed to create temporary file"
806,7 → 784,7
# or colour combination you like.
# randomize_look()
randomize_look() {
trace $FUNCNAME $@
 
local mode=f lineno
 
if [ "f" == $mode ]; then # Random mode
868,8 → 846,6
# from the current video
# compute_timecodes($1 = timecode_from, $2 = interval, $3 = numcaps)
compute_timecodes() {
trace $FUNCNAME $@
 
local st=0 end=${VID[$LEN]} tcfrom=$1 tcint=$2 tcnumcaps=$3 eo=0
# globals: fromtime, totime, timecode_from, TIMECODES, end_offset
if fptest $st -lt $fromtime ; then
935,7 → 911,6
# known values (e.g. VCD resolution turns into 4/3)
# guess_aspect($1 = width, $2 = height)
guess_aspect() {
trace $FUNCNAME $@
# mplayer's ID_ASPECT seems to be always 0 ¿?
local w=$1 h=$2 ar
 
982,7 → 957,6
# Capture a frame
# capture($1 = filename, $2 = second)
capture() {
trace $FUNCNAME $@
local f=$1 stamp=$2
local VIDCAPFILE=00000001.png
# globals: $shoehorned $decoder
1021,7 → 995,6
# Applies all individual vidcap filters
# filter_vidcap($1 = filename, $2 = timestamp, $3 = width, $4 = height)
filter_vidcap() {
trace $FUNCNAME $@
# For performance purposes each filter simply prints a set of options
# to 'convert'. That's less flexible but enough right now for the current
# filters.
1042,7 → 1015,6
#}
 
filt_resize() {
trace $FUNCNAME $@
local f="$1" t=$2 w=$3 h=$4
 
# Note the '!', required to change the aspect ratio
1052,7 → 1024,6
# Draw a timestamp in the file
# filt_apply_stamp($1 = filename, $2 = timestamp, $3 = width, $4 = height)
filt_apply_stamp() {
trace $FUNCNAME $@
local filename=$1 timestamp=$2 width=$3 height=$4
 
echo -n " \( -box '#000000aa' -fill '$fg_tstamps' -pointsize '$pts_tstamps' "
1064,7 → 1035,6
# Taken from <http://www.imagemagick.org/Usage/thumbnails/#polaroid>
# filt_photoframe($1 = filename, $2 = timestamp, $3 = width, $4 = height)
filt_photoframe() {
trace $FUNCNAME $@
# local file="$1" ts=$2 w=$3 h=$4
# Tweaking the size gives a nice effect too
# w=$(( $w - ( $RANDOM % ( $w / 3 ) ) ))
1078,7 → 1048,6
# Taken from <http://www.imagemagick.org/Usage/thumbnails/#polaroid>
# filt_randrot($1 = filename, $2 = timestamp, $3 = width, $4 = height)
filt_randrot() {
trace $FUNCNAME $@
# Rotation angle [-18..18]
local angle=$(( ($RANDOM % 37) - 18 ))
echo "-background none -rotate $angle "
1087,7 → 1056,6
# This one requires much more work, the results are pretty rough, but ok as
# a starting point / proof of concept
filt_film() {
trace $FUNCNAME $@
local file="$1" ts=$2 w=$3 h=$4
# Base reel dimensions
local rw=$(rmultiply $w,0.08) # 8% width
1129,7 → 1097,6
# create_contact_sheet($1 = columns, $2 = context, $3 = width, $4 = height,
# $5...$# = vidcaps) : output
create_contact_sheet() {
trace $FUNCNAME $@
$CSHEET_DELEGATE "$@"
}
 
1137,7 → 1104,6
# csheet_montage($1 = columns, $2 = context, $3 = width, $4 = height,
# $5... = vidcaps) : output
csheet_montage() {
trace $FUNCNAME $@
local cols=$1 ctx=$2 width=$3 height=$4 output=$(new_temp_file .png)
shift 4
case $ctx in
1164,7 → 1130,6
# csheet_overlap($1 = columns, $2 = context, $3 = width, $4 = height,
# $5... = $vidcaps) : output
csheet_overlap() {
trace $FUNCNAME $@
local cols=$1 ctx=$2 width=$3 height=$4
# globals: $VID
shift 4
1271,7 → 1236,6
# Sorts timestamps and removes duplicates
# clean_timestamps($1 = space separated timestamps)
clean_timestamps() {
trace $FUNCNAME $@
# Note AFAIK sort only sorts lines, that's why y replace spaces by newlines
local s=$1
sed 's/ /\n/g'<<<"$s" | sort -n | uniq
1280,7 → 1244,6
# Fills the $MPLAYER_CACHE and $VID variables with the video data
# identify_video($1 = file)
identify_video() {
trace $FUNCNAME $@
local f=$1
# Meta data extraction
# Note to self: Don't change the -vc as it would affect $vdec
1316,7 → 1279,6
# Creates the contact sheet.
# process($1 = file)
process() {
trace $FUNCNAME $@
local f=$1
 
local numcols=
1447,7 → 1409,7
local hlnc=$(rtomult "$(( ${#TIMECODES[@]} * $extended_factor ))" $((2*$numcols)))
 
unset TIMECODES # required step to get the right count
declare -a TIMECODES # Note the manual stamps are not included anymore
declare -a TIMECODES # Note the manual stamps aren't included anymore
compute_timecodes $TC_NUMCAPS "" $hlnc
unset hlnc