[FFmpeg-devel] [GSOC] [PATCH] SRCNN filter

Michael Niedermayer michael at niedermayer.cc
Tue Mar 27 20:39:17 EEST 2018


On Sun, Mar 25, 2018 at 08:04:17PM +0300, Sergey Lavrushkin wrote:
> Hello,
> 
> This is my implementation of qualification task for GSOC Super Resolution
> Filter project.
> For default x2 upsampling with provided srcnn filter following command can
> be used:
> ffmpeg -i input -vf scale=iw*2:-1,srcnn output
> Also other models for x2, x3, x4 upsampling can be specified using
> following command:
> ffmpeg -i input -vf scale=iw*factor:-1,srcnn=path_to_model output
> Configuration files with other models can be found here:
> https://drive.google.com/drive/folders/1-M9azWTtZ4egf8ndRU7Y
> _tiGP6QtN-Fp?usp=sharing
> And here are some examples of its work:
> https://drive.google.com/drive/folders/1jMVMKnre2KG0avq2zNw6
> CMqUKdPWnlQo?usp=sharing

[...]
> +#define OFFSET(x) offsetof(SRCNNContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
> +static const AVOption srcnn_options[] = {
> +    { "config_file", "path to configuration file with network parameters", OFFSET(config_file_path), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
> +    { NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(srcnn);
> +
> +#define CHECK_FILE(file)    if (ferror(file) || feof(file)){ \
> +                                av_log(context, AV_LOG_ERROR, "error reading configuration file\n");\
> +                                fclose(file); \
> +                                return AVERROR(EIO); \
> +                            }
> +
> +#define CHECK_ALLOCATION(conv, file)    if (allocate_and_read_convolution_data(&conv, file)){ \
> +                                            av_log(context, AV_LOG_ERROR, "could not allocate memory for convolutions\n"); \
> +                                            fclose(file); \
> +                                            return AVERROR(ENOMEM); \
> +                                        }
> +

> +static int allocate_and_read_convolution_data(Convolution* conv, FILE* config_file)
> +{
> +    int32_t kernel_size = conv->output_channels * conv->size * conv->size * conv->input_channels;
> +    conv->kernel = av_malloc(kernel_size * sizeof(double));
> +    if (!conv->kernel){
> +        return 1;

this should return an AVERROR code for consistency with the rest of
the codebase


> +    }

> +    fread(conv->kernel, sizeof(double), kernel_size, config_file);

directly reading data types is not portable, it would for example be
endian specific
and using avio for reading may be better, though fread is as far as iam
concerned also ok

[...]
> +/**
> + * @file
> + * Default cnn weights for x2 upsampling with srcnn filter.
> + */
> +
> +/// First convolution kernel

> +static double conv1_kernel[] = {

static data should be also const, otherwise it may be changed and could cause
thread saftey issues

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

You can kill me, but you cannot change the truth.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180327/09368e6a/attachment.sig>


More information about the ffmpeg-devel mailing list