When running the following command line to convert multiple .mkv files into .mp4 files, things go awry. It's as if the script tries to run all the commands at once or they get entangled in each other somehow, and the output gets messy. I don't know exactly. When I ran this just now, only the first file was converted. Other times, I seem to get unexpected or random results.
ls -1 *.mkv | while read f; do ffmpeg -i "$f" -codec copy "${f%.*}.mp4"; done
However, if I do the following, things work as expected:
ls -1 *.mkv | while read f; do echo ffmpeg -i \"$f\" -codec copy \"${f%.*}.mp4\"; done > script; bash script
But why? What is it with ffmpeg
? This doesn't happen with bash loops and other commands than ffmpeg
. I'd like to do it a simple way without escaping quotes, piping to a script file, etc.
ls
output, especially towhile read
. Use thefor f in *.mkv; do...
construct. Oh, and btw, you don't need-1
when the output is a pipe. – don_crissti Nov 07 '15 at 21:40ls
for things like this, especially not media files whose names are very likely to contain strange characters and whitespace. That said, please [edit] your question and show us this messy output you speak of. What does it look like? We can't help unless you show us the actual problem. – terdon Nov 07 '15 at 22:31find . -name "*.aifc" | while read f; do ffmpeg -i $f...
-- ffmpeg was stripping characters off of the input filename and I couldn't figure out why! Using thefor
construct solved the problem. – bonh Jan 07 '17 at 17:03