title: Cut multiple parts of a video with ffmpeg
body: <p>In what I'm trying to do, I need to remove some parts of a video file, and create a new one from that.</p>
  
  <p><strong>For example</strong>, from a video file like this:</p>
  
  <pre><code>===================
  </code></pre>
  
  <p>I make two cuts</p>
  
  <pre><code>======||=====||||==
  </code></pre>
  
  <p>and generate a new smaller video file:</p>
  
  <pre><code>=============
  </code></pre>
  
  <p>And when I say 2, I mean an arbitrary number of separate cuts, depending on the video file.</p>
  
  <p>If I wanted to cut just one part I would do:</p>
  
  <pre><code>ffmpeg -i video.mp4 -ss 00:00:03.500 -to 00:00:08.500 -async 1 cut.mp4 -y
  </code></pre>
  
  <p>Which works perfectly. I could perhaps do this many times and then join all the cuts together... But this is very inefficient for larger video files.</p>
  
  <p>To make two cuts I was looking at <strong>filter_complex</strong>. I've been trying to get it right for hours but I can't seem to get this working :/</p>
  
  <p>If I do something like this I get a video with no audio:</p>
  
  <pre class="lang-sh prettyprint-override"><code>command='ffmpeg -i video.mp4
                  -filter_complex "[0]trim=start_frame=10:end_frame=20[v0];
                                   [0]trim=start_frame=30:end_frame=40[v1];
                                   [v0][v1]concat=n=2[v5]"
                  -map [v5] -async 1 output.mp4'
  </code></pre>
  
  <p>If I try to do this, things get all messed up:</p>
  
  <pre class="lang-sh prettyprint-override"><code>ffmpeg -y -i video.mp4 
         -filter_complex "[0:v]trim=start_frame=10:end_frame=20[v0];
                          [0:a]atrim=start=10:end=20[a0];
                          [0:v]trim=start_frame=30:end_frame=40[v1];
                          [0:a]atrim=start=30:end=40[a1];
                          [v0][a0][v1][a1]concat=2:v=1:a=1[v5][a]" \
         -map [v5] -map [a] -async 1 output.mp4
  </code></pre>
  
  <p>I even trying to to this in Python with <strong>ffmpeg-python</strong> <a href="https://github.com/kkroening/ffmpeg-python" rel="noreferrer">https://github.com/kkroening/ffmpeg-python</a> but I also can't get audio to work.</p>
  
  <p>Can anyone give me some help on this?
  Thank you very much!!</p>