Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 10.02.2016 11:40, Paul B Mahol wrote: On 2/10/16, Tobias Rappwrote: On 10.02.2016 10:59, Paul B Mahol wrote: On 2/10/16, Tobias Rapp wrote: On 10.02.2016 10:01, Paul B Mahol wrote: On 2/10/16, Tobias Rapp wrote: On 06.02.2016 23:30, Paul B Mahol wrote: On 2/6/16, Paul B Mahol wrote: Hi, patch attached. Improved version attached. [...] + +static int string(const char *value1, const char *value2, size_t length) +{ +return !strncmp(value1, value2, length); +} If I understand correctly this function is used to compare if the start of value2 matches value1. Maybe this function should be called "starts_with" (also in the "function" option enum)? + +static int equal(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 != f2; +} + +static int less(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 > f2; +} + +static int greater(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 < f2; +} + [...] I think it would be better to not compare float values directly with "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= epsilon". BTW: Is the return value of "equal", "less" and "greater" inverse on purpose? Not for equal, but for other it is. OK, now I got it that the argument order is flipped but matches the documentation. In that case it is a bit counter-intuitive that one has to do something like mode=print:key=mykey:value=1.0:function=less to print all metadata values of "mykey" which are *bigger* than 1.0. Nope, this works fine here. It prints values less than 1.0 Then I have problems understanding the documentation text of "less" and "greater". Ah, the problem was in documenation and code, hopefully it should be clear now. Yes, with commit 408ea50ca6bcc666babc8b8e654eb135164480af everything is fine. Thanks for writing the metadata filter! Last week I had an idea for a similar filter but had not started implementation yet -- thus my interest in it. Regards, Tobias ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 10.02.2016 10:01, Paul B Mahol wrote: On 2/10/16, Tobias Rappwrote: On 06.02.2016 23:30, Paul B Mahol wrote: On 2/6/16, Paul B Mahol wrote: Hi, patch attached. Improved version attached. [...] + +static int string(const char *value1, const char *value2, size_t length) +{ +return !strncmp(value1, value2, length); +} If I understand correctly this function is used to compare if the start of value2 matches value1. Maybe this function should be called "starts_with" (also in the "function" option enum)? + +static int equal(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 != f2; +} + +static int less(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 > f2; +} + +static int greater(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 < f2; +} + [...] I think it would be better to not compare float values directly with "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= epsilon". BTW: Is the return value of "equal", "less" and "greater" inverse on purpose? Not for equal, but for other it is. OK, now I got it that the argument order is flipped but matches the documentation. In that case it is a bit counter-intuitive that one has to do something like mode=print:key=mykey:value=1.0:function=less to print all metadata values of "mykey" which are *bigger* than 1.0. Another sidenote: I have seen that some filters use a common expression language (e.g. aeval, crop, scale). Not sure if this expression language supports string operators or if it is limited to numbers but in my opinion it would be great to re-use it here. Added and applied. Filter is easily extendable. Thanks for adding expression support. I know my response has come late and I'm only an occasional FFmpeg developer so my thoughts might not have big weight. Still I think it would have been more polite to first respond on the list to all my comments (see the "starts_with" suggestion above) before applying the patch. Regards, Tobias ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 2/10/16, Tobias Rappwrote: > On 10.02.2016 10:01, Paul B Mahol wrote: >> On 2/10/16, Tobias Rapp wrote: >>> On 06.02.2016 23:30, Paul B Mahol wrote: On 2/6/16, Paul B Mahol wrote: > Hi, > > patch attached. > Improved version attached. [...] + +static int string(const char *value1, const char *value2, size_t length) +{ +return !strncmp(value1, value2, length); +} >>> >>> If I understand correctly this function is used to compare if the start >>> of value2 matches value1. Maybe this function should be called >>> "starts_with" (also in the "function" option enum)? >>> + +static int equal(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 != f2; +} + +static int less(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 > f2; +} + +static int greater(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 < f2; +} + [...] >>> >>> I think it would be better to not compare float values directly with >>> "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= epsilon". >>> >>> BTW: Is the return value of "equal", "less" and "greater" inverse on >>> purpose? >> >> Not for equal, but for other it is. > > OK, now I got it that the argument order is flipped but matches the > documentation. In that case it is a bit counter-intuitive that one has > to do something like > > mode=print:key=mykey:value=1.0:function=less > > to print all metadata values of "mykey" which are *bigger* than 1.0. > Nope, this works fine here. It prints values less than 1.0 >>> >>> Another sidenote: I have seen that some filters use a common expression >>> language (e.g. aeval, crop, scale). Not sure if this expression language >>> supports string operators or if it is limited to numbers but in my >>> opinion it would be great to re-use it here. >> >> Added and applied. Filter is easily extendable. > > Thanks for adding expression support. > > I know my response has come late and I'm only an occasional FFmpeg > developer so my thoughts might not have big weight. Still I think it > would have been more polite to first respond on the list to all my > comments (see the "starts_with" suggestion above) before applying the patch. You can post another patch anytime here and if it makes sense I will gladly apply it. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 06.02.2016 23:30, Paul B Mahol wrote: On 2/6/16, Paul B Maholwrote: Hi, patch attached. Improved version attached. [...] + +static int string(const char *value1, const char *value2, size_t length) +{ +return !strncmp(value1, value2, length); +} If I understand correctly this function is used to compare if the start of value2 matches value1. Maybe this function should be called "starts_with" (also in the "function" option enum)? + +static int equal(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 != f2; +} + +static int less(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 > f2; +} + +static int greater(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 < f2; +} + [...] I think it would be better to not compare float values directly with "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= epsilon". BTW: Is the return value of "equal", "less" and "greater" inverse on purpose? Another sidenote: I have seen that some filters use a common expression language (e.g. aeval, crop, scale). Not sure if this expression language supports string operators or if it is limited to numbers but in my opinion it would be great to re-use it here. Regards, Tobias ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 2/10/16, Tobias Rappwrote: > On 10.02.2016 10:59, Paul B Mahol wrote: >> On 2/10/16, Tobias Rapp wrote: >>> On 10.02.2016 10:01, Paul B Mahol wrote: On 2/10/16, Tobias Rapp wrote: > On 06.02.2016 23:30, Paul B Mahol wrote: >> On 2/6/16, Paul B Mahol wrote: >>> Hi, >>> >>> patch attached. >>> >> >> Improved version attached. >> >> [...] >> + >> +static int string(const char *value1, const char *value2, size_t >> length) >> +{ >> +return !strncmp(value1, value2, length); >> +} > > If I understand correctly this function is used to compare if the start > of value2 matches value1. Maybe this function should be called > "starts_with" (also in the "function" option enum)? > >> + >> +static int equal(const char *value1, const char *value2, size_t >> length) >> +{ >> +float f1, f2; >> + >> +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) >> +return 0; >> + >> +return f1 != f2; >> +} >> + >> +static int less(const char *value1, const char *value2, size_t >> length) >> +{ >> +float f1, f2; >> + >> +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) >> +return 0; >> + >> +return f1 > f2; >> +} >> + >> +static int greater(const char *value1, const char *value2, size_t >> length) >> +{ >> +float f1, f2; >> + >> +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) >> +return 0; >> + >> +return f1 < f2; >> +} >> + >> [...] > > I think it would be better to not compare float values directly with > "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= > epsilon". > > BTW: Is the return value of "equal", "less" and "greater" inverse on > purpose? Not for equal, but for other it is. >>> >>> OK, now I got it that the argument order is flipped but matches the >>> documentation. In that case it is a bit counter-intuitive that one has >>> to do something like >>> >>> mode=print:key=mykey:value=1.0:function=less >>> >>> to print all metadata values of "mykey" which are *bigger* than 1.0. >>> >> >> Nope, this works fine here. It prints values less than 1.0 > > Then I have problems understanding the documentation text of "less" and > "greater". Ah, the problem was in documenation and code, hopefully it should be clear now. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 10.02.2016 10:59, Paul B Mahol wrote: On 2/10/16, Tobias Rappwrote: On 10.02.2016 10:01, Paul B Mahol wrote: On 2/10/16, Tobias Rapp wrote: On 06.02.2016 23:30, Paul B Mahol wrote: On 2/6/16, Paul B Mahol wrote: Hi, patch attached. Improved version attached. [...] + +static int string(const char *value1, const char *value2, size_t length) +{ +return !strncmp(value1, value2, length); +} If I understand correctly this function is used to compare if the start of value2 matches value1. Maybe this function should be called "starts_with" (also in the "function" option enum)? + +static int equal(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 != f2; +} + +static int less(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 > f2; +} + +static int greater(const char *value1, const char *value2, size_t length) +{ +float f1, f2; + +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) +return 0; + +return f1 < f2; +} + [...] I think it would be better to not compare float values directly with "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= epsilon". BTW: Is the return value of "equal", "less" and "greater" inverse on purpose? Not for equal, but for other it is. OK, now I got it that the argument order is flipped but matches the documentation. In that case it is a bit counter-intuitive that one has to do something like mode=print:key=mykey:value=1.0:function=less to print all metadata values of "mykey" which are *bigger* than 1.0. Nope, this works fine here. It prints values less than 1.0 Then I have problems understanding the documentation text of "less" and "greater". Another sidenote: I have seen that some filters use a common expression language (e.g. aeval, crop, scale). Not sure if this expression language supports string operators or if it is limited to numbers but in my opinion it would be great to re-use it here. Added and applied. Filter is easily extendable. Thanks for adding expression support. I know my response has come late and I'm only an occasional FFmpeg developer so my thoughts might not have big weight. Still I think it would have been more polite to first respond on the list to all my comments (see the "starts_with" suggestion above) before applying the patch. You can post another patch anytime here and if it makes sense I will gladly apply it. OK. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 2/10/16, Tobias Rappwrote: > On 06.02.2016 23:30, Paul B Mahol wrote: >> On 2/6/16, Paul B Mahol wrote: >>> Hi, >>> >>> patch attached. >>> >> >> Improved version attached. >> >> [...] >> + >> +static int string(const char *value1, const char *value2, size_t length) >> +{ >> +return !strncmp(value1, value2, length); >> +} > > If I understand correctly this function is used to compare if the start > of value2 matches value1. Maybe this function should be called > "starts_with" (also in the "function" option enum)? > >> + >> +static int equal(const char *value1, const char *value2, size_t length) >> +{ >> +float f1, f2; >> + >> +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) >> +return 0; >> + >> +return f1 != f2; >> +} >> + >> +static int less(const char *value1, const char *value2, size_t length) >> +{ >> +float f1, f2; >> + >> +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) >> +return 0; >> + >> +return f1 > f2; >> +} >> + >> +static int greater(const char *value1, const char *value2, size_t length) >> +{ >> +float f1, f2; >> + >> +if (sscanf(value1, "%f", ) + sscanf(value2, "%f", ) != 2) >> +return 0; >> + >> +return f1 < f2; >> +} >> + >> [...] > > I think it would be better to not compare float values directly with > "==", "<" or ">". Instead use some code like "fabsf(f1 - f2) <= epsilon". > > BTW: Is the return value of "equal", "less" and "greater" inverse on > purpose? Not for equal, but for other it is. > > Another sidenote: I have seen that some filters use a common expression > language (e.g. aeval, crop, scale). Not sure if this expression language > supports string operators or if it is limited to numbers but in my > opinion it would be great to re-use it here. Added and applied. Filter is easily extendable. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 2/6/16, Paul B Maholwrote: > On 2/6/16, Paul B Mahol wrote: >> Hi, >> >> patch attached. >> > > Improved version attached. > Gonna push this soon. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 2/6/16, Moritz Barsnickwrote: > On Sat, Feb 06, 2016 at 12:47:25 +0100, Paul B Mahol wrote: >> patch attached. > > Nice. (Untested.) > > > >> +Manipulate frames metadata. > Either: > frame metadata [using this as a generic term] > or: > frames' metadata > > I prefer the former. > >> +If both @code{value} and @code{key} is set, select frame > ^ frames (plural) >> +every frame that have such key in metadata. > has (singular) > >> +Print key and value if metadata was found. > I'm not sure I've understood whether this can apply to only matching > metadata (key, key/value), or to any metadata. > >> +Set metadata value which will be used. This option is mandatory for >> modify >> +and add mode. > for 'modify' and 'add' modes (note the quoting and the plural). > >> +Set length of how much characters of two metadata values need to match to >> be > many All should be resolved in newer version. Thanks for feedback. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On 2/6/16, Paul B Maholwrote: > Hi, > > patch attached. > Improved version attached. From 46283dd6b38ce8f1346249707986212546026e39 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sat, 6 Feb 2016 11:19:45 +0100 Subject: [PATCH] avfilter: add metadata filters Signed-off-by: Paul B Mahol --- doc/filters.texi | 65 +++ libavfilter/Makefile | 2 + libavfilter/allfilters.c | 2 + libavfilter/f_metadata.c | 282 +++ 4 files changed, 351 insertions(+) create mode 100644 libavfilter/f_metadata.c diff --git a/doc/filters.texi b/doc/filters.texi index 664ebe8..fa33491 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -8444,6 +8444,71 @@ format=rgb24,mergeplanes=0x000102:yuv444p @end example @end itemize +@section metadata, ametadata + +Manipulate frame metadata. + +This filter accepts the following options: + +@table @option +@item m +Set mode of operation of the filter. + +Can be one of the following: + +@table @samp +@item select +If both @code{value} and @code{key} is set, select frames +which have such metadata. If only @code{key} is set, select +every frame that has such key in metadata. + +@item add +Add new metadata @code{key} and @code{value}. If key is already available +do nothing. + +@item modify +Modify value of already present key. + +@item delete +If @code{value} is set, delete only keys that have such value. +Otherwise, delete key. + +@item print +Print key and value if metadata was found. +@end table + +@item key +Set key used with all modes, Must be set. + +@item value +Set metadata value which will be used. This option is mandatory for +@code{modify} and @code{add} mode. + +@item length +Set length of how many characters of two metadata values need to match to be +considered same. Default is all available characters. + +@item function +Which function to use when comparing metadata value and @code{value}. + +Can be one of following: + +@table @samp +@item string +Values are interpreted as strings, returns true if @code{value} is same as metadata value up +to N chars as set in @code{length} option. + +@item less +Values are interpreted as floats, returns true if @code{value} is less than metadata value. + +@item equal +Values are interpreted as floats, returns true if @code{value} is equal with metadata value. + +@item greater +Values are interpreted as floats, returns true if @code{value} is greater than metadata value. +@end table +@end table + @section mpdecimate Drop frames that do not differ greatly from the previous frame in diff --git a/libavfilter/Makefile b/libavfilter/Makefile index e76d18e..852b60d 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -39,6 +39,7 @@ OBJS-$(CONFIG_AINTERLEAVE_FILTER)+= f_interleave.o OBJS-$(CONFIG_ALIMITER_FILTER) += af_alimiter.o OBJS-$(CONFIG_ALLPASS_FILTER)+= af_biquads.o OBJS-$(CONFIG_AMERGE_FILTER) += af_amerge.o +OBJS-$(CONFIG_AMETADATA_FILTER) += f_metadata.o OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o OBJS-$(CONFIG_APAD_FILTER) += af_apad.o @@ -185,6 +186,7 @@ OBJS-$(CONFIG_LUTYUV_FILTER) += vf_lut.o OBJS-$(CONFIG_MASKEDMERGE_FILTER)+= vf_maskedmerge.o framesync.o OBJS-$(CONFIG_MCDEINT_FILTER)+= vf_mcdeint.o OBJS-$(CONFIG_MERGEPLANES_FILTER)+= vf_mergeplanes.o framesync.o +OBJS-$(CONFIG_METADATA_FILTER) += f_metadata.o OBJS-$(CONFIG_MPDECIMATE_FILTER) += vf_mpdecimate.o OBJS-$(CONFIG_NEGATE_FILTER) += vf_lut.o OBJS-$(CONFIG_NNEDI_FILTER) += vf_nnedi.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 27d54bc..a904402 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -59,6 +59,7 @@ void avfilter_register_all(void) REGISTER_FILTER(ALIMITER, alimiter, af); REGISTER_FILTER(ALLPASS,allpass,af); REGISTER_FILTER(AMERGE, amerge, af); +REGISTER_FILTER(AMETADATA, ametadata, af); REGISTER_FILTER(AMIX, amix, af); REGISTER_FILTER(ANEQUALIZER,anequalizer,af); REGISTER_FILTER(ANULL, anull, af); @@ -206,6 +207,7 @@ void avfilter_register_all(void) REGISTER_FILTER(MASKEDMERGE,maskedmerge,vf); REGISTER_FILTER(MCDEINT,mcdeint,vf); REGISTER_FILTER(MERGEPLANES,mergeplanes,vf); +REGISTER_FILTER(METADATA, metadata, vf); REGISTER_FILTER(MPDECIMATE, mpdecimate, vf); REGISTER_FILTER(NEGATE, negate, vf); REGISTER_FILTER(NNEDI, nnedi, vf); diff --git a/libavfilter/f_metadata.c b/libavfilter/f_metadata.c new file mode 100644 index 000..f7195f1
Re: [FFmpeg-devel] [PATCH] avfilter: add metadata filters
On Sat, Feb 06, 2016 at 12:47:25 +0100, Paul B Mahol wrote: > patch attached. Nice. (Untested.) > +Manipulate frames metadata. Either: frame metadata [using this as a generic term] or: frames' metadata I prefer the former. > +If both @code{value} and @code{key} is set, select frame ^ frames (plural) > +every frame that have such key in metadata. has (singular) > +Print key and value if metadata was found. I'm not sure I've understood whether this can apply to only matching metadata (key, key/value), or to any metadata. > +Set metadata value which will be used. This option is mandatory for modify > +and add mode. for 'modify' and 'add' modes (note the quoting and the plural). > +Set length of how much characters of two metadata values need to match to be many Moritz ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel