This is an old question and unfortunately there's no code to point the problem for sure. But getting ENAMETOOLONG from ffmpeg on Windows usually means the command is really too long. And merging thousands of files makes this seem quite natural.
It still happens now in 2020. But one can work this around. We need to put the source filenames (for merger) into a text file and provide this text file as an input to ffmpeg.
A raw ffmpeg call would look like:
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.wav
with mylist.txt being like:
file '/path/to/file1.wav'
file '/path/to/file2.wav'
file '/path/to/file3.wav'
With fluent-ffmpeg it's not intuitive but still feasible:
const cmd = ffmpeg();
cmd.input('mylist.txt')
.inputOption(['-f concat', '-safe 0'])
.output('out.wav')
.run();
Note: Be careful with absolute paths of the list file and source files inside the list on Windows. Most ffmpeg versions would add the directory of the list to the source file resulting in similar corrupted path:
c:/ffmpeg/lists/c:/audiofiles/file1.wav
But you still can solve this if you go with url-formatted source files:
file 'file:c:/audiofiles/file1.wav'
file 'file:c:/audiofiles/file2.wav'
file 'file:c:/audiofiles/file3.wav'
I'm sure this will be helpful to someone searching for this ffmpeg error :-)