I have a bash script that look out for files recursively under multi-sub folders, then use ffmpeg to each file. at debug, it works great if i use echo ffmpeg but the thing is, at real work where it actually needs to use ffmpeg and wait for half an hour to finish for each video, the bash script cannot successfully run the ffmpeg to each file
My snippet is below:
find * \( -name '*.mkv' -o -name '*avi' -o -name '*mp4' -o -name '*flv' -o -name '*ogg' -o -name '*mov' ! -name '*-[900p].mkv' \) -print |
while IFS= read file ## IFS= prevents "read" stripping whitespace
do
ffmpeg -i "$file" "$target" && rm -rf "$file"
done
the thing is, because ffmpeg takes too long to respond, and while would just keep listing and executing. So I'm hoping what can I do to make sure loop would be process only after the done has ended?
Can somebody please help? Thanks!
Geez, I do not know why it was tagged as possible duplicate with another question of mine: Converting `for file in` to `find` so that my script can apply recursively
I am asking for a loop action that would allow my bash script to wait for each function inside the loop to finish before iterating to the next object. It is very far from asking how to find files recursively. Thanks!
findto complete before the first call toffmpeghappens? As it is, the loop will wait forffmpegto complete before processing the next file, so it's not very clear what you are asking. – dhag Apr 16 '15 at 18:59find *(asterisk) ? Why do you need the-rwithrmto remove a file ? Andwhile..readis the worst option... Try something like:find . \( -name '*avi' -o -name .... \) -exec sh -c 'ffmpeg -i "$0" "${0%.*}.mkv" && rm -f "$0"' {} \;– don_crissti Apr 16 '15 at 19:15