ffmpeg bash loop filenames truncated

Problem

When using ffmpeg in a loop to operate on many files, the filename variable may become truncated (usually from the front) because of the way ffmpeg handles EOF processing.

Example:

ls "${DIR}" | while read FILE; do
    ffmpeg -i "${FILE}" "${OUTPUT}"
done

In this case, after the first iteration of the loop, the $FILE variable containing the name of the second file will be truncated, resulting in a file not found error at best.

Solution

The solution is to read from /dev/null from stdin while running ffmpeg to give it an EOF (end-of-file):

Example:

ls "${DIR}" | while read FILE; do
    ffmpeg -i "${FILE}" "${OUTPUT}" < /dev/null
done