title: Working with -filter_complex in ffmpeg with a batch concat array
body: <p>What I am trying to do here is write an ffmpeg script that takes all songs from a folder and combines them into one audio file using the command line in Windows.</p>
  
  <p>So far I have</p>
  
  <pre><code>ffmpeg -i "pathforinput1" -i "pathforinput2" -i "pathforinputn" -filter_complex "[0:0] [1:0] concat=n=(number of songs goes here):v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "output file.mp3"
  </code></pre>
  
  <p>My problem is that I want to combine it with the existing script:</p>
  
  <p><code>for %A in ("input folder\*.extension") do ffmpeg</code></p>
  
  <p>to create a total script that uses <code>-i "%A"</code> for the input. The problem I am having here is that each input file requires an entry in the array <code>-filter_complex "[0:0] [1:0]</code> as well as having the total number of input files present in <code>concat=n=(number of files)</code>. I' m willing to use a batch script to make this possible, but I can't see how I would go about finding the total number of files in a folder and then creating an array for each (for example if there were 7 songs the array would be <code>[0:0] [1:0] [2:0] [3:0] [4:0] [5:0] [6:0]</code>).</p>
  
  <p>Any help or pointers for making this possible would be great. Someone in <a href="https://stackoverflow.com/questions/19176295/ffmpeg-concat-batch-loop-with-text-file">this</a> question managed to make something similar for a Unix system but I am using batch files and I don't know how to modify it for Windows.</p>
  
  <p>Thanks in advance for any help</p>
  
  <p>Ok, progress made with the help of the first commenter. However, I think ffmpeg isn't liking what I've made. My code thus far is:</p>
  
  <pre><code>:: Give you a list of the .wav filenames in -i "filename1" -i "filename2" format
  
  for %%a in ("C:\Users\James\Input\*.*") do call set var=%%var%% -i "%%a"
  echo %var%
  
  :: Give you the number of .mp3 files
  
  for /f %%a in ('dir "C:\Users\James\Input\*.*" /b /a-d ^|find /c /v "" ') do set "numfiles=%%a"
  echo there are "%numfiles%" files
  set /a totalnum=numfiles
  
  :: dir "C:\Users\James\Input\" /b &gt;&gt; C:\Users\James\Output\filelist.txt
  :: print some text
  set /a numfiles=numfiles-1
  for /L %%b in (0,1,%numfiles%) do call set array=%%array%% [%%b:0]
  :: for /L %%b in (0,1,%numfiles%) do call set array=%%array%% [0:0]
  echo %array%
  for /f "tokens=* delims= " %%C in ('echo %array% ') do set array=%%C
  set array=%array:~0,-1%
  echo %array%
  :: for %%d in ("C:\Users\James\Input\*.*") do ffmpeg -i "%%d" -filter_complex "%array% concat=n=%totalnum%:v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "C:\Users\James\Output\outputtestbatch1.mp3"
  for %%d in ("C:\Users\James\Input\*.*") do ffmpeg -i "%%d" -filter_complex "%array% concat=n=%totalnum%:v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "C:\Users\James\Output\outputtestbatch1.mp3"
  pause`
  </code></pre>
  
  <p>The issue I am having now is that I think ffmpeg is assuming each input file has audio stream [0:0] rather than incrementing them one after the other. Is there a way to fix this with the input method I'm using?</p>
  
  <p><strong>SECOND EDIT</strong>L: Success! I modified foxidrive's script a bit because it was slightly misconfigured. Final product is here:</p>
  
  <pre><code>@echo off
  
  for %%a in ("C:\Users\James\Input\*.*") do call set var=%%var%% -i "%%a"
  :: echo %var%
  :: Give you the number of files
  
  for /f %%a in ('dir "C:\Users\James\Input\*.*" /b /a-d ^|find /c /v "" ') do set "numfiles=%%a"
  echo there are "%numfiles%" files
  
  for /L %%b in (0,%numfiles%) do call set array=%%array%% [%%b:0]
  set array=%array:~1%
  echo "%array%"
  
  ffmpeg %var% -filter_complex "%array% concat=n=%numfiles%:v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "C:\Users\James\Output\outputtestbatch1.mp3"
  
  popd    
  pause
  </code></pre>