Opened 9 years ago

Closed 9 years ago

#325 closed enhancement (fixed)

Aspect Ratio of input Video required to e.g. automatically add correct letterbox/pillarbox when rescaling video

Reported by: Pae8uuW5 Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: yes


When converting videos of unknown size and aspect ratio, one needs to know the aspect ratio of the source video to calculate the size of letterbox or pillarbox bars to be added (if any). For source videos with non square pixels, a alone, which is just in_w/in_h, is insufficient. The trivial patch enclosed below adds a new variable "d" (rename as you like) to represent the input sample aspect ratio. With this, one can use a simple chain of a scale and a pad filter to always add correct pillar/letterboxes.

Attachments (1)

aspect_variable.patch (1.9 KB) - added by Pae8uuW5 9 years ago.
patch to add "d" variable containing the source sample aspect ratio

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by Pae8uuW5

patch to add "d" variable containing the source sample aspect ratio

comment:1 Changed 9 years ago by saste

  • Analyzed by developer set


I committed a variant of your patches in:

commit 0bf02fb1ea57962b97fb3ffc7c827d4b12e439f3
Author: Stefano Sabatini <>
Date:   Sat Jul 2 17:31:18 2011 +0200

    vf_pad: add support for a "sar" variable
    Also add a "dar" alias for "a", for avoiding confusion with sar/dar.

commit 01151a26c03c5df85509150d393e039f574d005f
Author: Stefano Sabatini <>
Date:   Sat Jul 2 17:27:31 2011 +0200

    vf_scale: add a "sar" variable
    Also create a "dar" alias for the "a" variable, for avoiding possible
    confusion between dar/sar.

And I'm planning to do the same to the crop filter.
Please test and report if it works fine for you. Also state if you want this change to be included in 0.7/0.8, and I'll see what I can do for it.

comment:2 Changed 9 years ago by Pae8uuW5

Tested and working as intended for my test cases. I've just started the switch to ffmpeg 0.8, so including this in just the 0.8 branch would be sufficient for me.

I'm quite confused as to what dar and sar are actually supposed to mean, the common usage appears to be different from your implementation, see e.g. the output of ffmpeg 0.8 below:

Stream #0.0(und): Video: h264 (Constrained Baseline), yuv420p, 512x1080 [PAR 135:64 DAR 1:1], 72 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc

comment:3 Changed 9 years ago by saste

  • Resolution set to fixed
  • Status changed from new to closed
  • Version changed from 0.8 to git-master

The a/dar mismatch was fixed in git-master:

commit 61d55fda2b513caf18e37b27aba680a87840904a
Author: Stefano Sabatini <>
Date:   Wed Jul 27 10:58:24 2011 +0200

    lavfi: tweak display aspect ratio variables in pad and scale filters
    Previously, "dar" and "a" were documented like "input display aspect
    ratio", but their actual value was "in_w/in_h".
    In order to avoid to break scripts which rely on the "a" variable, the
    patch keeps the same semantics but fixes the corresponding docs, and
    fixes the semantics of the recently added "dar" variable, which
    now correctly expresses the input Display Aspect Ratio value as
Note: See TracTickets for help on using tickets.