How do I convert a batch of avis into mp4s? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How do I convert a batch of avis into mp4s? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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 $@ are the variables that change with each new avi):

avconv -i $@.avi -c copy $@.mp4

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.

We are here to answer your question about How do I convert a batch of avis into mp4s? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji