I have this loop to find mp4 files that I want to convert to webm.
find "./$1" -type f -iname "*.mp4" | while IFS== read -r f; do
echo "found: $f"
fn=$( echo "$f" | rev | cut -d '.' -f 2- | rev )
fWebm="${fn}.webm"
#ffmpeg -i "$f" -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus "$fWebm"
if [ -f "$fWebm" ]; then
echo "removing $f"
#rm "$f"
else
echo "not removing $f"
fi
echo "Done."
done
If I uncomment the ffmpeg line then it converts the first video then quits.
Why?
How can I get it to continue with the rest of the files?
find | while readbreaks in surprising ways. That's why we usually strongly discourage doing that, and recommend usingfind … -exec …or, even better here, simply not using find but globbing; you can replace your wholefind … ; doline with a simpleshopt -s nullglob globstar nocaseglob; for f in **/*.mp4 ; do.fn=is creative, but a) should be in quotes"$(…)"(!) and b) settingshopt -s nocasematchat the beginning and doingfWebm="${f/%.mp4/.webm}is probably a bit easier on the mind of the reader.fn=$(foo)is exactly the same asfn="$(foo)", since a (scalar) assignment isn't subject to splitting and globbing anyway. (Barring bugs which e.g. Bash has had in some corner cases.)find | while read fis fine as long as the filenames are nice.find | while IFS= read -r fis better (it should pretty much leave newlines in filenames as the only issue). But settingIFS==seems odd, it would split on equal signs and that doesn't seem too useful here.