[FFmpeg-devel] [PATCH] avfilter: add rawdump filter

Eoff, Ullysses A ullysses.a.eoff at intel.com
Wed Jul 10 17:51:40 EEST 2019


> From: Eoff, Ullysses A
> +static av_cold int rawdump_init(AVFilterContext *avctx)
> +{
> +    RawDumpContext *ctx = avctx->priv;
> +    static char *mode = "w";

For the record, this "static" is a problem if multiple rawdump filters are
specified in the graph.  The initial reason for this was to open the file for
writing on the first init (to overwrite any pre-existing file), then open for
appending on successive reinit's (e.g. frame resolution changes).  Thus,
would need a better solution to achieve the same result without
influencing other instances of the filter.

> +
> +    ctx->rawdump_file = fopen(ctx->rawdump_file_str, mode);
> +
> +    if (ctx->rawdump_file == NULL) {
> +        int err = AVERROR(errno);
> +        char buf[128];
> +        av_strerror(err, buf, sizeof(buf));
> +        av_log(ctx, AV_LOG_ERROR, "Failed to open %s for dumping: %s\n",
> +               ctx->rawdump_file_str, buf);
> +        return err;
> +    }
> +
> +    av_log(ctx, AV_LOG_DEBUG, "Opened %s (mode:%s) for dumping.\n",
> +           ctx->rawdump_file_str, mode);
> +
> +    mode = "a";
> +
> +    return 0;
> +}
> +
> +static av_cold void rawdump_uninit(AVFilterContext *avctx)
> +{
> +    RawDumpContext *ctx = avctx->priv;
> +
> +    if (ctx->rawdump_file != NULL)
> +        fclose(ctx->rawdump_file);
> +}
> +
> +#define OFFSET(x) offsetof(RawDumpContext, x)
> +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
> +static const AVOption rawdump_options[] = {
> +    {"file", "Set file where to dump raw frames", OFFSET(rawdump_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
> +    { NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(rawdump);
> +
> +static const AVFilterPad rawdump_inputs[] = {
> +    {
> +        .name         = "default",
> +        .type         = AVMEDIA_TYPE_VIDEO,
> +        .filter_frame = rawdump_filter_frame,
> +    },
> +    { NULL }
> +};
> +
> +static const AVFilterPad rawdump_outputs[] = {
> +    {
> +        .name         = "default",
> +        .type         = AVMEDIA_TYPE_VIDEO,
> +    },
> +    { NULL }
> +};
> +
> +AVFilter ff_vf_rawdump = {
> +    .name          = "rawdump",
> +    .description   = NULL_IF_CONFIG_SMALL("Dump frames to file"),
> +    .init          = rawdump_init,
> +    .uninit        = rawdump_uninit,
> +    .query_formats = rawdump_query_formats,
> +    .priv_size     = sizeof(RawDumpContext),
> +    .priv_class    = &rawdump_class,
> +    .inputs        = rawdump_inputs,
> +    .outputs       = rawdump_outputs,
> +};
> --
> 2.20.1



More information about the ffmpeg-devel mailing list