LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-30-2010, 03:48 PM   #1
pete2222
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Rep: Reputation: 0
Batch file conversion command? the same command on all files in a folder ?


Hi

I just learnt to convert a video file into mp4 format so I can watch it on my PS3. However, I have dozens of video files from my video cam, and want to convert them all. They are all in the same folder. Please can someone explain how I might be able to adapt the code below so I can convert all my files in a batch. Perhaps keeping their same name or giving them some other name, I don't mind.
Thanks for you help

ffmpeg -i ~/Videos/121_0526.MOV -vcodec copy -acodec copy ~/Videos/121_0526.mp4
 
Old 09-30-2010, 05:01 PM   #2
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,895

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Try the following (untested):
Code:
for i in ~/Videos/*.MOV; do ffmpeg -i $i -vcodec copy -acodec copy ~/Videos/`basename $i .MOV`.mp4; done
 
Old 10-01-2010, 09:36 AM   #3
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Just to comment that the back ticks are out of style (they can confuse). Use '$()' instead. Also make sure to quote properly or it may have problems if files have spaces in their names.

Code:
for i in *.MOV; do ffmpeg -i "$i" -vcodec copy -acodec copy "$(basename "$i" .MOV).mp4"; done
 
Old 10-01-2010, 04:38 PM   #4
pete2222
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by bathory View Post
Try the following (untested):
Code:
for i in ~/Videos/*.MOV; do ffmpeg -i $i -vcodec copy -acodec copy ~/Videos/`basename $i .MOV`.mp4; done
Thanks very much, this worked great. It was really easy to convert multiple files with this and they seem to play back fine on the ps3.
 
Old 10-02-2010, 08:01 AM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
You're lucky, I've had huge problems getting anything to play properly on my PS3.
 
Old 10-02-2010, 11:12 AM   #6
pete2222
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by H_TeXMeX_H View Post
You're lucky, I've had huge problems getting anything to play properly on my PS3.
I just used this today to convert 30GB/~400 HD clips, just with the one command. They all went from .MOV to MP4. I have put them onto my PS3 now, and they are playing great.. so yes, I must be lucky!!! FYI, the clips were taken using a Kodak ZX1.
 
Old 10-02-2010, 11:59 AM   #7
dv502
Member
 
Registered: Sep 2006
Location: USA - NYC
Distribution: Whatever icon you see!
Posts: 642

Rep: Reputation: 57
"${i%.*}.mp4"

The brace expansion above will work with any file(s) extension regardless of case and the quotes are for files with or without spaces in them.

for i in ~/Videos/*.[Mm][Oo][Vv]; do ffmpeg -i "$i" -vcodec copy -acodec copy ~/Videos/"${i%.*}.mp4"; done

The wildcard in the brace expansion represents the file extension regardless of case (i.e MOV, mov, Mov, etc)

Last edited by dv502; 10-02-2010 at 12:34 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which command line command for updating a folder craig_panama Linux - Software 6 06-28-2009 08:11 PM
Help me...after used mv command all file missing only folder move to new path scoreone1 Linux - General 9 10-20-2008 11:22 PM
Command to forward files to folder TubeScreamer Linux - Newbie 3 08-03-2005 02:57 PM
Trigger linux command by windows batch file? mariusak Linux - Networking 6 06-03-2005 05:15 AM
rename file/folder command hct224 Linux - Newbie 4 09-19-2003 09:44 AM


All times are GMT -5. The time now is 03:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration