[PATCH] avfilter/colorize: add speed option
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions. Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..ad8577c8fd 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = { #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption colorize_options[] = { - { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, - { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, + { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1
On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions.
Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..ad8577c8fd 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = { #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption colorize_options[] = { - { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, - { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, + { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
The cosmetic changes should be in a separate patch. Regards, Gyan
+ { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions. Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..cfcf1a54fb 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -267,6 +275,7 @@ static const AVOption colorize_options[] = { { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1 Am 01.05.24 um 09:49 schrieb Gyan Doshi:
On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions.
Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..ad8577c8fd 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = { #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption colorize_options[] = { - { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, - { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, + { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
The cosmetic changes should be in a separate patch.
I have split them now.
Regards, Gyan
+ { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Add spaces to format option list table-like Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index cfcf1a54fb..ad8577c8fd 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -271,10 +271,10 @@ static const AVFilterPad colorize_inputs[] = { #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption colorize_options[] = { - { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, - { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, + { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1 Am 01.05.24 um 10:37 schrieb Yannis Gerlach:
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions.
Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..cfcf1a54fb 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -267,6 +275,7 @@ static const AVOption colorize_options[] = { { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1
Am 01.05.24 um 09:49 schrieb Gyan Doshi:
On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions.
Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..ad8577c8fd 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = { #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption colorize_options[] = { - { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, - { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, + { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
The cosmetic changes should be in a separate patch.
I have split them now.
Regards, Gyan
+ { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
Am 01.05.24 um 09:49 schrieb Gyan Doshi:
On 2024-05-01 12:18 pm, Yannis Gerlach wrote:
The speed option allows to have a constant (per frame) change of hue. This allows for an easy way of creating an color changing effect without relying on somewhat complicated expressions.
Signed-off-by: Yannis Gerlach <ffmpeg@ygerlach.de> --- libavfilter/vf_colorize.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/libavfilter/vf_colorize.c b/libavfilter/vf_colorize.c index e6c563e3e2..ad8577c8fd 100644 --- a/libavfilter/vf_colorize.c +++ b/libavfilter/vf_colorize.c @@ -29,6 +29,7 @@ typedef struct ColorizeContext { float saturation; float lightness; float mix; + float speed; int depth; int c[3]; @@ -205,6 +206,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ff_filter_execute(ctx, do_slice, frame, NULL, FFMIN(s->planeheight[1], ff_filter_get_nb_threads(ctx))); + s->hue += s->speed; + if (s->hue < 0.f) { + s->hue += 360.f; + } else if(s->hue > 360.f) { + s->hue -= 360.f; + } + return ff_filter_frame(ctx->outputs[0], frame); } @@ -263,10 +271,11 @@ static const AVFilterPad colorize_inputs[] = { #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption colorize_options[] = { - { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, - { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5},0, 1, VF }, - { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, + { "hue", "set the hue", OFFSET(hue), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 360, VF }, + { "saturation", "set the saturation", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "lightness", "set the lightness", OFFSET(lightness), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, VF }, + { "mix", "set the mix of source lightness", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
The cosmetic changes should be in a separate patch.
Regards, Gyan
+ { "speed", "set the change of hue per frame", OFFSET(speed), AV_OPT_TYPE_FLOAT, {.dbl=0}, -180, 180, VF }, { NULL } }; -- 2.34.1
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Good Day, i have now redone this patch making all arguments of colorize an expression. This allows for things like `colorize=hue=2*n` which solves the problem i initially wanted to solve with the patch. Please take a look: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21564 Have a nice day, Yannis
participants (2)
-
Gyan Doshi -
Yannis Gerlach