LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Batch file conversion command? the same command on all files in a folder ? (http://www.linuxquestions.org/questions/linux-general-1/batch-file-conversion-command-the-same-command-on-all-files-in-a-folder-835482/)

pete2222 09-30-2010 03:48 PM

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

bathory 09-30-2010 05:01 PM

Try the following (untested):
Code:

for i in ~/Videos/*.MOV; do ffmpeg -i $i -vcodec copy -acodec copy ~/Videos/`basename $i .MOV`.mp4; done

H_TeXMeX_H 10-01-2010 09:36 AM

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

pete2222 10-01-2010 04:38 PM

Quote:

Originally Posted by bathory (Post 4114138)
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.

H_TeXMeX_H 10-02-2010 08:01 AM

You're lucky, I've had huge problems getting anything to play properly on my PS3.

pete2222 10-02-2010 11:12 AM

Quote:

Originally Posted by H_TeXMeX_H (Post 4115601)
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.

dv502 10-02-2010 11:59 AM

"${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)


All times are GMT -5. The time now is 05:48 AM.