<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: StemSplitter</title>
    <description>The latest articles on DEV Community by StemSplitter (@stemsplitter).</description>
    <link>https://dev.to/stemsplitter</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4269954%2Fa5cbe95e-0581-4aa5-ab8f-73100eae8faa.png</url>
      <title>DEV Community: StemSplitter</title>
      <link>https://dev.to/stemsplitter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stemsplitter"/>
    <language>en</language>
    <item>
      <title>How I Split a 60-Minute Recording into Four Stems with Demucs and FFmpeg</title>
      <dc:creator>StemSplitter</dc:creator>
      <pubDate>Sat, 28 Nov 2026 03:22:15 +0000</pubDate>
      <link>https://dev.to/stemsplitter/how-i-split-a-60-minute-recording-into-four-stems-with-demucs-and-ffmpeg-52pm</link>
      <guid>https://dev.to/stemsplitter/how-i-split-a-60-minute-recording-into-four-stems-with-demucs-and-ffmpeg-52pm</guid>
      <description>&lt;p&gt;Split an hour of audio into four chunks and give each pair of neighboring chunks a four-second overlap. Add up the lengths of those chunks, and you get &lt;strong&gt;60 minutes and 12 seconds&lt;/strong&gt;. Those extra 12 seconds are intentional. They give FFmpeg something to work with when it joins the pieces back together.&lt;/p&gt;

&lt;p&gt;I ran into this while building &lt;a href="https://stemsplitter.dev/" rel="noopener noreferrer"&gt;StemSplitter&lt;/a&gt;, a browser-based tool that separates mixed audio into vocals, drums, bass, and everything else. Here’s how I planned the chunks, joined the stems, and checked that all four exports lined up with the source duration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Route by duration
&lt;/h2&gt;

&lt;p&gt;The pipeline reads the audio duration with &lt;code&gt;ffprobe&lt;/code&gt;. Files up to 15 minutes go through one Demucs prediction. Longer files go through FFmpeg first, so they can be split into smaller inputs for the same model.&lt;/p&gt;

&lt;p&gt;Duration gives the job planner a consistent basis for routing. A WAV and an MP3 of the same recording can have very different file sizes while spanning the same amount of audio. The 15-minute cutoff is an application setting. In the long-file path, the overlap makes a full chunk up to &lt;strong&gt;15 minutes and 4 seconds&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Before slicing, the media worker converts the first audio stream to stereo, 44.1 kHz FLAC. All chunks then come from the same normalized source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give each join four seconds of shared audio
&lt;/h2&gt;

&lt;p&gt;For a 60-minute source, the chunk plan looks like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Chunk&lt;/th&gt;
&lt;th&gt;Start&lt;/th&gt;
&lt;th&gt;End&lt;/th&gt;
&lt;th&gt;Length&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;code&gt;00:00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15:04&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15:04&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15:00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;30:04&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15:04&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;code&gt;30:00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;45:04&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15:04&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;code&gt;45:00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;60:00&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15:00&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each chunk goes through Demucs independently. To rebuild the drums track, I take the drums output from each chunk, sort the pieces by their original position, and crossfade them in that order. Vocals, bass, and the &lt;code&gt;other&lt;/code&gt; stem follow the same process. &lt;a href="https://github.com/facebookresearch/demucs" rel="noopener noreferrer"&gt;Demucs model documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the FFmpeg operation for two adjacent pieces of the same stem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffmpeg -i drums-0.flac -i drums-1.flac \
  -filter_complex &lt;span class="s2"&gt;"[0:a][1:a]acrossfade=d=4:c1=tri:c2=tri[out]"&lt;/span&gt; \
  -map &lt;span class="s2"&gt;"[out]"&lt;/span&gt; drums-joined.flac
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During the four seconds shared by both inputs, one fades down while the other fades up. For four chunks, the worker chains three of these joins. Each join consumes one overlap, so the timeline comes back to &lt;code&gt;3612 − 3 × 4 = 3600&lt;/code&gt; seconds. &lt;a href="https://ffmpeg.org/ffmpeg-filters.html#acrossfade" rel="noopener noreferrer"&gt;FFmpeg &lt;code&gt;acrossfade&lt;/code&gt; documentation&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check every exported stem
&lt;/h2&gt;

&lt;p&gt;For the staging test, I checked the duration of each delivered file with &lt;code&gt;ffprobe&lt;/code&gt;. The pass condition was that all four outputs had to be within one second of the source.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; file &lt;span class="k"&gt;in&lt;/span&gt; vocals.mp3 drums.mp3 bass.mp3 other.mp3&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s '&lt;/span&gt; &lt;span class="s2"&gt;"$file"&lt;/span&gt;
  ffprobe -v error -show_entries &lt;span class="nv"&gt;format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;duration \
    -of &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;noprint_wrappers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1:nokey=1 &lt;span class="s2"&gt;"$file"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stem&lt;/th&gt;
&lt;th&gt;Duration in the staging run&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Vocals&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3600.000 s&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Drums&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3600.000 s&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bass&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3600.000 s&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Other&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3600.000 s&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This check catches timeline mistakes, such as accidentally keeping duplicated overlap or dropping a section. Listening answers a different question. A file can have the right duration and still have an audible change at a join. If I were comparing overlap lengths, I’d start with an exposed vocal or a sharp drum hit near a boundary, where a change is easier to hear. &lt;a href="https://ffmpeg.org/ffprobe.html" rel="noopener noreferrer"&gt;ffprobe documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The most useful part of this design was working out the output timeline on paper before wiring up inference. Once the chunk starts and overlap lengths were explicit, I knew what each exported file should measure and could check the final result with one command.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was drafted with AI assistance using the project’s implementation and staging notes.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>automation</category>
      <category>programming</category>
      <category>python</category>
      <category>tools</category>
    </item>
  </channel>
</rss>
