Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ ffmpeg -init_hw_device vaapi=va -init_hw_device qsv=qs@va -init_hw_device opencl
ffmpeg -init_hw_device vaapi=va -init_hw_device opencl=ocl@va -hwaccel vaapi -hwaccel_output_format vaapi -i input.264 -vf "hwmap=derive_device=opencl,format=opencl,raisr_opencl,hwmap=derive_device=vaapi:reverse=1:extra_hw_frames=16" -c:v hevc_vaapi output.mp4
```

**Even output**

There are certain codecs that support only even resolution, the `evenoutput` parameter will support users to choose whether to make the output an even number

Set `evenoutput=1` to make output size as even number, the following command will get 632x632 output.
```
ffmpeg -i input.mp4 -an -vf scale=422x422,raisr=ratio=1.5:filterfolder=filters_1.5x/filters_highres:threadcount=1:evenoutput=1 output.mp4
```
It will keep the output resolution as the input resolution multiply by the upscaling ratio if set `evenoutput=0` or not set the parameter, will get 633x633 output with 422x422 input.

## To see help on the RAISR filter
`./ffmpeg -h filter=raisr`
Expand All @@ -89,6 +98,7 @@ ffmpeg -init_hw_device vaapi=va -init_hw_device opencl=ocl@va -hwaccel vaapi -hw
asm <string> ..FV....... x86 asm type: (avx512fp16, avx512, avx2 or opencl) (default "avx512fp16")
platform <int> ..FV....... select the platform (from 0 to INT_MAX) (default 0)
device <int> ..FV....... select the device (from 0 to INT_MAX) (default 0)
evenoutput <int> ..FV....... make output size as even number (0: ignore, 1: subtract 1px if needed) (from 0 to 1) (default 0)


# How to Contribute
Expand Down
18 changes: 16 additions & 2 deletions ffmpeg/vf_raisr.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct RaisrContext
struct plane_info inplanes[3];
int nb_planes;
int framecount;
int evenoutput;
} RaisrContext;

#define OFFSET(x) offsetof(RaisrContext, x)
Expand All @@ -89,6 +90,7 @@ static const AVOption raisr_options[] = {
{"asm", "x86 asm type: (avx512fp16, avx512, avx2 or opencl)", OFFSET(asmStr), AV_OPT_TYPE_STRING, {.str = "avx512fp16"}, 0, 0, FLAGS},
{"platform", "select the platform", OFFSET(platform), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
{"device", "select the device", OFFSET(device), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS},
{"evenoutput", "make output size as even number (0: ignore, 1: subtract 1px if needed)", OFFSET(evenoutput), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
{NULL}};

AVFILTER_DEFINE_CLASS(raisr);
Expand Down Expand Up @@ -212,6 +214,12 @@ static int config_props_output(AVFilterLink *outlink)
outlink->w = inlink0->w * raisr->ratio;
outlink->h = inlink0->h * raisr->ratio;

// resolution of output needs to be even due to some encoders support only even resolution
if (raisr->evenoutput == 1) {
outlink->w -= outlink->w % 2;
outlink->h -= outlink->h % 2;
}

return 0;
}

Expand All @@ -224,6 +232,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
RNLERRORTYPE ret;
VideoDataType vdt_in[3] = { 0 };
VideoDataType vdt_out[3] = { 0 };
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);

av_log(ctx, AV_LOG_VERBOSE, "Frame\n");

Expand Down Expand Up @@ -263,10 +272,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
vdt_in[p].height = plane->height;
vdt_in[p].step = in->linesize[p];

// Get horziontal and vertical power of 2 factors
int vsub = p ? desc->log2_chroma_h : 0;
int hsub = p ? desc->log2_chroma_w : 0;

// fill in the output video data type structure
vdt_out[p].pData = out->data[p];
vdt_out[p].width = plane->width * raisr->ratio;
vdt_out[p].height = plane->height * raisr->ratio;
// Determine the width and height of this plane/channel
vdt_out[p].width = AV_CEIL_RSHIFT(out->width, hsub);
vdt_out[p].height = AV_CEIL_RSHIFT(out->height, vsub);
vdt_out[p].step = out->linesize[p];
}
if (raisr->framecount == 0)
Expand Down
11 changes: 9 additions & 2 deletions ffmpeg/vf_raisr_opencl.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "internal.h"
#include "opencl.h"
#include "libavutil/pixdesc.h"
#include "video.h"

#define MIN_RATIO 1
#define MAX_RATIO 2
Expand All @@ -42,6 +43,7 @@ typedef struct RaisrOpenCLContext {
int mode;
RangeType range;
enum AVPixelFormat sw_format;
int evenoutput;
} RaisrOpenCLContext;


Expand Down Expand Up @@ -109,8 +111,8 @@ static int raisr_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
vdt_in[p].bitShift = desc->comp[p].shift;
// fill in the output video data type structure
vdt_out[p].pData = output->data[p];
vdt_out[p].width = input->width * ctx->ratio / wsub;
vdt_out[p].height = input->height * ctx->ratio / hsub;
vdt_out[p].width = output->width / wsub;
vdt_out[p].height = output->height / hsub;
vdt_out[p].step = output->linesize[p];
vdt_out[p].bitShift = desc->comp[p].shift;
}
Expand Down Expand Up @@ -195,6 +197,10 @@ static int raisr_opencl_config_output(AVFilterLink *outlink)

ctx->ocf.output_width = inlink->w * ctx->ratio;
ctx->ocf.output_height = inlink->h * ctx->ratio;
if (ctx->evenoutput == 1) {
ctx->ocf.output_width -= ctx->ocf.output_width % 2;
ctx->ocf.output_height -= ctx->ocf.output_height % 2;
}

err = ff_opencl_filter_config_output(outlink);
if (err < 0)
Expand Down Expand Up @@ -225,6 +231,7 @@ static const AVOption raisr_opencl_options[] = {
{ "CountOfBitsChanged", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CountOfBitsChanged }, INT_MIN, INT_MAX, FLAGS, "blending" },
{"passes", "passes to run (1: one pass, 2: two pass)", OFFSET(passes), AV_OPT_TYPE_INT, {.i64 = 1}, 1, 2, FLAGS},
{"mode", "mode for two pass (1: upscale in 1st pass, 2: upscale in 2nd pass)", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = 1}, 1, 2, FLAGS},
{"evenoutput", "make output size as even number (0: ignore, 1: subtract 1px if needed)", OFFSET(evenoutput), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS},
{NULL}
};

Expand Down
Loading