Register
It is currently Wed Dec 17, 2014 2:09 pm

To convert a lot of video files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Sat Sep 11, 2010 12:38 pm   

Joined: Sat Sep 11, 2010 12:31 pm
Posts: 7
Location: Israel
Hello everybody,

I have the next problem, in my direcory Films I have a lot of uncompressed MOV files from my camera. Like this:
Code:
ls -la Video/
-rw-r--r--  1 booch booch      26544 2010-09-11 19:26 MVI_1968.MOV
-rw-r--r--  1 booch booch    6145196 2010-09-11 19:31 MVI_1969.MOV
-rw-r--r--  1 booch booch   21138344 2010-08-27 22:54 MVI_1970.MOV
-rw-r--r--  1 booch booch   10883512 2010-09-11 18:43 MVI_1971.MOV

...
But I have many files, hundreds.

I wrote this command to convert them:
Code:
ffmpeg -i MVI_1968.MOV -s 1440x900 -b 4000kb -vcodec mpeg4 -acodec libmp3lame -f avi movies_final.avi

Could you please to help to cover this simple command in a script. Just to start a script and it will convert all the *.MOV files in my current directory.
Thank you very much in advence.


Last edited by mothes on Sun Sep 12, 2010 11:10 am, edited 1 time in total.

Top
 Profile WWW ICQ  
 PostPosted: Sat Sep 11, 2010 2:40 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Code:
for mov in *.MOV; do
  avi=${mov//.MOV/.avi}
  [ -f "$avi" ] || ffmpeg -i "$mov" -s 1440x900 -b 4000kb -vcodec mpeg4 -acodec libmp3lame -f avi "$avi"
done


This will convert all *.MOV files in the current directory to an avi file of the same name if it doesn't exist yet. (if won't overwrite)


Top
 Profile  
 PostPosted: Sat Sep 11, 2010 3:14 pm   

Joined: Sat Sep 11, 2010 12:31 pm
Posts: 7
Location: Israel
Thank you very much, I did this script convert.sh

Code:
booch@alexlinux:~/Video/test$ cat convert2.sh
#!/bin/bash
#MOV to AVI

for mov in *.MOV; do
  avi=${mov//.MOV/.avi}
  [ -f "$avi" ] || ffmpeg -i "$mov" -s 1440x900 -b 4000kb -vcodec mpeg4 -acodec libmp3lame -f avi "$avi"
done

but I got this error:

Code:
booch@alexlinux:~/Video/test$ sh convert2.sh
convert2.sh: 7: Bad substitution


Code:
booch@alexlinux:~/Video/test$ ls -la
итого 47220
drwxr-xr-x 2 booch booch     4096 2010-09-12 00:11 .
drwxr-xr-x 6 booch booch     4096 2010-09-12 00:11 ..
-rwxr-xr-x 1 booch booch      180 2010-09-12 00:11 convert2.sh
-rwxr-xr-x 1 booch booch 48338644 2010-09-11 19:51 MVI_1968.MOV


What does it mean ? Do you know ?

The same error I got with another script like this, it's strange for me, the same error in two different scripts. What I did wrong? Can't understand :(

Code:
#!/bin/bash
#MOV to AVI

for fl in *.MOV
do
mencoder ${fl} -o ${fl/mov/avi} -oac mp3lame -ovc lavc
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile ${fl/mov/mp3} ${fl/mov/avi}
done


Top
 Profile WWW ICQ  
 PostPosted: Sun Sep 12, 2010 1:04 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
The variable substitution part ${var//from/to} is very bash specific.
You're starting your script with 'sh' and I think your 'sh' is not bash. (test this by doing a ls -l /bin/sh)
Since the first line of the scripts contain #!/bin/bash I suggest starting them like ./script.sh


Top
 Profile  
 PostPosted: Sun Sep 12, 2010 6:33 am   

Joined: Sat Sep 11, 2010 12:31 pm
Posts: 7
Location: Israel
I will come at home, and I will try. May be you are right. Because I use Terminator and not a standard terminal.


Top
 Profile WWW ICQ  
 PostPosted: Sun Sep 12, 2010 9:45 am   

Joined: Sat Sep 11, 2010 12:31 pm
Posts: 7
Location: Israel
Yep! You were completely right! Thanks a lot for the help!
I have this :
Code:
booch@alexlinux:~/Video/test$ ls -la /bin/sh
lrwxrwxrwx 1 root root 4 2010-06-19 20:09 /bin/sh -> dash

What is it dash, I don't know :(
But your script work well like this:
Code:
booch@alexlinux:~/Video/test$ ./convert2.sh

PS: I understand that /bin/sh -> dash it's symbol link, but the same result I have on my another computer. Strange.


Top
 Profile WWW ICQ  
 PostPosted: Sun Sep 12, 2010 10:28 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
dash is just another shell like bash, ksh, csh or any of the other shells that have been created over the years. It is also the default shell of Ubuntu for some time now. (since version 6.10). This is done to improve boot-up speed, because according to Ubuntu, dash has a smaller footprint and therefor load time than bash. Unfortunately it is not 100% bash compliant, which you have just seen.

As long as you stick with a bash sha-bang at the beginning of your scripts and run them as you do now, you'll be fine.


Top
 Profile  
 PostPosted: Sun Sep 12, 2010 11:08 am   

Joined: Sat Sep 11, 2010 12:31 pm
Posts: 7
Location: Israel
Yeahh, right, I use Ubuntu Linux.
Thanx a lot for inforamtion and for help. Now I will know. A little bit sorry, that dash is not 100% bash compliant with standart bash.
The problem is 100% closed.


Top
 Profile WWW ICQ  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP