Answers.Body: <p>The parallel processing is happening slow enough that FFmpeg is flushing frames in buffer for the first trimmed clip. You can use the fifo filter to avoid that. Also, you can use vstack and skip the nullsrc/overlay route.</p>
  
  <pre><code>ffmpeg -i input.avi -filter_complex "
      [0:v] trim=0:60, setpts=PTS-STARTPTS, fifo [v0];
      [0:v] trim=60:120, setpts=PTS-STARTPTS [v1];
      [v0][v1] vstack [out]" \
  -map "[out]" output.mkv
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-14T21:03:43.273Z
Answers.LastActivityDate: 2016-09-14T21:03:43.273Z
Answers.UserDisplayName: Gyan
Body: <p>I have one input file, and I want to extract the first minute and the second minute, and then recombine them so the first minute is on the top, and the second minute is on the bottom, playing simultaneously.</p>
  
  <p>I cobbled this together, but for some reason, the upper clip freezes after a few seconds, while the bottom clip continues as expected. The input file has the resolution 640x352.</p>
  
  <pre><code>ffmpeg -i input.avi -filter_complex "
      nullsrc=size=640x704:duration=60 [base];
      [0:v] trim=0:60, setpts=PTS-STARTPTS [v0];
      [0:v] trim=60:120, setpts=PTS-STARTPTS [v1];
      [base][v0] overlay=x=0:y=0 [t1];
      [t1][v1] overlay=x=0:y=352 [out]" \
  -map "[out]" output.mkv
  </code></pre>
  
  <p>I suspect this is a problem internally in ffmpeg, and I have to first extract the two clips into separate input files.</p>
  
Tags: <ffmpeg>
Title: Using ffmpeg, how do I trim and overlay two different time periods from the same input?
UserDisplayName: stefansundin
ThreadText: # Using ffmpeg, how do I trim and overlay two different time periods from the same input?
  
  (Asked by: username_0 on 2016-09-14)
  
  I have one input file, and I want to extract the first minute and the second minute, and then recombine them so the first minute is on the top, and the second minute is on the bottom, playing simultaneously.
  
  I cobbled this together, but for some reason, the upper clip freezes after a few seconds, while the bottom clip continues as expected. The input file has the resolution 640x352.
  
  ```
  ffmpeg -i input.avi -filter_complex "
      nullsrc=size=640x704:duration=60 [base];
      [0:v] trim=0:60, setpts=PTS-STARTPTS [v0];
      [0:v] trim=60:120, setpts=PTS-STARTPTS [v1];
      [base][v0] overlay=x=0:y=0 [t1];
      [t1][v1] overlay=x=0:y=352 [out]" \
  -map "[out]" output.mkv
  
  ```
  
  I suspect this is a problem internally in ffmpeg, and I have to first extract the two clips into separate input files.
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-14. Score: 1 | Accepted answer
  
  The parallel processing is happening slow enough that FFmpeg is flushing frames in buffer for the first trimmed clip. You can use the fifo filter to avoid that. Also, you can use vstack and skip the nullsrc/overlay route.
  
  ```
  ffmpeg -i input.avi -filter_complex "
      [0:v] trim=0:60, setpts=PTS-STARTPTS, fifo [v0];
      [0:v] trim=60:120, setpts=PTS-STARTPTS [v1];
      [v0][v1] vstack [out]" \
  -map "[out]" output.mkv
  
  ```
  
  
  ---
  
  