[WIP] life source
Hi, proof of concept life source based on Conway's game of life. I'm using the overlay filter to test it. Enjoy. -- FFmpeg = Foolish & Fast Minimalistic Picky Ecletic Guru
Hi, On Fri, Sep 3, 2010 at 1:45 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
proof of concept life source based on Conway's game of life.
I'm using the overlay filter to test it.
I might be misunderstanding but wouldn't it make sense to use libavformat/libavcodec to read video rather than creating lavf/c-incompatible stream source filters? Ronald
On date Friday 2010-09-03 14:46:59 -0400, Ronald S. Bultje encoded:
Hi,
On Fri, Sep 3, 2010 at 1:45 PM, Stefano Sabatini <stefano.sabatini-lala at poste.it> wrote:
proof of concept life source based on Conway's game of life.
I'm using the overlay filter to test it.
I might be misunderstanding but wouldn't it make sense to use libavformat/libavcodec to read video rather than creating lavf/c-incompatible stream source filters?
What do you mean by "lavf/c-incompatible"? Consider this like a funny proof of concept, in general having sources can be interesting and useful (e.g. for simplifying regression tests). Anyway I'm quite convinced that we should implement some form of plugin system, this way people don't need to commit to FFmpeg in order to use their own filters/sources or maintain their patched trees, this way it would be simpler to have a series of external filters/sources/sinks collections. Regards. -- FFmpeg = Frightening Fancy Murdering Puritan Enhanced Gargoyle
On date Friday 2010-09-03 19:45:51 +0200, Stefano Sabatini encoded:
Hi,
proof of concept life source based on Conway's game of life.
I'm using the overlay filter to test it.
Enjoy.
Updated. You can try it e.g. with: ffplay -noframedrop -loglevel info -s 150x600 -f rawvideo -pix_fmt rgb24 /dev/zero -vf "life=libavfilter/avfilter.c:150x600:240 [life]; [in][life] overlay, format=yuv420p [out]" Regards. -- FFmpeg = Fierce Fundamental Multipurpose Puritan Ecstatic Genius
On date Saturday 2010-09-04 18:00:20 +0200, Stefano Sabatini wrote:
On date Friday 2010-09-03 19:45:51 +0200, Stefano Sabatini encoded:
Hi,
proof of concept life source based on Conway's game of life.
I'm using the overlay filter to test it.
Enjoy.
Updated.
You can try it e.g. with: ffplay -noframedrop -loglevel info -s 150x600 -f rawvideo -pix_fmt rgb24 /dev/zero -vf "life=libavfilter/avfilter.c:150x600:240 [life]; [in][life] overlay, format=yuv420p [out]"
[now using my lavfi indev for testing it] Updated in case there is interest in this funny/beautiful/apparently-non-useful (like life itself) source. (Note for the posterity: a better approach would require some form of scripting, e.g. I wrote my source/filter in scheme and get it interpreted through some libscheme). -- FFmpeg = Frightening Forgiving Multimedia Pitiful Emblematic Gangster
On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add lifesrc source
--- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_lifesrc.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_lifesrc.c
Well since I'm in an all-play-no-work mood I worked to an updated version. I could also add support to "bricks" (cells which can't never be filled) and provide an option for specifying connected topology, but that can be done later. Example: ffplay -f lavfi "lifesrc=f=CREDITS:s=300x300:rule=21219, boxblur=2:2, negate" -- FFmpeg = Frightening and Foolish Marvellous Puristic Entertaining Geek
On Sat, Nov 19, 2011 at 11:14:46PM +0100, Stefano Sabatini wrote:
On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add lifesrc source
--- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_lifesrc.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_lifesrc.c
Well since I'm in an all-play-no-work mood I worked to an updated version.
i think you should commit it and work on it in git. Theres no harm if it contains a bug or isnt perfect ... [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The greatest way to live with honor in this world is to be what we pretend to be. -- Socrates
Le nonidi 29 brumaire, an CCXX, Stefano Sabatini a écrit :
+@table @option +@item filename, f +Set the file from which to read the initial grid state. This option +must be specified.
An option to start with a random grid, or maybe a grid defined by a formula, would be nice. Regards, -- Nicolas George
On Sat, Nov 19, 2011 at 11:14:46PM +0100, Stefano Sabatini wrote:
On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add lifesrc source
--- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_lifesrc.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_lifesrc.c
Well since I'm in an all-play-no-work mood I worked to an updated version.
I could also add support to "bricks" (cells which can't never be filled) and provide an option for specifying connected topology, but that can be done later.
Example: ffplay -f lavfi "lifesrc=f=CREDITS:s=300x300:rule=21219, boxblur=2:2, negate"
fun :) [...]
+ + if (!life->filename) { + av_log(ctx, AV_LOG_ERROR, "No filename specified, aborting\n"); + return AVERROR(EINVAL); + } + + if ((ret = init_pattern_from_file(ctx) < 0)) + return ret;
if ((ret = ...) < 0), or else it will crash with for instance an empty file. BTW, I agree with both Michael and Nicolas about having it upstream (I want to do something on it :)) and the random init board in case of no file. [...] -- Clément B.
On Sun, Nov 20, 2011 at 08:11:05PM +0100, Clément Bœsch wrote:
On Sat, Nov 19, 2011 at 11:14:46PM +0100, Stefano Sabatini wrote:
On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add lifesrc source
--- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_lifesrc.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_lifesrc.c
Well since I'm in an all-play-no-work mood I worked to an updated version.
I could also add support to "bricks" (cells which can't never be filled) and provide an option for specifying connected topology, but that can be done later.
Example: ffplay -f lavfi "lifesrc=f=CREDITS:s=300x300:rule=21219, boxblur=2:2, negate"
fun :)
[...]
+ + if (!life->filename) { + av_log(ctx, AV_LOG_ERROR, "No filename specified, aborting\n"); + return AVERROR(EINVAL); + } + + if ((ret = init_pattern_from_file(ctx) < 0)) + return ret;
if ((ret = ...) < 0), or else it will crash with for instance an empty file.
BTW, I agree with both Michael and Nicolas about having it upstream (I want to do something on it :)) and the random init board in case of no file.
The attached WIP patch add some progressive death support: state = 0 -> alive state = 1 -> dead state = 2 -> very dead state = 3 -> very very dead... [...] state = 255 -> definitely, dead. ...and set the color accordingly. The output now looks like an awesome automato[1] fight. [1]: http://en.wikipedia.org/wiki/Automaton + http://en.wikipedia.org/wiki/Tomato -- Clément B.
On date Sunday 2011-11-20 20:11:05 +0100, Clément Bœsch encoded:
On Sat, Nov 19, 2011 at 11:14:46PM +0100, Stefano Sabatini wrote:
On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add lifesrc source
--- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_lifesrc.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_lifesrc.c
Well since I'm in an all-play-no-work mood I worked to an updated version.
I could also add support to "bricks" (cells which can't never be filled) and provide an option for specifying connected topology, but that can be done later.
Example: ffplay -f lavfi "lifesrc=f=CREDITS:s=300x300:rule=21219, boxblur=2:2, negate"
fun :)
[...]
+ + if (!life->filename) { + av_log(ctx, AV_LOG_ERROR, "No filename specified, aborting\n"); + return AVERROR(EINVAL); + } + + if ((ret = init_pattern_from_file(ctx) < 0)) + return ret;
if ((ret = ...) < 0), or else it will crash with for instance an empty file.
Fixed.
BTW, I agree with both Michael and Nicolas about having it upstream (I want to do something on it :)) and the random init board in case of no file.
Added random grid generation in case of no specified file (based on a simple probabilistic approach), border stitching (by default) and implemented a saner syntax for specifying rules based on the game of life Wikipedia article. Also changed the name lifesrc -> life. I'll apply it in a few days if no one has more comments, documentation remarks are especially appreciated. -- FFmpeg = Free Forgiving Mysterious Portable Efficient Guru
On Sun, Dec 04, 2011 at 01:16:21PM +0100, Stefano Sabatini wrote:
On date Sunday 2011-11-20 20:11:05 +0100, Clément Bœsch encoded:
On Sat, Nov 19, 2011 at 11:14:46PM +0100, Stefano Sabatini wrote:
On date Sunday 2011-06-26 20:11:52 +0200, Stefano Sabatini encoded:
From 680fc136c9f85e289b86195dc54e5b76bffe6b97 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefano.sabatini-lala@poste.it> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add lifesrc source
--- libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_lifesrc.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_lifesrc.c
Well since I'm in an all-play-no-work mood I worked to an updated version.
I could also add support to "bricks" (cells which can't never be filled) and provide an option for specifying connected topology, but that can be done later.
Example: ffplay -f lavfi "lifesrc=f=CREDITS:s=300x300:rule=21219, boxblur=2:2, negate"
fun :)
[...]
+ + if (!life->filename) { + av_log(ctx, AV_LOG_ERROR, "No filename specified, aborting\n"); + return AVERROR(EINVAL); + } + + if ((ret = init_pattern_from_file(ctx) < 0)) + return ret;
if ((ret = ...) < 0), or else it will crash with for instance an empty file.
Fixed.
BTW, I agree with both Michael and Nicolas about having it upstream (I want to do something on it :)) and the random init board in case of no file.
Added random grid generation in case of no specified file (based on a simple probabilistic approach), border stitching (by default) and implemented a saner syntax for specifying rules based on the game of life Wikipedia article. Also changed the name lifesrc -> life.
We will need to add FFmpeg in the "Notable Life programs" section now ;)
I'll apply it in a few days if no one has more comments, documentation remarks are especially appreciated. -- FFmpeg = Free Forgiving Mysterious Portable Efficient Guru
From 807a3d6a306070a3d64cb367187a91fde2656e29 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefasab@gmail.com> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add life source
--- doc/filters.texi | 80 +++++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_life.c | 410 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 492 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_life.c
diff --git a/doc/filters.texi b/doc/filters.texi index fc34bf2..a83a2d3 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2772,6 +2772,86 @@ Some examples follow: frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay @end example
+@section life + +Generate a life pattern. + [...] + +Default value is "S23/B3", which is the original Conway's game of life +rule, and will keep a cell alive if it has 2 or 3 neighbor alive +cells, and will born a new cell if there are three alive cells around +a dead cell. + +@item random_fill_ratio, ratio +Set the random fill ratio for the initial random grid. It is a +floating point number value ranging from 0 to 1, defaults to 1/PHI.
Ignored when a file is specified I guess?
+ +@item random_seed, seed +Set the seed for filling the initial grid, must be an integer included +between 0 and UINT32_MAX. If not specified, or if explicitely set to
explicitly
+-1, the filter will try to use a good random seed at a best effort bases. + +@item size, s +Set the size of the output video. + +If the @option{filename} option is specified it is set by default to +the same value of the input file, and the specified size must contain +the size specified in the initial grid file. +Otherwise it is set by default to "320x240" for a randomly generated +initial grid. +
We can't have a larger area in which the grid from the file would be set in the center, right? IIRC the first initial patch had that kind of behaviour. I don't mind if this isn't possible anymore, but it might be nice to explicit it.
+@item stitch +If set to 1, stitch the left and right grid edges together, and the +top and bottom edges also. Defaults to 1. +@end table +
Great :) [...]
diff --git a/libavfilter/vsrc_life.c b/libavfilter/vsrc_life.c new file mode 100644 index 0000000..8e91a72 --- /dev/null +++ b/libavfilter/vsrc_life.c [...] +static void evolve(AVFilterContext *ctx) +{ + LifeContext *life = ctx->priv; + int i, j, v; + uint8_t *oldbuf = life->buf[ life->buf_idx]; + uint8_t *newbuf = life->buf[!life->buf_idx]; + + enum { NW, N, NE, W, E, SW, S, SE }; + + /* evolve the grid */ + for (i = 0; i < life->h; i++) { + for (j = 0; j < life->w; j++) { + int pos[8][2], n; + if (life->stitch) { + pos[NW][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NW][1] = (j-1) < 0 ? life->w-1 : j-1; + pos[N ][0] = (i-1) < 0 ? life->h-1 : i-1; pos[N ][1] = j ; + pos[NE][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NE][1] = (j+1) == life->w ? 0 : j+1; + pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? life->w-1 : j-1; + pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? 0 : j+1; + pos[SW][0] = (i+1) == life->h ? 0 : i+1; pos[SW][1] = (j-1) < 0 ? life->w-1 : j-1; + pos[S ][0] = (i+1) == life->h ? 0 : i+1; pos[S ][1] = j ; + pos[SE][0] = (i+1) == life->h ? 0 : i+1; pos[SE][1] = (j+1) == life->w ? 0 : j+1; + } else { + pos[NW][0] = (i-1) < 0 ? -1 : i-1; pos[NW][1] = (j-1) < 0 ? -1 : j-1; + pos[N ][0] = (i-1) < 0 ? -1 : i-1; pos[N ][1] = j ; ^^^^ just a lack of spaces
+ pos[NE][0] = (i-1) < 0 ? -1 : i-1; pos[NE][1] = (j+1) == life->w ? -1 : j+1; + pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? -1 : j-1; + pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? -1 : j+1; + pos[SW][0] = (i+1) == life->h ? -1 : i+1; pos[SW][1] = (j-1) < 0 ? -1 : j-1; + pos[S ][0] = (i+1) == life->h ? -1 : i+1; pos[S ][1] = j ; + pos[SE][0] = (i+1) == life->h ? -1 : i+1; pos[SE][1] = (j+1) == life->w ? -1 : j+1; + } +
Anyway, looks good to me. I'll rebased my patch and submit it when this is upstream. Thanks! -- Clément B.
On date Sunday 2011-12-04 18:05:04 +0100, Clément Bœsch encoded:
On Sun, Dec 04, 2011 at 01:16:21PM +0100, Stefano Sabatini wrote: [...]
Added random grid generation in case of no specified file (based on a simple probabilistic approach), border stitching (by default) and implemented a saner syntax for specifying rules based on the game of life Wikipedia article. Also changed the name lifesrc -> life.
We will need to add FFmpeg in the "Notable Life programs" section now ;)
I'll apply it in a few days if no one has more comments, documentation remarks are especially appreciated. -- FFmpeg = Free Forgiving Mysterious Portable Efficient Guru
From 807a3d6a306070a3d64cb367187a91fde2656e29 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini <stefasab@gmail.com> Date: Sun, 26 Jun 2011 19:47:18 +0200 Subject: [PATCH] lavfi: add life source
--- doc/filters.texi | 80 +++++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vsrc_life.c | 410 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 492 insertions(+), 0 deletions(-) create mode 100644 libavfilter/vsrc_life.c
diff --git a/doc/filters.texi b/doc/filters.texi index fc34bf2..a83a2d3 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2772,6 +2772,86 @@ Some examples follow: frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay @end example
+@section life + +Generate a life pattern. + [...] + +Default value is "S23/B3", which is the original Conway's game of life +rule, and will keep a cell alive if it has 2 or 3 neighbor alive +cells, and will born a new cell if there are three alive cells around +a dead cell. + +@item random_fill_ratio, ratio +Set the random fill ratio for the initial random grid. It is a +floating point number value ranging from 0 to 1, defaults to 1/PHI.
Ignored when a file is specified I guess?
Added a note.
+ +@item random_seed, seed +Set the seed for filling the initial grid, must be an integer included +between 0 and UINT32_MAX. If not specified, or if explicitely set to
explicitly
Fixed.
+-1, the filter will try to use a good random seed at a best effort bases. + +@item size, s +Set the size of the output video. + +If the @option{filename} option is specified it is set by default to +the same value of the input file, and the specified size must contain +the size specified in the initial grid file. +Otherwise it is set by default to "320x240" for a randomly generated +initial grid. +
We can't have a larger area in which the grid from the file would be set in the center, right? IIRC the first initial patch had that kind of behaviour. I don't mind if this isn't possible anymore, but it might be nice to explicit it.
I reformulated the paragraph. [...] Did more wording fixes here and there, added some examples, and added life to FFmpeg. -- FFmpeg = Freak & Fundamentalist Mortal Pitiful Everlasting Game
participants (7)
-
Clément Bœsch -
Michael Niedermayer -
Nicolas George -
rsbultje@gmail.com -
Stefano Sabatini -
Stefano Sabatini -
stefano.sabatini-lala@poste.it