LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-07-2010, 05:08 AM   #1
delta function
Member
 
Registered: Jul 2004
Posts: 51

Rep: Reputation: 20
Help needed with costum progressbar of video conversiono script ( flv to xvid )


Hello,

I have writen a bash script to convert flv files ( eg Youtube ) to xvid to be played on my dvd player. The conversion is not really the issue, as it works.

What I am dealing with now are 2 problems I have not found a good workarouond:
1. Surpressing the shell output of mencoder completly ( I do not want to see all the mencoder messages). This I have only solved to a certian extend.
2. I want to create a progressbar. This one I have not yet cracked.

The script:
Code:
#!/bin/bash

## Settings
V_BITRATE=768
Video_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
Audio_OPTS="-oac mp3lame -lameopts fast:preset=standard"

store_dir=./converted_files

#Check if we have files of interest in this directory
flv_files=$(ls -1 ./*.flv 2> /dev/null | wc -l)

function store_dir {	

	# create store directory to store the converted files	
	if [ -d $store_dir ]; then
		echo ""
	else 
		echo ""
		mkdir $store_dir
	fi
}


function flv_to_xvid {

# Check if we have files to convert, otherwise print not found message
if [ $flv_files -ne 0 ]
then
# Start to convert the video files
for i in *.flv;do

	echo "Converting $i"
 	mencoder "$i" $Video_OPTS -vf pp=lb $Audio_OPTS -o "${i%.flv}.avi" > /dev/null
	echo "Done ..."

	# move file to store directory
	mv "${i%.flv}.avi" $store_dir
done

else
	echo ""
	echo "No flv files in directory"
fi
}

function main_menu {

	echo -e "---------------------------------"
	echo -e "Convert Flash Movie Files to XVID"
	echo -e "---------------------------------"
	echo -e "FLV Files Found: [$flv_files]"
	echo -e "\n"
	echo -en "Convert file(s)? [Y]es [N]o: "
	read input

case $input in

	y)
		store_dir	
		flv_to_xvid
	;;
	n)
		exit 1
	;;
	esac
}

#start the script
main_menu
1. Mencoder output: using /dev/null works more or less. For example: if mencoder detects a double frame while converting, a message is still printed on the bash screen

2. Progressbar: I have no clue yet on how to do this. Any link or tip is welcome.
My goal is something like this:
[56%] [time in progress] [timeleft ]

Thanks
 
Old 08-07-2010, 05:12 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
1. Mencoder output: using /dev/null works more or less.
This would be because you only redirect standard out. Try putting 2>&1 prior to /dev/null

Sorry do not have time right now to help with question 2, but have you searched this forum and google? I have seen plenty of progress meters
in linux systems.
 
Old 08-07-2010, 05:31 AM   #3
delta function
Member
 
Registered: Jul 2004
Posts: 51

Original Poster
Rep: Reputation: 20
Thanks,

fiddeoling around with >/dev/null I found that &>/dev/null seems to work.

As for the ptrogress bar: I have search LQ but was not very successful.
Google searchis still running, I have found some info, but still examining the findings.

Keep you posted

 
Old 08-07-2010, 06:55 AM   #4
delta function
Member
 
Registered: Jul 2004
Posts: 51

Original Poster
Rep: Reputation: 20
Ok well looks like I bit of more than I can chew.

I dropped the progress bar. As many of the the flv files do not contain data of lenght only size, its quite hard to construct an estimate final size. With now estimate final size, its very inaccurate to use a progress bar.

Instead I settled down on creating a simple timer to show the time in progress.
Basic idea:
Code:
  IFS=:
  secs=1
  while [ $secs -gt 0 ]
  do
    sleep 1 &
    printf "Time in progress \r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
    secs=$(( $secs + 1 ))
    wait
  done
  echo
The timer works, but will go on indefinitely. I tried to integrate the timer. No success. The timer will just go on and on.
I am trying to find a way to stop the timer when mencoder has completed the actual conversion.

So far no luck
 
Old 08-07-2010, 07:50 AM   #5
Freex
LQ Newbie
 
Registered: Oct 2006
Location: Belgium, Europe
Distribution: OpenSUSE 11.3 KDE, PCLinuxOS 2010 KDE
Posts: 29

Rep: Reputation: 17
Couldn't you use a sentinel, for instance a file? When the mencoder script is done, it creates an empty file, and the timer script checks for the existance of the file and quits if it exists (after deleting the sentinel)

Code:
secs=1
while [ $secs -gt 0 ]
do
    sleep 1
    if [ -f .sentinel ]; then
         rm -f .sentinel;
         break;
    fi
    printf "Time in progress \r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
    secs=$(( $secs + 1 ))
done
echo
(apologies if there are issues with my additions, haven't used shell scripting in a while)

Last edited by Freex; 08-07-2010 at 07:51 AM.
 
Old 08-07-2010, 08:52 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would add that you should use your round brackets for your while test:
Code:
[ $secs -gt 0 ] -> (( secs > 0 ))
And your increment can be done without extra assignment:
Code:
secs=$(( $secs + 1 )) -> (( secs++ ))
 
Old 08-07-2010, 10:42 AM   #7
delta function
Member
 
Registered: Jul 2004
Posts: 51

Original Poster
Rep: Reputation: 20
Thumbs up

Thanks a lot for your help.

After quite some trail and error. I found the same solution with the "sentinel" file. First it would not work, but I discovered that I did not start the timer correct.

Now everything is working

Thanks a lot and now its time for good cup of coffee

Here is the script:
Code:
#!/bin/bash

## Settings
V_BITRATE=768

MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"

store_dir=./converted_files


#Check if we have files of interest in this directory
flv_files=$(ls -1 ./*.flv 2> /dev/null | wc -l)

function store_dir {	

	# create store directory to store the converted files	
	if [ -d $store_dir ]; then
		echo ""
	else 
		echo ""
		mkdir $store_dir
	fi
}

function timer {
secs=1
while (( $secs > 0 ))
do
    sleep 1
    if [ -f ./check ]; then
         rm -f ./check;
         break;
    fi
    printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
    secs=$(( $secs + 1 ))
done

}


function flv_to_xvid {

# Check if we have files to convert, otherwise print not found message
if [ $flv_files -ne 0 ]
then
# Start to convert the video files
for i in *.flv;do

	echo ""

	echo "Converting $i"

	timer & \

 	mencoder "$i" $MENC_OPTS -vf pp=lb -oac mp3lame -lameopts fast:preset=standard -o "${i%.flv}.avi" &>/dev/null 
	
	touch ./check
	
	echo -e "    [ Done ]"

	# move file to store directory
	mv "${i%.flv}.avi" $store_dir
done

else
	echo ""
	echo "No flv files in directory"
fi
}

function main_menu {

	echo -e "---------------------------------"
	echo -e "Convert Flash Movie Files to XVID"
	echo -e "---------------------------------"
	echo -e "FLV Files Found: [$flv_files]"
	echo -e "\n"
	echo -en "Convert file(s)? [Y]es [N]o: "
	read input

case $input in

	y)
		store_dir	
		flv_to_xvid
	;;
	n)
		exit 1
	;;
	esac
}

#start the script
main_menu

Last edited by delta function; 08-07-2010 at 10:45 AM.
 
Old 08-07-2010, 11:47 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Just thought you might like a little feedback (if not then please ignore post):

1. The word function is not transportable to all other systems.

2. main_menu obviously not required, but doesn't hurt.

3. In main_menu you ask for - [Y]es or [N]o (ie upper case Y or N) and yet your case is only testing for lower case

4. Also in main_menu, when selecting no you are exiting with a 1 which if passed to another program will be interpreted as an error???

5. store_dir is both a function and a variable

6. In function store_dir, pointless echo for true if ... just use not (!) to negate
Code:
if [ ! -d $store_dir ]; then
7. Timer function, $ not required inside (()) construct

8. flv_to_xvid function, again use (()) for testing numbers
Code:
if (( $flv_files != 0 ))
9. echo "" the same as plain echo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
flv video downloader issues mark_alfred Linux - Software 7 04-19-2010 01:03 AM
xine can't play avi(xvid), flv hottdogg Zenwalk 2 12-13-2009 06:01 AM
Here is how to FLV Flash Video in 2007 Spring Bill Lahr Mandriva 1 11-10-2008 01:07 AM
Howto convert an Xvid video to normal windows machine (no divX/xvid)? frenchn00b Linux - Software 1 10-01-2008 05:03 PM
Help embedding FLV flash video MicahCarrick Programming 3 07-24-2006 08:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration