Referencing original Height and Width of input

Viewed 20

By combining scaling and cropping, the example script below scales/crops 30 pixels from each side of the input with the minimum loss of image.

In this example, 720 (original height) must be explicitly stated for the crop. If I use ih-60 instead of 720-60, ih will reference the height after the scale filter has been applied, not the original height of the source.

Is it possible to ignore the scale filter (and any other filtering) when referencing height and width.

    ffmpeg -i 1.mp4 -filter_complex [0]scale=iw-60:-1[S];[S]crop=iw:720-60 out.mp4
1 Answers

Work backwards to the original height from the input width and a (iw/ih):

  • the width is 60px less than the original: orig_w = iw+60
  • the scale filter maintains the aspect ratio so a is the same before and after the scale filter: orig_h = orig_w/a = (iw+60)/a

Thus, crop=iw:(iw+60)/a-60 should do the trick

Related