Skip to content

Commit bb50bd1

Browse files
committed
Modify output resolution to even due to encoder only support even
resolution. And fixed core dump issue when running on some input odd resolutions. Signed-off-by: Xiaoxia Liang <[email protected]>
1 parent 97875b7 commit bb50bd1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

ffmpeg/vf_raisr.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ static int config_props_output(AVFilterLink *outlink)
211211

212212
outlink->w = inlink0->w * raisr->ratio;
213213
outlink->h = inlink0->h * raisr->ratio;
214+
// resolution of output needs to be even due to encoder support only even resolution
215+
outlink->w = outlink->w % 2 == 0 ? outlink->w : outlink->w - 1 ;
216+
outlink->h = outlink->h % 2 == 0 ? outlink->h : outlink->h - 1;
214217

215218
return 0;
216219
}
@@ -224,6 +227,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
224227
RNLERRORTYPE ret;
225228
VideoDataType vdt_in[3] = { 0 };
226229
VideoDataType vdt_out[3] = { 0 };
230+
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
227231

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

@@ -263,10 +267,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
263267
vdt_in[p].height = plane->height;
264268
vdt_in[p].step = in->linesize[p];
265269

270+
// Get horziontal and vertical power of 2 factors
271+
int vsub = p ? desc->log2_chroma_h : 0;
272+
int hsub = p ? desc->log2_chroma_w : 0;
273+
266274
// fill in the output video data type structure
267275
vdt_out[p].pData = out->data[p];
268-
vdt_out[p].width = plane->width * raisr->ratio;
269-
vdt_out[p].height = plane->height * raisr->ratio;
276+
// Determine the width and height of this plane/channel
277+
vdt_out[p].width = AV_CEIL_RSHIFT(out->width, hsub);
278+
vdt_out[p].height = AV_CEIL_RSHIFT(out->height, vsub);
270279
vdt_out[p].step = out->linesize[p];
271280
}
272281
if (raisr->framecount == 0)

ffmpeg/vf_raisr_opencl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "internal.h"
2626
#include "opencl.h"
2727
#include "libavutil/pixdesc.h"
28+
#include "video.h"
2829

2930
#define MIN_RATIO 1
3031
#define MAX_RATIO 2
@@ -109,8 +110,8 @@ static int raisr_opencl_filter_frame(AVFilterLink *inlink, AVFrame *input)
109110
vdt_in[p].bitShift = desc->comp[p].shift;
110111
// fill in the output video data type structure
111112
vdt_out[p].pData = output->data[p];
112-
vdt_out[p].width = input->width * ctx->ratio / wsub;
113-
vdt_out[p].height = input->height * ctx->ratio / hsub;
113+
vdt_out[p].width = output->width / wsub;
114+
vdt_out[p].height = output->height / hsub;
114115
vdt_out[p].step = output->linesize[p];
115116
vdt_out[p].bitShift = desc->comp[p].shift;
116117
}
@@ -195,6 +196,9 @@ static int raisr_opencl_config_output(AVFilterLink *outlink)
195196

196197
ctx->ocf.output_width = inlink->w * ctx->ratio;
197198
ctx->ocf.output_height = inlink->h * ctx->ratio;
199+
// resolution of output needs to be even due to encoder support only even resolution
200+
ctx->ocf.output_width = ctx->ocf.output_width % 2 == 0 ? ctx->ocf.output_width : ctx->ocf.output_width - 1;
201+
ctx->ocf.output_height = ctx->ocf.output_height % 2 == 0 ? ctx->ocf.output_height : ctx->ocf.output_height - 1;
198202

199203
err = ff_opencl_filter_config_output(outlink);
200204
if (err < 0)

0 commit comments

Comments
 (0)