Answers.Body: <p>It is possible to use the <code>select</code> filter to select scenes for stabilisation and inclusion into the final result - see the example below. It seems that <code>select</code> is slow for skipping over unwanted material. This does not create any intermediate files except the <code>*.trf</code> file. In my example I am not using audio, which would have to be selected likewise. </p>
  
  <pre><code>#! /bin/bash
  
  f="20191128_215245A.mp4"
  x="select='between(t,5,10)+between(t,15,20)',setpts=N/FRAME_RATE/TB"
  s="vidstabdetect=stepsize=6:shakiness=6:accuracy=9:result=foo.trf"
  y="vidstabtransform=input=foo.trf:zoom=1:maxangle=(1*PI/180):smoothing=30"
  z="scale=1440:-2,unsharp=5:5:0.8:3:3:0.4"
  a="-an -tune film -r 60 -crf 26 -vcodec libx264 -preset slow"
  
  ffmpeg -y -i $f -vf "$x,$s" -f null -
  ffmpeg -y -i $f -vf "$x,$y,$z" $a foo.mp4
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-30T19:41:42.920Z
Answers.LastActivityDate: 2019-12-01T12:08:28.343Z
Answers.LastEditDate: 2019-12-01T12:08:28.343Z
Answers.UserDisplayName: Christian Lindig
Body: <p>I'm using ffmpeg's <code>vidstabdetect</code> and <code>vidstabtransform</code> filter to stabilise videos. Currently I first cut out the scenes from the single input that I want to stabilise into individual files, which I then stabilise, transform, and join together. To avoid creating these intermediate files, is it possible to:</p>
  
  <ul>
  <li>specify multiple time ranges to stabilise;</li>
  <li>create the necessary <code>*.trf</code> file(s) in a first pass;</li>
  <li>stabilise (transform) the time ranges from the input in a second pass and create a single output file containing just the stabilised scenes</li>
  </ul>
  
  <p>without creating intermediate files beyond the <code>*.trf</code> file(s)? I am asking because I am not sure that the <code>*.trf</code> files can deal with non-continuous scenes.</p>
  
  <p>What would be the right flag to specify the time ranges to stabilise and join?</p>
  
  <p>Current workflow to extract and stabilise a scene from <code>foo.mp4</code>:</p>
  
  <pre><code>$ ffmpeg -v error -y -ss 00:00:00 -to 00:01:00 -i foo.mp4 -c copy foo-000000-000100.mp4
  
  $ ffmpeg -y -v error -i foo-000000-000100.mp4 -vf vidstabdetect=stepsize=6:shakiness=6:accuracy=9:result=foo-000000-000100.trf -f null -
  
  $ ffmpeg -v error -y -i foo-000000-000100.mp4 -vf vidstabtransform=input=foo-000000-000100.trf:zoom=1:maxangle=(1*PI/180):smoothing=30,rotate=(0.0*PI/180):ow=1920:oh=1080,scale=1440:-2,unsharp=5:5:0.8:3:3:0.4,drawtext=fontfile=din.ttf:fontcolor=0x55b575:fontsize=18:x=w-tw-10:y=h-th-10:timecode='00\:00\:00\:00':rate=60,drawtext=fontfile=din.ttf:fontcolor=0x55b575:fontsize=18:x=10:y=h-th-10:text='foo' -vcodec libx264 -preset slow -tune film -an -r 60 -crf 26 foo-000000-000100.stab.mp4
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-26T16:07:37.060Z
Comments.Text: You could avoid the intermediate files created in step 1 and used in step 2 but not in step 3.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-26T19:55:49.557Z
Comments.Text: My goal would be to take, say 3, scenes from a file, create in the first pass one '*.trf', and use that in the second pass to stabilise the scenes and extract them (joined up) into a final output file.
Comments.UserDisplayName: Christian Lindig
Tags: <ffmpeg><stabilisation>
Title: ffmpeg: using vidstab{detect,transform} on parts of a video
UserDisplayName: Christian Lindig
ThreadText: # ffmpeg: using vidstab{detect,transform} on parts of a video
  
  (Asked by: username_0 on 2019-11-26)
  
  I'm using ffmpeg's `vidstabdetect` and `vidstabtransform` filter to stabilise videos. Currently I first cut out the scenes from the single input that I want to stabilise into individual files, which I then stabilise, transform, and join together. To avoid creating these intermediate files, is it possible to:
  
  * specify multiple time ranges to stabilise;
  * create the necessary `*.trf` file(s) in a first pass;
  * stabilise (transform) the time ranges from the input in a second pass and create a single output file containing just the stabilised scenes
  
  without creating intermediate files beyond the `*.trf` file(s)? I am asking because I am not sure that the `*.trf` files can deal with non-continuous scenes.
  
  What would be the right flag to specify the time ranges to stabilise and join?
  
  Current workflow to extract and stabilise a scene from `foo.mp4`:
  
  ```
  $ ffmpeg -v error -y -ss 00:00:00 -to 00:01:00 -i foo.mp4 -c copy foo-000000-000100.mp4
  
  $ ffmpeg -y -v error -i foo-000000-000100.mp4 -vf vidstabdetect=stepsize=6:shakiness=6:accuracy=9:result=foo-000000-000100.trf -f null -
  
  $ ffmpeg -v error -y -i foo-000000-000100.mp4 -vf vidstabtransform=input=foo-000000-000100.trf:zoom=1:maxangle=(1*PI/180):smoothing=30,rotate=(0.0*PI/180):ow=1920:oh=1080,scale=1440:-2,unsharp=5:5:0.8:3:3:0.4,drawtext=fontfile=din.ttf:fontcolor=0x55b575:fontsize=18:x=w-tw-10:y=h-th-10:timecode='00\:00\:00\:00':rate=60,drawtext=fontfile=din.ttf:fontcolor=0x55b575:fontsize=18:x=10:y=h-th-10:text='foo' -vcodec libx264 -preset slow -tune film -an -r 60 -crf 26 foo-000000-000100.stab.mp4
  
  ```
  
  **Tags:** ffmpeg, stabilisation
  
  > **Comments:**
  > **username_1**: You could avoid the intermediate files created in step 1 and used in step 2 but not in step 3.  
  > **username_0**: My goal would be to take, say 3, scenes from a file, create in the first pass one '*.trf', and use that in the second pass to stabilise the scenes and extract them (joined up) into a final output file.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-11-30. Score: 1 | Accepted answer
  
  It is possible to use the `select` filter to select scenes for stabilisation and inclusion into the final result - see the example below. It seems that `select` is slow for skipping over unwanted material. This does not create any intermediate files except the `*.trf` file. In my example I am not using audio, which would have to be selected likewise.
  
  ```
  #! /bin/bash
  
  f="20191128_215245A.mp4"
  x="select='between(t,5,10)+between(t,15,20)',setpts=N/FRAME_RATE/TB"
  s="vidstabdetect=stepsize=6:shakiness=6:accuracy=9:result=foo.trf"
  y="vidstabtransform=input=foo.trf:zoom=1:maxangle=(1*PI/180):smoothing=30"
  z="scale=1440:-2,unsharp=5:5:0.8:3:3:0.4"
  a="-an -tune film -r 60 -crf 26 -vcodec libx264 -preset slow"
  
  ffmpeg -y -i $f -vf "$x,$s" -f null -
  ffmpeg -y -i $f -vf "$x,$y,$z" $a foo.mp4
  
  ```
  
  
  ---
  
  