[tovid] r3413 committed - * More work on decreasing verbosity of screen output...

5 views
Skip to first unread message

to...@googlecode.com

unread,
Mar 4, 2012, 1:31:38 AM3/4/12
to tovi...@googlegroups.com
Revision: 3413
Author: grepper
Date: Sat Mar 3 22:31:02 2012
Log: * More work on decreasing verbosity of screen output
using print2log, reworking get_stats, etc.
* Use full option names for some like:
-menu-title-font
* Use coloured messages for more output.
* Remove VERBOSE var which was unused.
* Get tovid.ini opts for makempg:
TODO: echo them to screen for information to user
* Don't use coloured output with gui to fix errors re tput
* Don't run filter test when recursing if already run.
* Fix Usage message to use 'tovid disc' instead of 'todisc'
* Fix a few thumb dimensions to allow better fit
* Fix typo in 'tovid dvd' burn command


http://code.google.com/p/tovid/source/detail?r=3413

Modified:
/trunk/tovid/src/todisc

=======================================
--- /trunk/tovid/src/todisc Wed Sep 21 19:17:58 2011
+++ /trunk/tovid/src/todisc Sat Mar 3 22:31:02 2012
@@ -39,18 +39,22 @@
# grepper on irc.freenode.net

SCRIPT_NAME=`cat << EOF
+
--------------------------------
tovid disc
-Generate a DVD filesystem with animated thumbnail menus
+Generate a DVD file-system with optional menus, from a list of multimedia
files.
+Menus can be moving or static thumbnails, or text. Encoding done
automatically.
+
Version $TOVID_VERSION
$TOVID_HOME_PAGE
--------------------------------
+
EOF`

USAGE=`cat << EOF
Usage:

- todisc [OPTIONS] \\\\
+ tovid disc [OPTIONS] \\\\
-files File1.mpg File2.mpg ... \\\\
-titles "Title 1" "Title 2" ... \\\\
-out OUT_PREFIX
@@ -152,7 +156,7 @@
ALIGN_OVERRIDE=false
MULTILINE_TITLE=false
SAFE_AREA=50 # undocumented: you can set this from CLI with
-showcase-safe-area
-SAFE_OFFSET=36
+SAFE_OFFSET=0 # we only add this offset if center title align, to keep
onscreen
ASPECT_RATIO=4:3
AR=1.333
ASPECT_ARG=all
@@ -164,7 +168,6 @@
XGEO=0
YGEO=45
USER_GRAVITY=false
-USER_GEO=false
USER_SPLIT=false
TITLE_GRAVITY=south
SPACER=15
@@ -262,20 +265,27 @@
AUDIO_EXT="ac3"
SAMPLERATE="48000"
MPLEX_FORMAT="8"
+FROM_GUI=false # needed to disable tput (colour output) in GUI
TOVID_PREFIX=$(tovid -prefix)


##############################################################################
#
Functions #

##############################################################################

-# Y-echo: echo to two places at once (stdout and logfile)
+# Y-echo: print to two places at once (stdout and logfile)
# Output is preceded by the script name that produced it
# Args: $@ == any text string
-# If no args are given, echo a separator bar
+# If no args are given, print a separator bar
+# If empty string is the arg, print a newline
# Use yecho if you want output to go to the logfile
yecho()
{
- if test $# -eq 0; then
+ # arg supplied but empty (""): just print a newline
+ if [[ "${1+defined}" && -z $1 ]]; then
+ printf "\n"
+ [[ -e "$LOG_FILE" ]] && printf "\n" >> "$LOG_FILE"
+ # no arg supplied at all, just 'yecho': print \n[todisc]:\n
+ elif test $# -eq 0; then
printf "\n%s\n\n" "$SEPARATOR"
# If logfile exists, copy output to it (with pretty formatting)
test -e "$LOG_FILE" && \
@@ -287,14 +297,6 @@
fold -bs >> "$LOG_FILE"
fi
}
-#
******************************************************************************
-# Execute the given command-line string, with appropriate stream
redirection
-# Args: $@ == text string containing complete command-line
-# Returns: Exit status of the subprocess
-# To filter/prettify the subprocess output before writing it to the log
file,
-# set the LOG_FILTER variable before calling this function, to e.g.
-# LOG_FILTER="sed 's/\r/\r\n/g'" # Replace LF with CR/LF
-#
******************************************************************************

# Print script name, usage notes, and optional error message, then exit.
# Args: $@ == text string(s) containing error message and help
@@ -311,38 +313,94 @@
exit 1
}

-printred()
-{
- tput setaf 1
- printf "%s\n" "$@" | sed "s/ */ /g;s/^ *//" | tee -a "$LOG_FILE"
- tput sgr0
- printf ""
+# Usage: continue_in [SECONDS]
+continue_in()
+{
+ yecho ""
+ (($1)) && LAST=$1 || LAST=5
+ for ((i=LAST; i>=0; i--)); do
+ ((i==0)) && count='' || count="continuing in $i seconds ..."
+ spin $count
+ ((i>0)) && sleep 1
+ done
+}
+
+info_message()
+{
+ local MESSAGE=$(sed "s/ */ /g;s/^ *//" <<< "$@" | fold -w 60 -bs)
+ printgreen "*** Note: ***"
+ print2log "$MESSAGE"
+ while read -r line; do
+ printf "%s\n" "$line"
+ done <<< "$MESSAGE"
+ printgreen "*************"
+}
+
+# print to log, formated with leading/trailing spaces removed
+# and prefixed with the script name. [todisc]:
+# with no args it just prints [todisc]:, with "" as arg it prints newline
+print2log()
+{
+ local MESSAGE=$(sed "s/ */ /g;s/^ *//" <<< "$@" | fold -w 60 -bs)
+ # if "" passed in as arg (ie. defined but empty, print a blank line
+ if [[ "${1+defined}" && -z $1 ]]; then
+ printf "\n" >> "$LOG_FILE"
+ # otherwise print [todisc]: $line for each line of input
+ else
+ while read -r line; do
+ printf "%s %s\n" "$ME" "$line" >> "$LOG_FILE"
+ done <<< "$MESSAGE"
+ printf "\n" >> "$LOG_FILE"
+ fi
+}
+
+# pipe stdout to log prefixed by "[name]:", and ending in newline. 2 opt
args
+# arg 1: [name to prefix each line of output]
+# arg 2: [fold] fold lines appropriately. Usually you don't fold program
stdout.
+# uses stdbuf (coreutils) if present so stdin is line buffered
+pipe2log()
+{
+ if [[ $1 ]]; then
+ name="[$1]: "
+ else
+ name="[${0##*/}]: "
+ fi
+ if [[ $2 && $2 = format ]]; then
+ cols=$(( 79 - $(wc -l <<< $name) ))
+ ((cols)) || cols=60
+ format="fold -w $cols -bs"
+ else
+ format="cat"
+ fi
+ $std_buf tr "\015" "\012" < /dev/stdin | $std_buf tr -d "\033" |
$format | \
+ while read line; do
+ printf "%s %s\n" "$name" "$line"
+ done >> "$LOG_FILE"
+ printf "\n" >> "$LOG_FILE"
}

printgreen()
{
- tput setaf 2
- printf "%s\n" "$@" | sed "s/ */ /g;s/^ *//" | tee -a "$LOG_FILE"
- tput sgr0
+ $FROM_GUI || tput setaf 2
+ printf "%s\n" "$@" | sed "s/ */ /g;s/^ *//"
+ print2log "$@"
+ $FROM_GUI || tput sgr0
printf ""
}

-info_message()
-{
- local MESSAGE=( "$@" )
- yecho $SEPARATOR
- printgreen "*** Note: ***"
- for ((i=0; i<$#; i++)) ; do printf "%s" "${MESSAGE[i]}"; done |
- format_output | tee -a "$LOG_FILE"
- echo | tee -a "$LOG_FILE"
- printgreen "*************"
- yecho "$SEPARATOR"
+printred()
+{
+ $FROM_GUI || tput setaf 1
+ printf "%s\n" "$@" | sed "s/ */ /g;s/^ *//"
+ print2log "$@"
+ $FROM_GUI || tput sgr0
+ printf ""
}

titlesafe_error()
{
(($1 > SAFE_AREA)) && preposition='off the' || preposition='from'
- yecho
+ yecho ""
printred "***** WARNING *****"
yecho "video title is $1 pixels $preposition screen edge"
yecho "Part of the title may not be visible on your tv screen"
@@ -356,7 +414,7 @@
: # insert message here for east offscreen stuff #fixme
fi
yecho "****************************"
- $WARN && sleep 5
+ $WARN && continue_in 5
}

format_output()
@@ -388,7 +446,7 @@
[[ -n $2 ]] && stream_type=$2
[[ -n $3 ]] && end="-t $3"
[[ $stream_type = 'audio' ]] && ff_opts="-vn -acodec copy"
- echo "Using ffmpeg to get accurate $stream_type length of $1"
>> "$LOG_FILE"
+ print2log "Using ffmpeg to get accurate $stream_type length of $1"
local len=$(ffmpeg -i "$1" $end $ff_opts -f null -y /dev/null 2>&1 |
sed -n 's/^.*time= *\([^ ]*\).*/\1/p' | tail -n 1)
unformat_time $len
@@ -470,9 +528,9 @@
yecho "todisc encountered an error:"
yecho " $@"
echo
- echo "The error should be shown above, also check the contents of
+ echo "Please check the contents of
$LOG_FILE to see what went wrong." |format_output
- echo "See the tovid website ($TOVID_HOME_PAGE) for possible further
info."
+ echo "See the tovid website ($TOVID_HOME_PAGE) for further help
options."
echo "Sorry for the inconvenience!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
cleanup
@@ -518,7 +576,7 @@
confirm_preview()
{
confirm_msg="type 'yes' to continue, or press <ENTER> to exit: "
- yecho
+ yecho ""
if $SWITCHED || $TITLESET_MODE || $VMGM_ONLY; then
echo "If doing titlesets or switched menus and you wish to exit "
echo "without seeing more previews, then type: 'exit', else you
will "
@@ -532,7 +590,7 @@
echo
if [ ! -z "$input" -a "$input" = "yes" ]; then
yecho "Preview OK, continuing."
- yecho
+ yecho ""
else
yecho "Preview not OK, exiting."
#echo -n "Deleting symlink in /tmp . . . "
@@ -544,7 +602,7 @@
#echo -n "Deleting "$REAL_WORK_DIR" . . . "
rm -fr "$REAL_WORK_DIR"
fi
- yecho
+ yecho ""
echo
echo "Some configuration options to try, if things look bad:"
echo "Color:"
@@ -572,12 +630,10 @@
{
SPIN_CHARS=".oOo"
SPINNER="${SPIN_CHARS:SP++%${#SPIN_CHARS}:1}"
- # Print spaces to overwrite previous line
- echo
-ne "\r "
+ echo -ne "\r$(printf %60s)" # print spaces to overwrite previous line
echo -ne "\r$@ "
}

-#EXPAND="expand=-6:-6,"
get_framed_pics()
{
mplayer -ss $MPLAYER_SEEK_VAL -vo $VOUT -noconsolecontrols \
@@ -626,49 +682,50 @@

get_stats()
{
-unset IN_STATS FILES_IN
-this_set=$1
-if [[ $this_set = "group" ]]; then
- unset TOT IN_STATS FILES_IN
- TOT=${#grouping[@]} # || TOT=${#IN_FILES[@]}
- IN_STATS=( "${group_idvid_stats[@]}" )
- FILES_IN=( "${grouping[@]}" )
-else
- TOT=${#IN_FILES[@]}
- IN_STATS=( "${idvid_stats[@]}" )
- FILES_IN=( "${IN_FILES[@]}" )
-fi
-for ((i=0; i<TOT; i++)); do
- VCODEC="$(awk -F= '/ID_VIDEO_FORMAT/ {print $2}'
<<< "${IN_STATS[i]}")"
- V_BR="$(awk -F= '/ID_VIDEO_BITRATE/ {print $2}'
<<< "${IN_STATS[i]}")"
- ACODEC="$(awk -F= '/ID_AUDIO_CODEC/ {print $2}'
<<< "${IN_STATS[i]}")"
- A_BR="$(awk -F= '/ID_AUDIO_BITRATE/ {print $2}'
<<< "${IN_STATS[i]}")"
- if [ -z "$A_BR" ]; then
- A_BR="No audio found"
+ unset IN_STATS FILES_IN
+ this_set=$1
+ if [[ $this_set = "group" ]]; then
+ unset TOT IN_STATS FILES_IN
+ TOT=${#grouping[@]} # || TOT=${#IN_FILES[@]}
+ IN_STATS=( "${group_idvid_stats[@]}" )
+ FILES_IN=( "${grouping[@]}" )
+ else
+ TOT=${#IN_FILES[@]}
+ IN_STATS=( "${idvid_stats[@]}" )
+ FILES_IN=( "${IN_FILES[@]}" )
fi
- V_LENGTH=${VID_LEN[i]}
- [[ $this_set = "group" ]] && V_LENGTH=${GROUP_VID_LEN[i]}
- FPS="$(awk -F= '/ID_VIDEO_FPS/ {print $2}' <<< "${IN_STATS[i]}")"
- yecho
- if [[ $this_set = "group" ]] && ((i == 0)); then
- echo; echo ". . . Grouped file stats . . ."; echo
- yecho
- fi
- [[ $this_set = "group" ]] && echo -e "Stats for" \
- $(readlink -f "${FILES_IN[i]}") "\n" || \
- echo -e "Stats for" "${FILES_IN[i]}" "\n"
- echo -e \
- " video codec: " \
- "$VCODEC" "\n" \
- "video bitrate: " "$V_BR" "bits per second" "\n" \
- "framerate: " "$FPS" "fps" "\n" \
- "audio codec: " \
- "$ACODEC" "\n" \
- "audio bitrate: " \
- "$A_BR" "bits per second" "\n" \
- "video length: " \
- "$V_LENGTH" "seconds" |tee -a "$LOG_FILE"
-done
+ for ((i=0; i<TOT; i++)); do
+ VCODEC="$(awk -F= '/ID_VIDEO_FORMAT/ {print $2}'
<<< "${IN_STATS[i]}")"
+ V_BR="$(awk -F= '/ID_VIDEO_BITRATE/ {print $2}'
<<< "${IN_STATS[i]}")"
+ ACODEC="$(awk -F= '/ID_AUDIO_CODEC/ {print $2}'
<<< "${IN_STATS[i]}")"
+ A_BR="$(awk -F= '/ID_AUDIO_BITRATE/ {print $2}'
<<< "${IN_STATS[i]}")"
+ if [ -z "$A_BR" ]; then
+ A_BR="No audio found"
+ fi
+ V_LENGTH=${VID_LEN[i]}
+ [[ $this_set = "group" ]] && V_LENGTH=${GROUP_VID_LEN[i]}
+ FPS="$(awk -F= '/ID_VIDEO_FPS/ {print $2}' <<< "${IN_STATS[i]}")"
+ yecho ""
+ if [[ $this_set = "group" ]] && ((i == 0)); then
+ print2log ""; print2log ". . . Grouped file stats . . ."
+ yecho ""
+ fi
+ [[ $this_set = "group" ]] && print2log "Stats for \
+ $(readlink -f "${FILES_IN[i]}")" || \
+ print2log "Stats for" "${FILES_IN[i]}"
+ echo -e \
+ " video codec: " \
+ "$VCODEC" "\n" \
+ "video bitrate: " "$V_BR" "bits per second" "\n" \
+ "framerate: " "$FPS" "fps" "\n" \
+ "audio codec: " \
+ "$ACODEC" "\n" \
+ "audio bitrate: " \
+ "$A_BR" "bits per second" "\n" \
+ "video length: " \
+ "$V_LENGTH" "seconds" |pipe2log
+ done
+
}
test_compliance()
{
@@ -686,6 +743,8 @@
# slide mpg's go in $WORK_DIR, and are moved to BASEDIR later if
recursing
# for video files: files are named $IN_FILE.enc.mpg
unset FILES_TO_ENCODE ENC_IN_FILES CHECK_IN_FILES
+ # get user's config options for makempg from the tovid.ini file
+ makempg_ini_opts=$(tovid mpg | awk '/Read options/{getline;print}')
group_set=false
if [[ $1 = "group" ]]; then
group_set=:
@@ -709,7 +768,7 @@
OUTFILE="$WORK_DIR/${TSET_NUM}-$((i+1)).mpg"
fi

- spin "Checking compliance of file $((i+1))"
+ print2log "Checking compliance of file $((i+1))"
# if file tested as an image when we were verifying input files
if [[ $is_image = "yes" ]]; then
$group_set && grp_use_image2mpeg2[i]="yes" ||
@@ -730,17 +789,16 @@
ENC_IN_FILES=("${ENC_IN_FILES[@]}" "${IN_FILE}.enc.mpg")
fi
done
+ echo
$DEBUG && etime=$(date +%s) && get_elapsed "compliance check"
if test "${#FILES_TO_ENCODE[@]}" -gt 0; then
TGT_CAPS=$(tr a-z A-Z <<< "$TARGET")
TV_STND_CAPS=$(tr a-z A-Z <<< "$TV_STANDARD")
- echo
- yecho "Encode input files"
+ print2log "Encode input files"
if ! $SINGLE_SLIDESHOW; then
- echo
yecho "Some of the -files you provided are not \
$TV_STND_CAPS $TGT_CAPS-compliant:"
- echo " "
+ print2log ""
fi
if test ${#FILES_TO_ENCODE[@]} -lt 12 && ! $SINGLE_SLIDESHOW; then
for i in "${FILES_TO_ENCODE[@]}"; do
@@ -754,12 +812,10 @@
if { $SWITCHED && [[ $MENU_NUM -ne 2 ]] ; } \
|| $NOASK || [[ ${TOVID_OPTS[@]} = *-noask* ]] || \
[[ ${#NO_PROMPT_FILES[@]} = ${#FILES_TO_ENCODE[@]} ]]; then
- yecho " "
echo "Encoding files to $TV_STND_CAPS $TGT_CAPS-compliant
format."
- echo "(This may take a long time)"
ENCODE="yes"
else
- yecho " "
+ yecho ""
yecho "I can encode them for you, but it may take a long time."
yecho "Encoding will ensure that your disc is fully compliant;"
yecho "you may skip this, but your disc may not be playable."
@@ -768,9 +824,7 @@
fi
if test -n "$ENCODE" && test "$ENCODE" = 'yes'; then
if ! $SINGLE_SLIDESHOW; then
- yecho
yecho "Converting files to $TGT_CAPS format"
- yecho
fi
for i in "${!FILES_TO_ENCODE[@]}"; do
IN=$(readlink -f "${FILES_TO_ENCODE[i]}")
@@ -801,12 +855,30 @@
fi
# AUDIO_FADE=false # do not fade silence FIXME ???
else # not an image file - outfile goes beside infile
- THIS_FILE=$(readlink -f "${FILES_TO_ENCODE[i]}")
- yecho "Converting $THIS_FILE"
+ #THIS_FILE=$(readlink -f "${FILES_TO_ENCODE[i]}")
+ if [[ -e "$IN.enc.mpg" ]]; then
+ if ! grep -w -- -overwrite <<< \
+ "$makempg_ini_opts ${script_args[@]}"; then
+ : #FIXME need to echo to terminal what makempg
would do
+ fi
+ fi
+ yecho "Converting $IN"
echo
- countdown 3
+ continue_in 3
TOVID_WORKING_DIR=$WORKING_DIR makempg $NO_ASK \
- -$TV_STANDARD -$TARGET -in "$IN"
-out "${IN}.enc" "${TOVID_OPTS[@]}"
+ -$TV_STANDARD -$TARGET -in "$IN" -out "${IN}.enc" \
+ "${TOVID_OPTS[@]}" 2>&1 |pipe2log makempg
+ if ! ((${PIPESTATUS[0]})); then
+ runtime_error "makempg could not encode $IN \
+ see $LOG_FILE for details."
+ else
+ if [[ -e "${IN}.enc.mpg" ]];then
+ yecho "Success! Using ${IN}.enc.mpg for this
DVD menu"
+ else
+ runtime_error "There appears to be a problem
creating \
+ the DVD compatible mpeg. See $LOG_FILE for
details"
+ fi
+ fi
# for grouped files replace symlink in $WORK_DIR
$group_set && [[ -L "${FILES_TO_ENCODE[i]}" ]] && \
ln -sf "${IN}.enc.mpg" "${FILES_TO_ENCODE[i]}"
@@ -822,17 +894,15 @@
KEEP_FILES=:
runtime_error "Could not encode file: $IN"
fi
- #yecho
+ #yecho ""
done

# Replace IN_FILES with ENC_IN_FILES (with .enc extension)
# for grouped files the mpeg already replaced the group symlink
! $group_set && IN_FILES=("${ENC_IN_FILES[@]}")
else
- yecho
- yecho "Not re-encoding. I will proceed with menu generation,
but"
- yecho "your authored disc will not be fully
$TGT_CAPS-compliant."
- yecho
+ info_message "Not re-encoding. I will proceed with menu
generation, but
+ your authored disc will not be fully $TGT_CAPS-compliant."
fi
fi
}
@@ -843,7 +913,7 @@
VIDEO_IN="$1"
VIDEO_IN_SEEK="$2"
video_type=$3
- yecho
+ yecho ""
yecho "$VIDEO_IN is not compliant - re-encoding \
$(bc <<< "$VIDEO_IN_SEEK + ${MENU_LEN[MENU_NUM-1]}" 2>/dev/null)
second slice to DVD compliant file"
@@ -858,9 +928,9 @@
return
fi
fi
- yecho
+ yecho ""
yecho "Converting files to $TGT_CAPS format with 'makempg'"
- countdown
+ continue_in 5
makempg $NO_ASK -in "$VIDEO_IN" \
-slice 0-$(bc <<< "$VIDEO_IN_SEEK + ${MENU_LEN[MENU_NUM-1]}"
2>/dev/null) \
-${TV_STANDARD} -${TARGET} -in "$VIDEO_IN" \
@@ -873,7 +943,7 @@
[[ $video_type = background ]] && BG_VIDEO="${VIDEO_IN}.enc.mpg"
fi
SUPPORT_VIDEOS=( "${SUPPORT_VIDEOS[@]}" "${VIDEO_IN}.enc.mpg" )
- yecho
+ yecho ""
}

mk_workdir()
@@ -1026,8 +1096,10 @@
-i "$IN_IMAGE" -f s16le -ar 48000 -i /dev/zero -t $alength \
-ar $SAMPLERATE -ac 2 -ab 224k -target ${TV_STANDARD}-${TARGET} \
-s $VIDSIZE $ASPECT -y "$OUT_MPEG")
- echo "Running ${IMAGE_ENC_CMD[@]}" | format_output >> "$LOG_FILE"
- "${IMAGE_ENC_CMD[@]}" 2>&1 |strings >> "$LOG_FILE"
+ print2log ""
+ print2log "Running ${IMAGE_ENC_CMD[@]}"
+ print2log ""
+ "${IMAGE_ENC_CMD[@]}" 2>&1 | pipe2log ffmpeg
}

switched_menu_mode()
@@ -1042,6 +1114,7 @@
-basedir "$BASEDIR" -menu_num $((i+1)) -showcase "${FILES[i]}""
todisc "$@" -switched-mode $IS_TITLESET -basedir "$WORK_DIR" \
-menu_num $((i+1)) -todisc_pids "$TODISC_PIDS"
-showcase "${FILES[i]}"
+ yecho
done
yecho
yecho "Working on switched menu 1"
@@ -1075,7 +1148,7 @@
$NO_CONFIRM_BACKUP ${encopt[@]} $sld_tranition
$background_carousel \
$showcase_carousel -out "$OUT_PREFIX" -carousel_menu_mode -basedir
\
"$WORK_DIR" $menulen -carousel_num $((c+1))
-todisc_pids "$TODISC_PIDS")
- yecho
+ yecho ""
yecho "Running ${MC_CMD[@]}"
"${MC_CMD[@]}"
}
@@ -1363,7 +1436,7 @@
################### end titleset options testing
#########################

if [[ -z ${VMGM_OPTS[@]} ]]; then
- yecho
+ #yecho
yecho "You have not supplied -vmgm OPTIONS -end-vmgm"
yecho "At a minumum you should have: \
'-vmgm -titles "Title one" "Title two" -end-vmgm'"
@@ -1383,8 +1456,8 @@
fi
yecho "Making a generic vmgm menu for you - \
you may wish to cancell out and change this."
- yecho
- $VMGM_MENU && $WARN && sleep 15
+ yecho ""
+ $VMGM_MENU && $WARN && continue_in 15
else
unset vmgmtitles
get_menu_titles "${VMGM_OPTS[@]}"
@@ -1395,12 +1468,11 @@
fi
################### end titleset options testing
#########################
# VMGM menu
- yecho
- yecho "Making a VMGM menu with the following command:"
+ print2log "Making a VMGM menu"
vmgm_menu_cmd=(todisc "${GEN_OPTS[@]}" -basedir "$WORK_DIR" -vmgm_only
\
-textmenu -todisc_pids "$TODISC_PIDS" $NO_CONFIRM_BACKUP \
-title_count "$num_titles" $vmgm_playall "${VMGM_OPTS[@]}")
- yecho "Running: ${vmgm_menu_cmd[@]}"
+ print2log "Running: ${vmgm_menu_cmd[@]}"
INITIALDIR="$BASEDIR"
if ! "${vmgm_menu_cmd[@]}" ; then cleanup && exit 1; fi
# TITLESET menus
@@ -1424,8 +1496,8 @@
yecho
yecho "Working on the menu for titleset number $tset"
yecho
- $WARN && sleep 5
- yecho "Running: ${titleset_cmd[@]}"
+ $WARN && continue_in 5
+ print2log "Running: ${titleset_cmd[@]}"
if ! "${titleset_cmd[@]}"; then cleanup && exit 1; fi
yecho
;;
@@ -1434,7 +1506,7 @@
done
echo -e "</dvdauthor>" >> "$DVDAUTHOR_XML"
yecho "Running dvdauthor to create final DVD structure"
- dvdauthor -x "$DVDAUTHOR_XML" 2>&1 | tee -a "$LOG_FILE"
+ dvdauthor -x "$DVDAUTHOR_XML" 2>&1 | pipe2log dvdauthor
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
dvdauthor_error
fi
@@ -1459,7 +1531,7 @@

burn_disc()
{
- BURN_CMD=(tovid dvd -burn -device $EJECT "$BURN_DEVICE" \
+ BURN_CMD=(tovid dvd -burn -device "$BURN_DEVICE" $EJECT \
$BURN_SPEED \"$BURN_TGT\")
yecho
echo "You have indicated you want to burn the $BURN_TGT_STR"
@@ -1471,7 +1543,7 @@
echo "Proceeding to burn, continuing."
echo
$BURN_PROG -burn -device "$BURN_DEVICE" \
- $BURN_SPEED "$BURN_TGT" | tee -a "$LOG_FILE" 2>&1
+ $BURN_SPEED "$BURN_TGT" | pipe2log makedvd
if ((${PIPESTATUS[0]}==0)); then
echo "Your ${BURN_TGT_STR/ *} should be ready"
else
@@ -1488,20 +1560,26 @@

thanks_goodbye()
{
- echo
- echo $SEPARATOR
SCRIPT_TIME=$(format_seconds $SECONDS)
- echo "todisc took $SCRIPT_TIME to finish on $CPU_MODEL $CPU_SPEED mhz"
- echo $SEPARATOR
- echo "Your new DVD should be in $OUT_DIR"
- echo "You can preview them in gxine with this command:"
- echo " gxine \"dvd:/$OUT_DIR\""
- echo "Or in vlc with this command:"
- echo " vlc \"$OUT_DIR\""
- echo "If you are satisfied with the results, you can burn a disc with:"
- echo " tovid dvd -burn \"$OUT_DIR\""
+ goodbye=`cat << EOF
+
+ $SEPARATOR
+ todisc took $SCRIPT_TIME to finish on
+ $CPU_MODEL $CPU_SPEED mhz
+ $SEPARATOR
+
+ Your new DVD should be in $OUT_DIR
+ You can preview them in gxine with this command:
+ $(printf "%s\t" "gxine \"dvd:/$OUT_DIR\"")
+ Or in vlc with this command:
+ $(printf "%s\t" "vlc \"$OUT_DIR\"")
+ If you are satisfied with the results, you can burn a disc with:
+ $(printf "%s\t" "tovid dvd \"$OUT_DIR\"")
+
+ Thanks for using tovid!
+EOF`
echo
- echo "Thanks for using tovid!"
+ sed 's/^ //g' <<< "$goodbye" | tee -a "$LOG_FILE"
}

# usage mk_return_button (mk_play_button) COLOUR1 COLOUR2 OUTBUTTON
@@ -1528,7 +1606,7 @@
-draw "polyline 60,10 60,50 30,30 60,10" \
-fill "$COLR2" -draw "rectangle 6,10 10,50" \
-resize 30% -trim +repage +antialias "$OUTBUTTON")
- echo -e "\nRunning ${MK_RTN_CMD[@]}\n" |format_output
+ print2log "Running ${MK_RTN_CMD[@]}"
"${MK_RTN_CMD[@]}"
mogrify -channel A -threshold 50% "$OUTBUTTON"
RTN_BTN_DIM=$(get_image_dim "$OUTBUTTON")
@@ -1554,7 +1632,7 @@
-fill "$COLR2" -stroke none \
-draw "polyline 40,10 40,50 80,30 40,10" \
-resize 30% -trim +repage "$OUTBUTTON")
- echo -e "\nRunning ${MK_PLAY_CMD[@]}\n" |format_output >> "$LOG_FILE"
+ print2log "Running ${MK_PLAY_CMD[@]}"
"${MK_PLAY_CMD[@]}"
PLAY_BTN_DIM=$(get_image_dim "$OUTBUTTON")
play_btn_width=$(awk -Fx '{print $1}' <<< $PLAY_BTN_DIM )
@@ -1563,7 +1641,7 @@

check_menufile()
{
- yecho
+ yecho ""
if test -f "$MENU_FILE"; then
echo "Menu file $MENU_FILE created"
echo
@@ -1584,34 +1662,42 @@
QM_MENU_TIME=${MENU_LEN[MENU_NUM-1]} && QM_PREVIEW=false
fi
# test for filters and vhook
- filters=$(ffmpeg -filters 2>/dev/null)
- if grep -q -w '^movie' <<< "$filters" && \
- grep -q -w '^crop' <<< "$filters"; then
- echo "libavfilter overlay and crop filters are present"
- use_overlay_filter=:
- echo "Using libavfilter for -quick-menu"
- elif grep -q ^-vhook <<< "$(ffmpeg -h 2>&1)"; then
- # find out where vhook lives for ffmpeg
- local config=$(ffmpeg -version 2>&1 | grep -- --prefix=)
- config=${ffmpeg_prefix//*--prefix=}
- ffmpeg_prefix=${config// *}
- # empty var means no --prefix passed, use default prefix of
/usr/local
- ffmpeg_prefix=${ffmpeg_prefix:-/usr/local}
- imlib2_vhook="${ffmpeg_prefix}/lib/vhook/imlib2.so"
- if [[ -s "$imlib2_vhook" ]]; then
- use_vhooks=:
- else
- yecho "!!!!! $imlib2_vhook not found, can not continue !!!!!"
+ if ! ((filter_test_completed)); then
+ filters=$(ffmpeg -filters 2>/dev/null)
+ if grep -q -w '^movie' <<< "$filters" && \
+ grep -q -w '^crop' <<< "$filters"; then
+ print2log "libavfilter movie filter present - using for
-quick-menu"
+ use_overlay_filter=:
+ elif grep -q ^-vhook <<< "$(ffmpeg -h 2>&1)"; then
+ # find out where vhook lives for ffmpeg
+ local config=$(ffmpeg -version 2>&1 | grep -- --prefix=)
+ config=${ffmpeg_prefix//*--prefix=}
+ ffmpeg_prefix=${config// *}
+ # empty var means no --prefix passed, use default prefix of
/usr/local
+ ffmpeg_prefix=${ffmpeg_prefix:-/usr/local}
+ imlib2_vhook="${ffmpeg_prefix}/lib/vhook/imlib2.so"
+ if [[ -s "$imlib2_vhook" ]]; then
+ use_vhooks=:
+ print2log "vhooks present, using imlib2 vhook for
-quick-menu"
+ fi
+ #else
+ # yecho "!!!!! $imlib2_vhook not found, can not
continue !!!!!"
+ #fi
fi
fi

# exit if neither vhooks or movie filter found
if ! $use_vhooks && ! $use_overlay_filter; then
- runtime_error "No -quick-menu possible: ffmpeg movie filter absent"
+ runtime_error \
+ "No ffmpeg 'movie' filter or (older) 'vhooks'. -quick-menu
impossible"
fi
+ # ensure the filter test is only run once
+ filter_test_completed=1
if $QUICKMENU_IS_SHOWCASE; then
- yecho
- yecho "resizing and padding showcase file: $SHOWCASE_VIDEO"
+ if ! $NOASK; then
+ yecho ""
+ yecho "resizing and padding showcase file: $SHOWCASE_VIDEO"
+ fi
LEFTPAD=$SC_X
TOPPAD=$SC_Y
RIGHTPAD="-padright \
@@ -1640,18 +1726,18 @@
qm_post_seek=$qm_seek && unset qm_pre_seek
fi

- $QM_PREVIEW && yecho "Creating a quick-menu preview image"
+ $QM_PREVIEW && ! $NOASK && yecho "Creating a quick-menu preview image"
# pad/resize if needed, use overlay filter (or vhook) to add menu
graphics
# framing (if showcase) by ntsc-safe black bg
- ! $QM_PREVIEW && yecho
if ! $QM_PREVIEW; then
+ yecho ""
yecho "Using ffmpeg to add titles and background"
fi
if $use_overlay_filter; then
local overlay="$WORK_DIR/quick_menu_bg.png"
local PADDING="$VF pad=720:480:$VF_PADX:$VF_PADY"
local aspect=""
- overlay_filter="movie=$overlay [wm];[in][wm] overlay=0:0:1 [wm2]"
+ overlay_filter="movie=$overlay [wm];[in][wm] overlay=0:0 [wm2]"
ffmpeg_filter=($VF "$overlay_filter; [wm2] setdar=4:3 [out]")
elif $use_vhooks; then
local PADDING="$TOPPAD $BOTTOMPAD $LEFTPAD $RIGHTPAD"
@@ -1673,53 +1759,49 @@
-i "$yuvout" -an -s $VIDSIZE -f mpeg2video -r $FRAME_RATE \
$STANDARD $TV_STANDARD -b 7000k -maxrate 8000k -bufsize 224KiB \
$aspect "${ffmpeg_filter[@]}" -y "$WORK_DIR/intro.m2v")
- if $VERBOSE; then
- $QM_PREVIEW && yecho
- yecho "Running ${PAD_CMD[@]}"|fold -bs
- echo "${QUICKMENU_CMD[@]}" | fold -bs | tee -a "$LOG_FILE"
- fi
"${PAD_CMD[@]}" < /dev/null > "${LOG_FILE}-1.tmp" 2>&1 &
"${QUICKMENU_CMD[@]}" < /dev/null > "${LOG_FILE}-2.tmp" 2>&1 &
ffmpeg_pid=$!
- $VERBOSE && yecho
- while ps -p $ffmpeg_pid >/dev/null; do
- sleep 1
- [[ -s "$WORK_DIR/intro.m2v" ]] && txt="Writing" || txt="Seeking"
- spin $txt $SPINNER
- done
+ if ! $QM_PREVIEW; then
+ while ps -p $ffmpeg_pid >/dev/null; do
+ sleep 1
+ [[ -s "$WORK_DIR/intro.m2v" ]] && txt="Writing" ||
txt="Seeking"
+ spin $txt $SPINNER
+ done
+ fi
wait
- yecho
+ ! $QM_PREVIEW && yecho ""
# remove control characters and seeking lines
- strings "${LOG_FILE}-1.tmp" | sed '/time=10000000000.00/d'
>> "$LOG_FILE"
- strings "${LOG_FILE}-2.tmp" | sed '/time=10000000000.00/d'
>> "$LOG_FILE"
+ [[ -e ${LOG_FILE}-1.tmp ]] && \
+ cat "${LOG_FILE}-1.tmp" | sed '/time=10000000000.00/d' | pipe2log
ffmpeg
+ [[ -e ${LOG_FILE}-2.tmp ]] && \
+ cat "${LOG_FILE}-2.tmp" | sed '/time=10000000000.00/d' | pipe2log
ffmpeg
if [[ ! -s "$WORK_DIR/intro.m2v" ]]; then
runtime_error "There was a problem creating the menu video
$funct_arg"
fi
rm -f "${LOG_FILE}*.tmp"
- ! $QM_PREVIEW && yecho
+ ! $QM_PREVIEW && yecho ""
# create preview images if called for, taking largest of 10 images
if $QM_PREVIEW; then
FFMPEG_CMD=(ffmpeg -i "$WORK_DIR/intro.m2v" -an -vframes 10 \
-f image2 -y "$outdir"/%06d.$IMG_FMT)
- yecho "Running ${FFMPEG_CMD[@]}" | strings
- "${FFMPEG_CMD[@]}" 2>&1 | strings >> "$LOG_FILE"
+ print2log "Running ${FFMPEG_CMD[@]}"
+ "${FFMPEG_CMD[@]}" 2>&1 | pipe2log ffmpeg
# take the largest image (best quality?) of a 10 frame sampling
largest_img=$(get_largest 6 10 "$outdir" )
mv "$largest_img" "$PREVIEW_IMG"
- yecho "Removing temporary preview files"
+ print2log "Removing temporary preview files"
rm -f "$WORK_DIR/intro.m2v"
rm -f "$WORK_DIR"/showcase/*.$IMG_FMT "$WORK_DIR"/bg/*.$IMG_FMT
fi
- $QM_PREVIEW && yecho
+ $QM_PREVIEW && yecho ""
}

# 3x1 and 4x1 tile only for default arrangement
tile_warning()
{
- yecho
- echo "-tile-3x1 and -tile-4x1 are not showcase options. Disabling"
- yecho
- $WARN && sleep 5
+ info_message "-tile-3x1 and -tile-4x1 are not showcase options.
Disabling"
+ $WARN && continue_in 5
}
dvdauthor_error()
{
@@ -1765,21 +1847,25 @@
-L 1 -b1 -j "$WORK_DIR/dummy.jpg")
ENC_CMD2=(ffmpeg -f yuv4mpegpipe -i - -an -r $FRAME_RATE -s $VIDSIZE \
$STANDARD $TV_STANDARD $FFMPEG_OPTS -y "$WORK_DIR/dummy.m2v")
- echo "Running: ${ENC_CMD1[@]} | ${ENC_CMD2[@]}"|format_output
>> "$LOG_FILE"
- if ! ${ENC_CMD1[@]} 2>> "$LOG_FILE" |
- ${ENC_CMD2[@]} 2>&1 |strings >> "$LOG_FILE"; then
+ print2log "Running: ${ENC_CMD1[@]} | ${ENC_CMD2[@]}"
+ if ! ${ENC_CMD1[@]} 2>> "${LOG_FILE}.tmp" |
+ ${ENC_CMD2[@]} 2>&1 |pipe2log ffmpeg; then
runtime_error
fi
+ [[ -e ${LOG_FILE}.tmp ]] && cat "${LOG_FILE}.tmp" | pipe2log jpeg2yuv
+ rm -f "${LOG_FILE}.tmp"
local VMGM_TIME=$(stream_length "$WORK_DIR/dummy.m2v")
BGAUDIO_CMD=(ffmpeg -f s16le -ar 48000 -i /dev/zero -t $VMGM_TIME \
$AUDIO_OPTS -y "$WORK_DIR/dummy.$AUDIO_EXT")
- "${BGAUDIO_CMD[@]}" 2>&1 | strings >> "$LOG_FILE"
+ print2log "Creating silent audio stream."
+ print2log "${BGAUDIO_CMD[@]}"
+ "${BGAUDIO_CMD[@]}" 2>&1 | pipe2log ffmpeg
! [[ -s "$WORK_DIR/dummy.$AUDIO_EXT" ]] && runtime_error

MPLEX_CMD=(mplex -V -f $MPLEX_FORMAT -o "$BASEDIR/dummy.mpg" \
"$WORK_DIR/dummy.$AUDIO_EXT" "$WORK_DIR/dummy.m2v")
- echo "Running: ${MPLEX_CMD[@]}" |fold -bs >> "$LOG_FILE"
- ! "${MPLEX_CMD[@]}" 2>&1 |strings >> "$LOG_FILE" && runtime_error
+ print2log "Running: ${MPLEX_CMD[@]}"
+ ! "${MPLEX_CMD[@]}" 2>&1 |pipe2log mplex && runtime_error
}
verify_infiles()
{
@@ -1831,13 +1917,11 @@
# also convert if not PNG or JPEG or wrong aspect ratio
# test IN_FILES for preview - group files tested later
if [[ $DEPTH = 16 || $PAD_IMG = "yes" ]] || $CONVRT ; then
- echo "Converting $IN_FILE to proper image format" \
- >> "$LOG_FILE"
+ print2log "Converting $IN_FILE to proper image format"
IMG_CMD=(convert "$IN_FILE" -depth 8 "${CROP_CMD[@]}" \
-quality 01 "$OUTPNG")
- format_output <<< "${IMG_CMD[@]}" \
- >> "LOG_FILE"
- "${IMG_CMD[@]}" |format_output >> "$LOG_FILE" 2>&1
+ print2log "${IMG_CMD[@]}"
+ "${IMG_CMD[@]}" 2>&1| pipe2log imagemagick
# replace IN_FILES[i] OR group symlink
if [[ $verify_type = "infiles" ]]; then
IN_FILES[i]=$OUTPNG
@@ -1876,6 +1960,7 @@
usage_error "Sorry, $IN_FILE does not exist or is empty"
fi
done
+ echo
}

# contrasting 'undercolor' for -background from given font colour
@@ -2122,7 +2207,7 @@
if [[ $mask_type == "thumb" ]]; then
local BLUR_CMD=( "${THUMB_BLUR_CMD[@]}" )
else
- local BLUR_CMD=( "${SC_BLUR_CMD[@]]}" )
+ local BLUR_CMD=( "${SC_BLUR_CMD[@]}" )
fi
MASK="$WORK_DIR/${shape}_${mask_type}_mask.png"

@@ -2251,7 +2336,7 @@
transcode shown below if it shows transcode finishing the last image. \
These harmless 'broken pipe' messages from transcode appear to be a \
subtle bug in transcode when running it (or a script) from python. \
- \n****\n" | sed "s/ */ /g;s/^ *//" |fold -bs >> "$LOG_FILE"
+ \n****\n" | sed "s/ */ /g;s/^ *//" | pipe2log todisc format
}

# get the largest PNG (1st match sequentially if more than one are same
size)
@@ -2295,7 +2380,7 @@

egrep -q 'titleset-mode|switched-mode|menu-only|carousel_menu_mode'
<<< "$@" \
&& NONAME=:
-! $NONAME && yecho $"$SCRIPT_NAME"
+! $NONAME && echo $"$SCRIPT_NAME"

while test $# -gt 0; do
DO_SHIFT=:
@@ -2318,6 +2403,9 @@
for f in ${!ARGS_ARRAY[@]}; do
FILENAMES[f]=${ARGS_ARRAY[f]}
filenames[f]=$(readlink -f "${ARGS_ARRAY[f]}")
+ if [[ ! -e ${filenames[f]} ]]; then
+ usage_error "${filenames[f]} does not exist"
+ fi
done
if $incoming_slides; then
SLIDESHOW=( ${SLIDESHOW[@]} : ) # is this a slideshow ?
@@ -2333,6 +2421,9 @@
unset group groupkey grp x
for ((i=0; i<${#ARGS_ARRAY[@]}; i++)); do
grp[x++]=$(readlink -f "${ARGS_ARRAY[i]}")
+ if [[ ! -e "${ARGS_ARRAY[i]}" ]]; then
+ usage_error "${ARGS_ARRAY[i]} does not exist"
+ fi
done
unset x
[[ -z ${FILES[@]} ]] && ss_index=0 || ss_index=${#FILES[@]}
@@ -2497,6 +2588,7 @@
ADV_OPT=( "${ADV_OPT[@]}" "$1" )
shift
BUTTON_GRAVITY=$1
+ BUTTON_GRAVITY=$(tr A-Z a-z <<< $BUTTON_GRAVITY) # West => west
[[ $BUTTON_GRAVITY = "centre" ]] && BUTTON_GRAVITY="center"
USER_GRAVITY=:
;;
@@ -2800,9 +2892,10 @@
"-showcase-titles-align" )
shift
SC_TITLE_ALIGN="$1"
+ SC_TITLE_ALIGN=$(tr A-Z a-z <<< $SC_TITLE_ALIGN) # West => west
[[ SC_TITLE_ALIGN = "centre" ]] && SC_TITLE_ALIGN="center"
;;
- "-title-gap" )
+ "-titles-gap" | "-title-gap" )
ADV_OPT=( "${ADV_OPT[@]}" "$1" )
shift
SPACER=$1
@@ -2905,6 +2998,7 @@
(( ${SC_BLUR%.*} >= 2 )) && SC_BLUR=2
SC_USER_BLUR=1
;;
+ "-menu-title-colour" | "-menu-title-color" | \
"-title-colour" | "-title-color" )
shift
TITLE_CLR="$1"
@@ -2921,7 +3015,7 @@
shift
SM_TITLE_CLR="$1"
;;
- "-title-stroke" )
+ "-menu-title-stroke" | "-title-stroke" )
shift
M_TITLE_STROKE="$1"
;;
@@ -2937,7 +3031,7 @@
shift
test_is_number $1 && TITLES_OPACITY="$1"
;;
- "-title-opacity" )
+ "-menu-title-opacity" | "-title-opacity" )
shift
test_is_number $1 && TITLE_OPACITY="$1"
;;
@@ -2969,7 +3063,8 @@
shift
SELECT_CLR="$1"
;;
- "-title-font-deco" | "-title-fontdeco" )
***The diff for this file has been truncated for email.***

Reply all
Reply to author
Forward
0 new messages