3

I have a bunch of files which need to be converted from .mp4 to .mpeg.one. A friend of mine had suggested me this simple script. However it doesn't work because filenames contain blank spaces.

Here is the script:

for f in $(ls *.mp4); do ffmpeg -i "$f".mp4 "$f".mprg; done
1

3 Answers 3

11

You don't need to use ls in this case. As a general rule, always try to use shell builtins and glob features instead of relying on external programs (e.g. ls) that can introduce problems with ugly workarounds.

Also, you shouldn't 'manually' append the extension to the input file name (the one you give to -i) and you should strip the extension on the output file.

So the command should be:

for f in *.mp4; do ffmpeg -i "$f" "${f%.mp4}".mprg; done
1
  • Note that ffmpeg chooses the output container format depending on the extension. If you want another extension, you have to specify the container format - in this case with -f mpeg.
    – phoibos
    Feb 3, 2013 at 13:00
4

Instead of ls, you can use find -print0 and xargs -0:

find -name '*.mp4' -print0 | xargs -0 -n1 ffmpeg -i '{}' '{}'.mpeg

Followed by a rename afterwards:

rename s/mp4.mpeg$/mpeg/ *.mp4.mpeg
2
  • No ls needed
  • You probably mean .mpeg as extension
  • If you place the " right, spaces won't be aproblem
  • ffmpeg -i "$f".mp4 in your command will look for e.g. files.mp4.mp4, which you probably didn't mean
  • Be aware that your output files will be named e.g. files.mp4.mpeg

Possible solution:

for f in *.mp4; do ffmpeg -i "$f" "$f".mpeg; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .