[x265] [PATCH] cli: refactor handling of input file parameters

Steve Borho steve at borho.org
Tue Feb 25 18:41:38 CET 2014


On Tue, Feb 25, 2014 at 10:43 AM, dave <dtyx265 at gmail.com> wrote:
> On 02/25/2014 08:00 AM, Steve Borho wrote:
>
> # HG changeset patch
> # User Steve Borho <steve at borho.org>
> # Date 1393303499 21600
> #      Mon Feb 24 22:44:59 2014 -0600
> # Node ID 651c0bc9e280282de1d1c9975d25fa34de7b25ef
> # Parent  5e375c097de471c3824fd5ce3568325de746fa78
> cli: refactor handling of input file parameters
>
> * allow y4m header to provide aspect ratio
> * allow user to override Y4M aspect ratio or frame rate
> * allow user to provide data possibly missing from Y4M header
> * do not clamp framesToBeEncoded to predicted file size (stop at EOF)
>
> diff -r 5e375c097de4 -r 651c0bc9e280 source/common/param.cpp
> --- a/source/common/param.cpp Mon Feb 24 23:22:55 2014 -0600
> +++ b/source/common/param.cpp Mon Feb 24 22:44:59 2014 -0600
> @@ -671,6 +671,65 @@
>  namespace x265 {
>  // internal encoder functions
>
> +static const int fixedRatios[][2] =
> +{
> +    { 1,  1 },
> +    { 12, 11 },
> +    { 10, 11 },
> +    { 16, 11 },
> +    { 40, 33 },
> +    { 24, 11 },
> +    { 20, 11 },
> +    { 32, 11 },
> +    { 80, 33 },
> +    { 18, 11 },
> +    { 15, 11 },
> +    { 64, 33 },
> +    { 160, 99 },
> +    { 4, 3 },
> +    { 3, 2 },
> +    { 2, 1 },
> +};
>
>
> This array is off by one.  aspect_ratio_idc = 0 is valid and signifies an
> unspecified sar.

I believe I handled that correctly in the set/get functions.  If
aspectRatioIdc was 0, it returns height = width = 0, otherwise it
decrements the idc before indexing into the array.

>
> +void setParamAspectRatio(x265_param *p, int width, int height)
> +{
> +    p->bEnableVuiParametersPresentFlag = 1;
> +    p->bEnableAspectRatioIdc = 1;
> +    p->aspectRatioIdc = X265_EXTENDED_SAR;
> +    p->sarWidth = width;
> +    p->sarHeight = height;
> +    for (size_t i = 0; i < sizeof(fixedRatios) / sizeof(fixedRatios[0]);
> i++)
> +    {
> +        if (width == fixedRatios[i][0] && height == fixedRatios[i][1])
> +        {
> +            p->aspectRatioIdc = (int)i + 1;
> +            return;
> +        }
> +    }
> +}
> +
> +void getParamAspectRatio(x265_param *p, int& width, int& height)
> +{
> +    if (!p->bEnableVuiParametersPresentFlag || !p->bEnableAspectRatioIdc ||
> !p->aspectRatioIdc)
> +    {
> +        width = height = 0;
> +    }
> +    else if ((size_t)p->aspectRatioIdc <= sizeof(fixedRatios) /
> sizeof(fixedRatios[0]))
> +    {
> +        width  = fixedRatios[p->aspectRatioIdc - 1][0];
> +        height = fixedRatios[p->aspectRatioIdc - 1][1];
> +    }
> +    else if (p->aspectRatioIdc == X265_EXTENDED_SAR)
> +    {
> +        width  = p->sarWidth;
> +        height = p->sarHeight;
> +    }
> +    else
> +    {
> +        width = height = 0;
> +    }
> +}
> +

-- 
Steve Borho


More information about the x265-devel mailing list