Skip to content

Instantly share code, notes, and snippets.

@slhck
Created December 6, 2021 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slhck/7ca145663f5898b2a9018106cc0b0d6a to your computer and use it in GitHub Desktop.
Save slhck/7ca145663f5898b2a9018106cc0b0d6a to your computer and use it in GitHub Desktop.
FFmpeg Filter Grammar
// Work in progress! Does not handle escapes within filter arguments.
FilterGraph =
head: FilterChain
tail:(";" @FilterChain)*
{ return [head, ...tail]; }
FilterChain =
head: Filter
tail:("," @Filter)*
{
return {
"filters": [head, ...tail],
}
}
Name = [a-zA-Z_0-9:]+
FilterLabel =
_ "[" _ name:Name _ "]" _
{ return name.join(""); }
FilterArg =
arg:[a-zA-Z1-9=]+
{ return arg.join(""); }
FilterArgs =
head: FilterArg
tail:(":" @FilterArg)*
{ return [head, ...tail]; }
Filter =
inLabels:FilterLabel*
name:Name("@"Name)? // TODO capture ID
args:(
"="
FilterArgs
)?
outLabels:FilterLabel*
{
return {
"inLabels": inLabels,
"name": name.join(""),
"args": args === null ? [] : args[1],
"outLabels": inLabels,
};
}
_ "whitespace"
= [ \t\n\r]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment