[FFmpeg-devel] [RFC][WIP][PATCH] avfilter: add luascript filter

James Darnley james.darnley at gmail.com
Sat Feb 6 01:29:49 CET 2016


On 2016-02-04 19:40, Paul B Mahol wrote:

> +#define FN_ENTRY(name) {#name, script_ ## name}
> +struct fn_entry {
> +    const char *name;
> +    int (*fn)(lua_State *L);
> +};
> +
> +static const struct fn_entry main_fns[] = {
> +    FN_ENTRY(log),
> +    FN_ENTRY(frame_count),
> +    FN_ENTRY(filter),
> +    {0}
> +};

Consider using Lua's luaL_Reg type here.  It already has the same fields
as your struct.  Whether it really matters I don't know.

> +static int run_script(AVFilterContext *ctx)
> +{
> +    LuaScriptContext *s = ctx->priv;
> +    const char *dump;
> +    int ret, i;
> +
> +    if (s->L)
> +        lua_close(s->L);
> +
> +    s->L = luaL_newstate();
> +    if (!s->L)
> +        return AVERROR(ENOMEM);
> +
> +    avfilter_graph_free(&s->graph);
> +    memset(s->fctx, 0, sizeof(s->fctx));
> +    s->nbf = 0;
> +
> +    s->graph = avfilter_graph_alloc();
> +    if (!s->graph)
> +        return AVERROR(ENOMEM);
> +
> +    if (lua_cpcall(s->L, run_lua, ctx)) {

lua_cpcall was removed in Lua 5.2 but you can replace this by just
pushing the function and args on the stack and then calling it like any
other function with lua_pcall.

Overall I like this and see some potential in it.  I know you have a few
things to fix after speaking on IRC.  I've already made a few changes
but I won't do too many while you're still working on it, unless you ask
for it of course.  You can find my few changes here
https://gitlab.com/J_Darnley/ffmpeg/commits/lua use as you see fit.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 603 bytes
Desc: OpenPGP digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160206/9504bd59/attachment.sig>


More information about the ffmpeg-devel mailing list