How do I convert a batch of avis into mp4s?

I have several avi files in the one directory that I would like to convert to mp4s using avconv. Now I know the basic procedure of how to do this, manually, for each avi, namely (where [email protected] are the variables that change with each new avi):

avconv -i [email protected] -c copy [email protected]

but I was wondering if anyone knows of how to write a bash script to do this automatically. I have tried a modified version of the answer provided to my optimizing PNG question namely:

for k in `find . -name "*.avi"`
do
   avconv -i "$k" -c copy "$k.mp4"
done

but as k is of the form ./filename avconv could not understand it when given as input. Another issue is that even though I used quotation marks, because many of my avis have spaces in their file names, for some reason avconv was being run for every space-separated word in the file’s name.

Answer

This should loop over all .avi files and convert them (untested):

printf '%s' *.avi | xargs -0 -I {} -P 1 avconv -i "{}" -c copy "{}".mp4

You can change -P 1 to e.g. -P 8 to convert 8 files in parallel.

Leave a Reply

Your email address will not be published. Required fields are marked *