Repository 32bit  Forum
Repository 64bit  Wiki

Mencoderprogress (en)

Da Slacky.eu.
Versione delle 09:20, 4 ott 2008, autore: 414n (Discussione | contributi)

(diff) ← Versione meno recente | Versione attuale (diff) | Versione più recente → (diff)


Per la versione in italiano di questa pagina, fiondarsi qui

Indice

Introduction

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.

Description

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

Current version is 1.01, released on 02/10/2008 (date is in dd/mm/yyyy format).

Dependencies

GNU Bash 
Needed in order to execute the script.
mencoder 
To produce the output to elaborate.
awk 
Used to process/filter information.

Configuration

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:

634 
Is the movie length in seconds. I was forced to put it as a command line parameter because the output of mencoder (contrary to that of ffmpeg) lacks this information. If not specified, the default value of "9999999" is used (not much sense...).
"Converting Doo da doo" 
Is the message to be displayed during conversion. If not specified, the message "Converting video..." will be shown.

UPDATE

From version 1.01 a new user editable variable has been added:

REFRESH_TIME 
Tells how much seconds must pass before the percentage needs to be updated (in seconds). If not set, default value is 3 (seconds).


Script

#!/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

Installation

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"

Changelog

1.00 
initial version of the script.
1.01 
added a refresh interval in order to boost performance.

Feedback

If you've got something to say/report, please do it here. It's an italian Slackware forum.

414n

Strumenti personali
Namespace

Varianti