Answers.Body: <p>You are feeding 21 seconds of audio from the video file and then applying <code>adelay=3000|3000</code>, hence 24 seconds. Add <code>atrim=end=21</code> at the end to both your audio filterchains.</p>
  
  <p><strong>And</strong></p>
  
  <p>Add <code>shortest=1</code> to both your overlays.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-15T01:03:32.367Z
Answers.Text: I still get the 24 seconds when I try that, even if I lower the seconds for atrim below 21.
Answers.UserDisplayName: HDL
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-15T02:07:43.737Z
Answers.Text: Works here. Where have you placed the atrim?
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-15T12:27:35.710Z
Answers.Text: [1:a]adelay=1000|1000,stereotools=muter=1,afade=t=in:st=1:d=2,afade=t=out:st=15:d=2,atrim=end=21[a1]; \
Answers.UserDisplayName: HDL
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-15T14:40:24.547Z
Answers.Text: Adding shortest worked and now the video properly ends after the background fades.  ffprobe and ffplay still report the duration as 20.98 instead of 21 (final encoded frame says 21 flat), but for all intents this gives the expected result.  Thanks for the help!
Answers.UserDisplayName: HDL
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-14T17:14:07.167Z
Answers.LastActivityDate: 2016-11-15T13:16:04.543Z
Answers.LastEditDate: 2016-11-15T13:16:04.543Z
Answers.UserDisplayName: Gyan
Body: <p>My goal is to take clips that last over 40 seconds and overlay them on a background, then trim the total time once the clips and background fade out.  It works great, except the seeking goes up to 24 seconds even when I specify 21.</p>
  
  <pre><code>ffmpeg -y -framerate 60 -loop 1 -ss 0 -t 21 -i ~/Desktop/FP2.tiff -ss 0 -t 21 -i ~/Desktop/fp.mov -lavfi \
  "[0]fade=t=in:st=0:d=1,fade=t=out:st=20:d=1,trim=end=21[bg]; \
  [1:v]setpts=(PTS-STARTPTS)+1/TB,fifo,fade=t=in:st=1:d=2,fade=t=out:st=15:d=2[fade]; \
  [bg][fade]overlay=10:(main_h-overlay_h)/2:format=rgb[v1]; \
  [1:v]setpts=(PTS-STARTPTS)+3/TB,fifo,fade=in:0:120,fade=t=out:st=18:d=2[v2]; \
  [v1][v2]overlay=460:(main_h-overlay_h)/2:format=rgb[video]; \
  [1:a]adelay=1000|1000,stereotools=muter=1,afade=t=in:st=1:d=2,afade=t=out:st=15:d=2[a1]; \
  [1:a]adelay=3000|3000,stereotools=mutel=1,afade=t=in:st=3:d=2,afade=t=out:st=18:d=2[a2]; \
  [a1][a2]amix=inputs=2[audio]" \
  -map [video] -map [audio] -c:v ffv1 -level 3 -c:a pcm_s16be ~/Desktop/filtergraph.nut
  </code></pre>
  
  <p>You can see this in ffplay; the background will fade completely by the 21 second mark, but the video itself ends at 24 seconds.  How do I get them to match exactly?  I'm aware I can use <code>-ss</code> and <code>-t</code> after the inputs, but that method can be slow if you intend to use a start point past 0.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-14T17:20:22.300Z
Comments.Text: *I'm aware I can use -ss and -t after the inputs* -> you can keep your current command and just **add** `-t 21` after the inputs.
Comments.UserDisplayName: Gyan
Tags: <video><ffmpeg><transcoding><filter>
Title: How do I remove excess video duration in ffmpeg when using lavfi?
UserDisplayName: HDL
ThreadText: # How do I remove excess video duration in ffmpeg when using lavfi?
  
  (Asked by: username_0 on 2016-11-14)
  
  My goal is to take clips that last over 40 seconds and overlay them on a background, then trim the total time once the clips and background fade out. It works great, except the seeking goes up to 24 seconds even when I specify 21.
  
  ```
  ffmpeg -y -framerate 60 -loop 1 -ss 0 -t 21 -i ~/Desktop/FP2.tiff -ss 0 -t 21 -i ~/Desktop/fp.mov -lavfi \
  "[0]fade=t=in:st=0:d=1,fade=t=out:st=20:d=1,trim=end=21[bg]; \
  [1:v]setpts=(PTS-STARTPTS)+1/TB,fifo,fade=t=in:st=1:d=2,fade=t=out:st=15:d=2[fade]; \
  [bg][fade]overlay=10:(main_h-overlay_h)/2:format=rgb[v1]; \
  [1:v]setpts=(PTS-STARTPTS)+3/TB,fifo,fade=in:0:120,fade=t=out:st=18:d=2[v2]; \
  [v1][v2]overlay=460:(main_h-overlay_h)/2:format=rgb[video]; \
  [1:a]adelay=1000|1000,stereotools=muter=1,afade=t=in:st=1:d=2,afade=t=out:st=15:d=2[a1]; \
  [1:a]adelay=3000|3000,stereotools=mutel=1,afade=t=in:st=3:d=2,afade=t=out:st=18:d=2[a2]; \
  [a1][a2]amix=inputs=2[audio]" \
  -map [video] -map [audio] -c:v ffv1 -level 3 -c:a pcm_s16be ~/Desktop/filtergraph.nut
  
  ```
  
  You can see this in ffplay; the background will fade completely by the 21 second mark, but the video itself ends at 24 seconds. How do I get them to match exactly? I'm aware I can use `-ss` and `-t` after the inputs, but that method can be slow if you intend to use a start point past 0.
  
  **Tags:** video, ffmpeg, transcoding, filter
  
  > **Comments:**
  > **username_1**: *I'm aware I can use -ss and -t after the inputs* -> you can keep your current command and just **add** `-t 21` after the inputs.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-14. Score: 1 | Accepted answer
  
  You are feeding 21 seconds of audio from the video file and then applying `adelay=3000|3000`, hence 24 seconds. Add `atrim=end=21` at the end to both your audio filterchains.
  
  **And**
  
  Add `shortest=1` to both your overlays.
  
  > **Comments:**
  > **username_0**: I still get the 24 seconds when I try that, even if I lower the seconds for atrim below 21.  
  > **username_1**: Works here. Where have you placed the atrim?  
  > **username_0**: [1:a]adelay=1000|1000,stereotools=muter=1,afade=t=in:st=1:d=2,afade=t=out:st=15:d=2,atrim=end=21[a1]; \  
  > **username_0**: Adding shortest worked and now the video properly ends after the background fades.  ffprobe and ffplay still report the duration as 20.98 instead of 21 (final encoded frame says 21 flat), but for all intents this gives the expected result.  Thanks for the help!  
  
  ---
  
  