Message ID | 20201002180331.20416-4-anton@khirnov.net |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,1/7] mpegvideo: use the AVVideoEncParams API for exporting QP tables | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > --- > libavfilter/Makefile | 2 +- > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > libavfilter/vf_spp.h | 3 +- > tests/fate/filter-video.mak | 4 +-- > 4 files changed, 29 insertions(+), 37 deletions(-) > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > index d20f2937b6..2669d7b84b 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > opencl/convolution.o > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > index 4bcc6429e0..2eb383be03 100644 > --- a/libavfilter/vf_spp.c > +++ b/libavfilter/vf_spp.c > @@ -36,6 +36,7 @@ > #include "libavutil/opt.h" > #include "libavutil/pixdesc.h" > #include "internal.h" > +#include "qp_table.h" > #include "vf_spp.h" > > enum mode { > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > } else{ > const int qps = 3 + is_luma; > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? thx [...]
Quoting Michael Niedermayer (2020-10-03 20:23:02) > On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > > --- > > libavfilter/Makefile | 2 +- > > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > > libavfilter/vf_spp.h | 3 +- > > tests/fate/filter-video.mak | 4 +-- > > 4 files changed, 29 insertions(+), 37 deletions(-) > > > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > > index d20f2937b6..2669d7b84b 100644 > > --- a/libavfilter/Makefile > > +++ b/libavfilter/Makefile > > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > > opencl/convolution.o > > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > > index 4bcc6429e0..2eb383be03 100644 > > --- a/libavfilter/vf_spp.c > > +++ b/libavfilter/vf_spp.c > > @@ -36,6 +36,7 @@ > > #include "libavutil/opt.h" > > #include "libavutil/pixdesc.h" > > #include "internal.h" > > +#include "qp_table.h" > > #include "vf_spp.h" > > > > enum mode { > > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > > } else{ > > const int qps = 3 + is_luma; > > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); > > wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? There should be no such cases - in the new API, only TYPE_MPEG2 exists (disregarding newer codecs that were not supported by this filter anyway).
On Mon, Oct 05, 2020 at 10:26:24AM +0200, Anton Khirnov wrote: > Quoting Michael Niedermayer (2020-10-03 20:23:02) > > On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > > > --- > > > libavfilter/Makefile | 2 +- > > > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > > > libavfilter/vf_spp.h | 3 +- > > > tests/fate/filter-video.mak | 4 +-- > > > 4 files changed, 29 insertions(+), 37 deletions(-) > > > > > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > > > index d20f2937b6..2669d7b84b 100644 > > > --- a/libavfilter/Makefile > > > +++ b/libavfilter/Makefile > > > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > > > opencl/convolution.o > > > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > > > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > > > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > > > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > > > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > > > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > > > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > > > index 4bcc6429e0..2eb383be03 100644 > > > --- a/libavfilter/vf_spp.c > > > +++ b/libavfilter/vf_spp.c > > > @@ -36,6 +36,7 @@ > > > #include "libavutil/opt.h" > > > #include "libavutil/pixdesc.h" > > > #include "internal.h" > > > +#include "qp_table.h" > > > #include "vf_spp.h" > > > > > > enum mode { > > > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > > > } else{ > > > const int qps = 3 + is_luma; > > > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > > > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > > > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); > > > > wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? > > There should be no such cases - in the new API, only TYPE_MPEG2 exists > (disregarding newer codecs that were not supported by this filter > anyway). before the patch the code was intended to convert the quantization step size used in the codec to the same scale as the filter used. disregarding if the codec was 8x8 dct based. In fact spp should not require the input to be 8x8 dct based at all, why should it? It uses the DCT as a means to favor real images and remove "noise" that is not part of real images. It should for example also work if a image has blocking artifacts that look like hexagons or triangles I never tried but H264 with disabled loop filter should benefit from spp in terms of subjective quality as long as the filter strength is set appropriately That is for streams where the bitrate is low enough to see artifacts thx [...]
Quoting Michael Niedermayer (2020-10-06 00:15:06) > On Mon, Oct 05, 2020 at 10:26:24AM +0200, Anton Khirnov wrote: > > Quoting Michael Niedermayer (2020-10-03 20:23:02) > > > On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > > > > --- > > > > libavfilter/Makefile | 2 +- > > > > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > > > > libavfilter/vf_spp.h | 3 +- > > > > tests/fate/filter-video.mak | 4 +-- > > > > 4 files changed, 29 insertions(+), 37 deletions(-) > > > > > > > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > > > > index d20f2937b6..2669d7b84b 100644 > > > > --- a/libavfilter/Makefile > > > > +++ b/libavfilter/Makefile > > > > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > > > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > > > > opencl/convolution.o > > > > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > > > > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > > > > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > > > > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > > > > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > > > > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > > > > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > > > > index 4bcc6429e0..2eb383be03 100644 > > > > --- a/libavfilter/vf_spp.c > > > > +++ b/libavfilter/vf_spp.c > > > > @@ -36,6 +36,7 @@ > > > > #include "libavutil/opt.h" > > > > #include "libavutil/pixdesc.h" > > > > #include "internal.h" > > > > +#include "qp_table.h" > > > > #include "vf_spp.h" > > > > > > > > enum mode { > > > > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > > > > } else{ > > > > const int qps = 3 + is_luma; > > > > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > > > > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > > > > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); > > > > > > wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? > > > > There should be no such cases - in the new API, only TYPE_MPEG2 exists > > (disregarding newer codecs that were not supported by this filter > > anyway). > > before the patch the code was intended to convert the quantization step size > used in the codec to the same scale as the filter used. disregarding if the > codec was 8x8 dct based. In fact spp should not require the input to be 8x8 dct > based at all, why should it? It uses the DCT as a means to favor real images > and remove "noise" that is not part of real images. It should for example also > work if a image has blocking artifacts that look like hexagons or triangles > > I never tried but H264 with disabled loop filter should benefit from spp in > terms of subjective quality as long as the filter strength is set appropriately > That is for streams where the bitrate is low enough to see artifacts Are you saying I should expand this filter to support new codecs? That does not seem appropriate for a patch that only adapts it to new API.
On Fri, Oct 09, 2020 at 08:13:24AM +0200, Anton Khirnov wrote: > Quoting Michael Niedermayer (2020-10-06 00:15:06) > > On Mon, Oct 05, 2020 at 10:26:24AM +0200, Anton Khirnov wrote: > > > Quoting Michael Niedermayer (2020-10-03 20:23:02) > > > > On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > > > > > --- > > > > > libavfilter/Makefile | 2 +- > > > > > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > > > > > libavfilter/vf_spp.h | 3 +- > > > > > tests/fate/filter-video.mak | 4 +-- > > > > > 4 files changed, 29 insertions(+), 37 deletions(-) > > > > > > > > > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > > > > > index d20f2937b6..2669d7b84b 100644 > > > > > --- a/libavfilter/Makefile > > > > > +++ b/libavfilter/Makefile > > > > > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > > > > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > > > > > opencl/convolution.o > > > > > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > > > > > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > > > > > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > > > > > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > > > > > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > > > > > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > > > > > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > > > > > index 4bcc6429e0..2eb383be03 100644 > > > > > --- a/libavfilter/vf_spp.c > > > > > +++ b/libavfilter/vf_spp.c > > > > > @@ -36,6 +36,7 @@ > > > > > #include "libavutil/opt.h" > > > > > #include "libavutil/pixdesc.h" > > > > > #include "internal.h" > > > > > +#include "qp_table.h" > > > > > #include "vf_spp.h" > > > > > > > > > > enum mode { > > > > > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > > > > > } else{ > > > > > const int qps = 3 + is_luma; > > > > > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > > > > > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > > > > > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); > > > > > > > > wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? > > > > > > There should be no such cases - in the new API, only TYPE_MPEG2 exists > > > (disregarding newer codecs that were not supported by this filter > > > anyway). > > > > before the patch the code was intended to convert the quantization step size > > used in the codec to the same scale as the filter used. disregarding if the > > codec was 8x8 dct based. In fact spp should not require the input to be 8x8 dct > > based at all, why should it? It uses the DCT as a means to favor real images > > and remove "noise" that is not part of real images. It should for example also > > work if a image has blocking artifacts that look like hexagons or triangles > > > > I never tried but H264 with disabled loop filter should benefit from spp in > > terms of subjective quality as long as the filter strength is set appropriately > > That is for streams where the bitrate is low enough to see artifacts > > Are you saying I should expand this filter to support new codecs? That > does not seem appropriate for a patch that only adapts it to new API. no but before your patch theres a central place ff_norm_qscale() that has access to both the QP type (codec type) and the QP and can produce a standarized QP So someone who wanted to SPP support some random new codec could do it there and at the same time have 4 other filters for free also support the new codec. The patch does not replace the qp type by its replacement AVVideoEncParamsType but instead a wrong hardcoded value If you use AVVideoEncParamsType or something equivalent to it / qp_type then that resolves this concern unless iam missing something of course ... thx [...]
Quoting Michael Niedermayer (2020-10-09 19:17:06) > On Fri, Oct 09, 2020 at 08:13:24AM +0200, Anton Khirnov wrote: > > Quoting Michael Niedermayer (2020-10-06 00:15:06) > > > On Mon, Oct 05, 2020 at 10:26:24AM +0200, Anton Khirnov wrote: > > > > Quoting Michael Niedermayer (2020-10-03 20:23:02) > > > > > On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > > > > > > --- > > > > > > libavfilter/Makefile | 2 +- > > > > > > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > > > > > > libavfilter/vf_spp.h | 3 +- > > > > > > tests/fate/filter-video.mak | 4 +-- > > > > > > 4 files changed, 29 insertions(+), 37 deletions(-) > > > > > > > > > > > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > > > > > > index d20f2937b6..2669d7b84b 100644 > > > > > > --- a/libavfilter/Makefile > > > > > > +++ b/libavfilter/Makefile > > > > > > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > > > > > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > > > > > > opencl/convolution.o > > > > > > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > > > > > > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > > > > > > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > > > > > > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > > > > > > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > > > > > > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > > > > > > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > > > > > > index 4bcc6429e0..2eb383be03 100644 > > > > > > --- a/libavfilter/vf_spp.c > > > > > > +++ b/libavfilter/vf_spp.c > > > > > > @@ -36,6 +36,7 @@ > > > > > > #include "libavutil/opt.h" > > > > > > #include "libavutil/pixdesc.h" > > > > > > #include "internal.h" > > > > > > +#include "qp_table.h" > > > > > > #include "vf_spp.h" > > > > > > > > > > > > enum mode { > > > > > > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > > > > > > } else{ > > > > > > const int qps = 3 + is_luma; > > > > > > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > > > > > > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > > > > > > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); > > > > > > > > > > wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? > > > > > > > > There should be no such cases - in the new API, only TYPE_MPEG2 exists > > > > (disregarding newer codecs that were not supported by this filter > > > > anyway). > > > > > > before the patch the code was intended to convert the quantization step size > > > used in the codec to the same scale as the filter used. disregarding if the > > > codec was 8x8 dct based. In fact spp should not require the input to be 8x8 dct > > > based at all, why should it? It uses the DCT as a means to favor real images > > > and remove "noise" that is not part of real images. It should for example also > > > work if a image has blocking artifacts that look like hexagons or triangles > > > > > > I never tried but H264 with disabled loop filter should benefit from spp in > > > terms of subjective quality as long as the filter strength is set appropriately > > > That is for streams where the bitrate is low enough to see artifacts > > > > Are you saying I should expand this filter to support new codecs? That > > does not seem appropriate for a patch that only adapts it to new API. > > no > but before your patch theres a central place ff_norm_qscale() > that has access to both the QP type (codec type) and the QP > and can produce a standarized QP > So someone who wanted to SPP support some random new codec could > do it there and at the same time have 4 other filters for free also > support the new codec. ff_norm_qscale() is still there and the filter still calls it. But if someone wants to extend it to support other codecs, they still need to add code to ff_qp_table_extract() to handle AVVideoEncParams.type != AV_VIDEO_ENC_PARAMS_MPEG2. It does not seem reasonable to me to pretend the code supports something that it actually does not. > > The patch does not replace the qp type by its replacement AVVideoEncParamsType > but instead a wrong hardcoded value The value is not wrong. It is correct in all the cases that code runs in. If someone wants to handle new cases later, it is easy to grep for ff_norm_qscale() calls and replace the value, after adapting all the other code. > If you use AVVideoEncParamsType or something equivalent to it / qp_type then > that resolves this concern > > unless iam missing something of course ... It cannot be handled generically (at least not easily), because the data layout allowed by AVVideoBlockParams is more general than the one handled by those *pp filters. Additionally, the interpretation of qp is codec-dependent. So IMO the code should not pretends it can handle arbitrary codecs, when it is not actually true.
ping Michael, do you still object to this set? If not, I am going to push it.
On Fri, Nov 27, 2020 at 03:38:51PM +0100, Anton Khirnov wrote: > Quoting Michael Niedermayer (2020-10-09 19:17:06) > > On Fri, Oct 09, 2020 at 08:13:24AM +0200, Anton Khirnov wrote: > > > Quoting Michael Niedermayer (2020-10-06 00:15:06) > > > > On Mon, Oct 05, 2020 at 10:26:24AM +0200, Anton Khirnov wrote: > > > > > Quoting Michael Niedermayer (2020-10-03 20:23:02) > > > > > > On Fri, Oct 02, 2020 at 08:03:28PM +0200, Anton Khirnov wrote: > > > > > > > --- > > > > > > > libavfilter/Makefile | 2 +- > > > > > > > libavfilter/vf_spp.c | 57 ++++++++++++++++--------------------- > > > > > > > libavfilter/vf_spp.h | 3 +- > > > > > > > tests/fate/filter-video.mak | 4 +-- > > > > > > > 4 files changed, 29 insertions(+), 37 deletions(-) > > > > > > > > > > > > > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile > > > > > > > index d20f2937b6..2669d7b84b 100644 > > > > > > > --- a/libavfilter/Makefile > > > > > > > +++ b/libavfilter/Makefile > > > > > > > @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o > > > > > > > OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ > > > > > > > opencl/convolution.o > > > > > > > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > > > > > > > -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o > > > > > > > +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o > > > > > > > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > > > > > > > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > > > > > > > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > > > > > > > diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c > > > > > > > index 4bcc6429e0..2eb383be03 100644 > > > > > > > --- a/libavfilter/vf_spp.c > > > > > > > +++ b/libavfilter/vf_spp.c > > > > > > > @@ -36,6 +36,7 @@ > > > > > > > #include "libavutil/opt.h" > > > > > > > #include "libavutil/pixdesc.h" > > > > > > > #include "internal.h" > > > > > > > +#include "qp_table.h" > > > > > > > #include "vf_spp.h" > > > > > > > > > > > > > > enum mode { > > > > > > > @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, > > > > > > > } else{ > > > > > > > const int qps = 3 + is_luma; > > > > > > > qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; > > > > > > > - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); > > > > > > > + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); > > > > > > > > > > > > wouldnt this break the cases where qscale_type is not FF_QSCALE_TYPE_MPEG2 ? > > > > > > > > > > There should be no such cases - in the new API, only TYPE_MPEG2 exists > > > > > (disregarding newer codecs that were not supported by this filter > > > > > anyway). > > > > > > > > before the patch the code was intended to convert the quantization step size > > > > used in the codec to the same scale as the filter used. disregarding if the > > > > codec was 8x8 dct based. In fact spp should not require the input to be 8x8 dct > > > > based at all, why should it? It uses the DCT as a means to favor real images > > > > and remove "noise" that is not part of real images. It should for example also > > > > work if a image has blocking artifacts that look like hexagons or triangles > > > > > > > > I never tried but H264 with disabled loop filter should benefit from spp in > > > > terms of subjective quality as long as the filter strength is set appropriately > > > > That is for streams where the bitrate is low enough to see artifacts > > > > > > Are you saying I should expand this filter to support new codecs? That > > > does not seem appropriate for a patch that only adapts it to new API. > > > > no > > but before your patch theres a central place ff_norm_qscale() > > that has access to both the QP type (codec type) and the QP > > and can produce a standarized QP > > So someone who wanted to SPP support some random new codec could > > do it there and at the same time have 4 other filters for free also > > support the new codec. > > ff_norm_qscale() is still there and the filter still calls it. But if > someone wants to extend it to support other codecs, they still need to > add code to ff_qp_table_extract() to handle > AVVideoEncParams.type != AV_VIDEO_ENC_PARAMS_MPEG2. > > It does not seem reasonable to me to pretend the code supports something > that it actually does not. I see what you mean but as its done by the patch the code is not clean afterwards at all. For example the argument is always the same, it asks for it being removed. If you dont want to pass the type without support in ff_qp_table_extract() then IMHO its better to add very minimal generic support in ff_qp_table_extract() instead of hardcoding a type leaving the code with a constant argument. [...] > > If you use AVVideoEncParamsType or something equivalent to it / qp_type then > > that resolves this concern > > > > unless iam missing something of course ... > > It cannot be handled generically (at least not easily), because the data > layout allowed by AVVideoBlockParams is more general than the one > handled by those *pp filters. Additionally, the interpretation of qp is > codec-dependent. So IMO the code should not pretends it can handle > arbitrary codecs, when it is not actually true. I dont see why generic handling wouldnt work or is hard input is a set of rectangles, output is a ordered list of 16x16 squares The simplest could be a mere intersect and take maximum of the QP one wouldnt even need to use average for this to probably work reasonable codec specific QP would need to be mapped to the expectec scale though to avoid misunderstanding, iam not asking you to do any work here, just not to remove things like the type. OTOH if you want it to be all functional or not at all i think a very basic version of this should be rather simple that said, iam not blocking any patches above is just my oppinion Thanks [...]
diff --git a/libavfilter/Makefile b/libavfilter/Makefile index d20f2937b6..2669d7b84b 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -404,7 +404,7 @@ OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o \ opencl/convolution.o OBJS-$(CONFIG_SPLIT_FILTER) += split.o -OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o +OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o qp_table.o OBJS-$(CONFIG_SR_FILTER) += vf_sr.o OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o diff --git a/libavfilter/vf_spp.c b/libavfilter/vf_spp.c index 4bcc6429e0..2eb383be03 100644 --- a/libavfilter/vf_spp.c +++ b/libavfilter/vf_spp.c @@ -36,6 +36,7 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "internal.h" +#include "qp_table.h" #include "vf_spp.h" enum mode { @@ -289,7 +290,7 @@ static void filter(SPPContext *p, uint8_t *dst, uint8_t *src, } else{ const int qps = 3 + is_luma; qp = qp_table[(FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride]; - qp = FFMAX(1, ff_norm_qscale(qp, p->qscale_type)); + qp = FFMAX(1, ff_norm_qscale(qp, FF_QSCALE_TYPE_MPEG2)); } for (i = 0; i < count; i++) { const int x1 = x + offset[i + count - 1][0]; @@ -374,47 +375,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out = in; int qp_stride = 0; - const int8_t *qp_table = NULL; + int8_t *qp_table = NULL; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); const int depth = desc->comp[0].depth; + int ret = 0; /* if we are not in a constant user quantizer mode and we don't want to use * the quantizers from the B-frames (B-frames often have a higher QP), we * need to save the qp table from the last non B-frame; this is what the * following code block does */ - if (!s->qp) { - qp_table = av_frame_get_qp_table(in, &qp_stride, &s->qscale_type); - - if (qp_table && !s->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { - int w, h; - - /* if the qp stride is not set, it means the QP are only defined on - * a line basis */ - if (!qp_stride) { - w = AV_CEIL_RSHIFT(inlink->w, 4); - h = 1; - } else { - w = qp_stride; - h = AV_CEIL_RSHIFT(inlink->h, 4); - } - - if (w * h > s->non_b_qp_alloc_size) { - int ret = av_reallocp_array(&s->non_b_qp_table, w, h); - if (ret < 0) { - s->non_b_qp_alloc_size = 0; - return ret; - } - s->non_b_qp_alloc_size = w * h; - } + if (!s->qp && (s->use_bframe_qp || in->pict_type != AV_PICTURE_TYPE_B)) { + ret = ff_qp_table_extract(in, &qp_table, &qp_stride, NULL); + if (ret < 0) { + av_frame_free(&in); + return ret; + } - av_assert0(w * h <= s->non_b_qp_alloc_size); - memcpy(s->non_b_qp_table, qp_table, w * h); + if (!s->use_bframe_qp && in->pict_type != AV_PICTURE_TYPE_B) { + av_freep(&s->non_b_qp_table); + s->non_b_qp_table = qp_table; + s->non_b_qp_stride = qp_stride; } } if (s->log2_count && !ctx->is_disabled) { - if (!s->use_bframe_qp && s->non_b_qp_table) - qp_table = s->non_b_qp_table; + if (!s->use_bframe_qp && s->non_b_qp_table) { + qp_table = s->non_b_qp_table; + qp_stride = s->non_b_qp_stride; + } if (qp_table || s->qp) { const int cw = AV_CEIL_RSHIFT(inlink->w, s->hsub); @@ -429,7 +417,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out = ff_get_video_buffer(outlink, aligned_w, aligned_h); if (!out) { av_frame_free(&in); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto finish; } av_frame_copy_props(out, in); out->width = in->width; @@ -453,7 +442,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) inlink->w, inlink->h); av_frame_free(&in); } - return ff_filter_frame(outlink, out); + ret = ff_filter_frame(outlink, out); +finish: + if (qp_table != s->non_b_qp_table) + av_freep(&qp_table); + return ret; } static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, diff --git a/libavfilter/vf_spp.h b/libavfilter/vf_spp.h index 879ed40f03..00caf5780d 100644 --- a/libavfilter/vf_spp.h +++ b/libavfilter/vf_spp.h @@ -33,13 +33,12 @@ typedef struct SPPContext { int log2_count; int qp; int mode; - int qscale_type; int temp_linesize; uint8_t *src; uint16_t *temp; AVDCT *dct; int8_t *non_b_qp_table; - int non_b_qp_alloc_size; + int non_b_qp_stride; int use_bframe_qp; int hsub, vsub; diff --git a/tests/fate/filter-video.mak b/tests/fate/filter-video.mak index 98df744f16..202c7f30d7 100644 --- a/tests/fate/filter-video.mak +++ b/tests/fate/filter-video.mak @@ -574,9 +574,9 @@ fate-filter-pp6: CMD = video_filter "pp=be/fd" fate-filter-pp7: fate-vsynth1-mpeg4-qprd fate-filter-pp7: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "pp7" -#FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp +FATE_FILTER_VSYNTH-$(CONFIG_SPP_FILTER) += fate-filter-spp fate-filter-spp: fate-vsynth1-mpeg4-qprd -fate-filter-spp: CMD = framecrc -flags bitexact -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "spp=idct=simple:dct=int" +fate-filter-spp: CMD = framecrc -flags bitexact -export_side_data venc_params -idct simple -i $(TARGET_PATH)/tests/data/fate/vsynth1-mpeg4-qprd.avi -frames:v 5 -flags +bitexact -vf "spp=idct=simple:dct=int" FATE_FILTER_VSYNTH-$(CONFIG_CODECVIEW_FILTER) += fate-filter-codecview fate-filter-codecview: fate-vsynth1-mpeg4-qprd