Per la versione in italiano di questa pagina, fiondarsi qui
At first, I thought to write down a script to capture ffmpeg conversions progress, in order to display it in percentage instead of the actual position (in seconds) inside the stream (not that great to have an idea of the actual progress). After the completion of that script (which will be published shortly here on Wikislacky), I made a similar one for mencoder.
mencoder shouldn't need a script like this which elaborates its output in order to display a percentage of the conversion progress, because it already does it. However, sometimes, the percentage shown by mencoder itself stays at 0% meanwhile the position inside the stream (in seconds) works everytime.
Given this, I made this script. It's automatically invoked by my other script toZenAviMencoder, being it also available here on Wikislacky.
This script screens the normal output on standard output (stdout) of mencoder to show, instead, the progress of the video conversion, using a percentage. If dialog is inside the PATH, it will be used. Otherwise, the progress will be shown using a normal echo.
Current version is 1.01, released on 02/10/2008 (date is in dd/mm/yyyy format).
The script must be piped with mencoder, so it can capture its output on standard output. A usage example:
mencoder <parameters> | mencoderprogress.sh 634 "Converting Doo da doo"
where:
UPDATE
From version 1.01 a new user editable variable has been added:
#!/bin/bash
#
# Script used to show the progress of a mencoder conversion.
# Made for you by 414N <414N atATat slacky dotDOTdot it>
# 02/09/2008
# Versione 1.01
# Parameters:
# (stdin) : piped mencoder output
# $1 : Movie length (in seconds)
# $2 : Messagge to show
# Arguments check
DURATION=${1:-"9999999"}
MESSAGE=${2:-"Converting video..."}
# Variable which contains the last elaborated progress value. Used to save prints.
OLDPROGRESS=0
# Variable containg the actual progress, elaborated time to time.
PROGRESS=0
# Percentage refresh interval (to boost performance)
# It is in seconds.
REFRESH_TIME=${REFRESH_TIME:-3}
# dialog presence in PATH check
if [ -z "$USE_DIALOG" ]
then
if [ `which dialog 2>/dev/null` = "" ]
then
USE_DIALOG=0
else
USE_DIALOG=1
fi
fi
# Function to output the progress to screen
#
# Parameters:
# $1 = Actual progress (integer)
function print_progress ()
{
if [ "$USE_DIALOG" = 0 ]
then
echo -ne "$MESSAGE : $1%\r"
else
echo "$1" | dialog --title "mencoder video conversion" --gauge "$MESSAGE" 10 50
fi
}
print_progress 0
while read -e -d $'\r' INFO
do
ACTUAL_TIME=$(echo "$INFO" | awk -F's' '{gsub(/ */,"",$2); print $2}' | cut -d':' -f2 | awk '/^([1-9][0-9]*\.[0-9]*)$/')
if [ $ACTUAL_TIME ]
then
PROGRESS=$(echo "$ACTUAL_TIME $DURATION" | awk '{printf "%.0f\n",$1 / $2 * 100}')
if [ "$PROGRESS" -ne "$OLDPROGRESS" ]
then
print_progress "$PROGRESS"
OLDPROGRESS="$PROGRESS"
read -t "$REFRESH_TIME"
fi
fi
done
if [ "$PROGRESS" -eq 0 ]
then
exit 1
else
print_progress 100
fi
exit 0
You just need to put the script inside a path contained in the PATH enviroment variable, and grant it execution permission. I suggest to create a folder (bin, for example) inside your home folder and put it in your PATH, editing/creating the ~/.bashrc and ~/.bash_profile files with the following
export PATH+=":~/bin"
If you've got something to say/report, please do it here. It's an italian Slackware forum.