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
  • You could avoid the intermediate files created in step 1 and used in step 2 but not in step 3.
    – Gyan
    Nov 26, 2019 at 16:07
  • 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. Nov 26, 2019 at 19:55

1 Answer 1


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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.