* [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support
@ 2023-03-19 14:15 Michael Niedermayer
2023-03-19 14:15 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support Michael Niedermayer
2023-03-19 15:34 ` [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support James Almer
0 siblings, 2 replies; 6+ messages in thread
From: Michael Niedermayer @ 2023-03-19 14:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavcodec/snowenc.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 658684c575..a03e4292ee 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -26,6 +26,7 @@
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
+#include "internal.h" //For AVCodecInternal.recon_frame
#include "me_cmp.h"
#include "packet_internal.h"
#include "snow_dwt.h"
@@ -1576,6 +1577,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
{
SnowContext *s = avctx->priv_data;
RangeCoder * const c= &s->c;
+ AVCodecInternal *avci = avctx->internal;
AVFrame *pic;
const int width= s->avctx->width;
const int height= s->avctx->height;
@@ -1877,6 +1879,10 @@ redo_frame:
s->encoding_error,
(s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
s->current_picture->pict_type);
+ if (avci->recon_frame) {
+ av_frame_unref(avci->recon_frame);
+ av_frame_ref(avci->recon_frame, s->current_picture);
+ }
pkt->size = ff_rac_terminate(c, 0);
if (s->current_picture->key_frame)
@@ -1934,7 +1940,9 @@ const FFCodec ff_snow_encoder = {
CODEC_LONG_NAME("Snow"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_SNOW,
- .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+ .p.capabilities = AV_CODEC_CAP_DR1 |
+ AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+ AV_CODEC_CAP_ENCODER_RECON_FRAME,
.priv_data_size = sizeof(SnowContext),
.init = encode_init,
FF_CODEC_ENCODE_CB(encode_frame),
--
2.17.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support
2023-03-19 14:15 [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support Michael Niedermayer
@ 2023-03-19 14:15 ` Michael Niedermayer
2023-03-19 14:24 ` James Almer
2023-03-19 15:34 ` [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support James Almer
1 sibling, 1 reply; 6+ messages in thread
From: Michael Niedermayer @ 2023-03-19 14:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
about 50% faster (based on command line fps)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
libavfilter/vf_uspp.c | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
index f60eb230a2..9318410089 100644
--- a/libavfilter/vf_uspp.c
+++ b/libavfilter/vf_uspp.c
@@ -231,16 +231,25 @@ static int filter_1phase(AVFilterContext *ctx, void *arg, int i, int nb_jobs)
return ret;
}
- ret = avcodec_send_packet(p->avctx_dec[i], pkt);
- av_packet_unref(pkt);
- if (ret < 0) {
- av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
- return ret;
- }
- ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec[i]);
- if (ret < 0) {
- av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
- return ret;
+ if (p->avctx_enc[i]->flags & AV_CODEC_FLAG_RECON_FRAME) {
+ av_packet_unref(pkt);
+ ret = avcodec_receive_frame(p->avctx_enc[i], p->frame_dec[i]);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from encoding\n");
+ return ret;
+ }
+ } else {
+ ret = avcodec_send_packet(p->avctx_dec[i], pkt);
+ av_packet_unref(pkt);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
+ return ret;
+ }
+ ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec[i]);
+ if (ret < 0) {
+ av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
+ return ret;
+ }
}
offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec[i]->linesize[0];
@@ -397,6 +406,10 @@ static int config_input(AVFilterLink *inlink)
avctx_enc->max_b_frames = 0;
avctx_enc->pix_fmt = inlink->format;
avctx_enc->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY;
+ if (enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME) {
+ avctx_enc->flags |= AV_CODEC_FLAG_RECON_FRAME;
+ av_dict_set(&opts, "no_bitstream", "1", 0);
+ }
avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
avctx_enc->global_quality = 123;
avctx_dec->thread_count =
@@ -408,9 +421,11 @@ static int config_input(AVFilterLink *inlink)
av_assert0(avctx_enc->codec);
- ret = avcodec_open2(avctx_dec, dec, NULL);
- if (ret < 0)
- return ret;
+ if (!(enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME)) {
+ ret = avcodec_open2(avctx_dec, dec, NULL);
+ if (ret < 0)
+ return ret;
+ }
if (!(uspp->frame[i] = av_frame_alloc()))
return AVERROR(ENOMEM);
--
2.17.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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support
2023-03-19 14:15 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support Michael Niedermayer
@ 2023-03-19 14:24 ` James Almer
2023-03-19 19:39 ` Michael Niedermayer
0 siblings, 1 reply; 6+ messages in thread
From: James Almer @ 2023-03-19 14:24 UTC (permalink / raw)
To: ffmpeg-devel
On 3/19/2023 11:15 AM, Michael Niedermayer wrote:
> about 50% faster (based on command line fps)
You should not allocate the 256 decoders if the encoder is a
AV_CODEC_FLAG_RECON_FRAME one, as they will not be used.
Doing so would save memory and speed up initialization.
>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavfilter/vf_uspp.c | 41 ++++++++++++++++++++++++++++-------------
> 1 file changed, 28 insertions(+), 13 deletions(-)
>
> diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c
> index f60eb230a2..9318410089 100644
> --- a/libavfilter/vf_uspp.c
> +++ b/libavfilter/vf_uspp.c
> @@ -231,16 +231,25 @@ static int filter_1phase(AVFilterContext *ctx, void *arg, int i, int nb_jobs)
> return ret;
> }
>
> - ret = avcodec_send_packet(p->avctx_dec[i], pkt);
> - av_packet_unref(pkt);
> - if (ret < 0) {
> - av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
> - return ret;
> - }
> - ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec[i]);
> - if (ret < 0) {
> - av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
> - return ret;
> + if (p->avctx_enc[i]->flags & AV_CODEC_FLAG_RECON_FRAME) {
> + av_packet_unref(pkt);
> + ret = avcodec_receive_frame(p->avctx_enc[i], p->frame_dec[i]);
> + if (ret < 0) {
> + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from encoding\n");
> + return ret;
> + }
> + } else {
> + ret = avcodec_send_packet(p->avctx_dec[i], pkt);
> + av_packet_unref(pkt);
> + if (ret < 0) {
> + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n");
> + return ret;
> + }
> + ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec[i]);
> + if (ret < 0) {
> + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n");
> + return ret;
> + }
> }
>
> offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec[i]->linesize[0];
> @@ -397,6 +406,10 @@ static int config_input(AVFilterLink *inlink)
> avctx_enc->max_b_frames = 0;
> avctx_enc->pix_fmt = inlink->format;
> avctx_enc->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY;
> + if (enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME) {
> + avctx_enc->flags |= AV_CODEC_FLAG_RECON_FRAME;
> + av_dict_set(&opts, "no_bitstream", "1", 0);
> + }
> avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
> avctx_enc->global_quality = 123;
> avctx_dec->thread_count =
> @@ -408,9 +421,11 @@ static int config_input(AVFilterLink *inlink)
> av_assert0(avctx_enc->codec);
>
>
> - ret = avcodec_open2(avctx_dec, dec, NULL);
> - if (ret < 0)
> - return ret;
> + if (!(enc->capabilities & AV_CODEC_CAP_ENCODER_RECON_FRAME)) {
> + ret = avcodec_open2(avctx_dec, dec, NULL);
> + if (ret < 0)
> + return ret;
> + }
>
> if (!(uspp->frame[i] = av_frame_alloc()))
> return AVERROR(ENOMEM);
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support
2023-03-19 14:24 ` James Almer
@ 2023-03-19 19:39 ` Michael Niedermayer
0 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2023-03-19 19:39 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 574 bytes --]
On Sun, Mar 19, 2023 at 11:24:54AM -0300, James Almer wrote:
> On 3/19/2023 11:15 AM, Michael Niedermayer wrote:
> > about 50% faster (based on command line fps)
>
> You should not allocate the 256 decoders if the encoder is a
> AV_CODEC_FLAG_RECON_FRAME one, as they will not be used.
> Doing so would save memory and speed up initialization.
ok will post a new patchset
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The educated differ from the uneducated as much as the living from the
dead. -- Aristotle
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support
2023-03-19 14:15 [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support Michael Niedermayer
2023-03-19 14:15 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support Michael Niedermayer
@ 2023-03-19 15:34 ` James Almer
2023-03-19 19:27 ` Michael Niedermayer
1 sibling, 1 reply; 6+ messages in thread
From: James Almer @ 2023-03-19 15:34 UTC (permalink / raw)
To: ffmpeg-devel
On 3/19/2023 11:15 AM, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavcodec/snowenc.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
> index 658684c575..a03e4292ee 100644
> --- a/libavcodec/snowenc.c
> +++ b/libavcodec/snowenc.c
> @@ -26,6 +26,7 @@
> #include "avcodec.h"
> #include "codec_internal.h"
> #include "encode.h"
> +#include "internal.h" //For AVCodecInternal.recon_frame
> #include "me_cmp.h"
> #include "packet_internal.h"
> #include "snow_dwt.h"
> @@ -1576,6 +1577,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> {
> SnowContext *s = avctx->priv_data;
> RangeCoder * const c= &s->c;
> + AVCodecInternal *avci = avctx->internal;
> AVFrame *pic;
> const int width= s->avctx->width;
> const int height= s->avctx->height;
> @@ -1877,6 +1879,10 @@ redo_frame:
> s->encoding_error,
> (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
> s->current_picture->pict_type);
> + if (avci->recon_frame) {
The proper check is (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME).
avci->recon_frame could start being allocated unconditionally in the
future for whatever reason.
> + av_frame_unref(avci->recon_frame);
> + av_frame_ref(avci->recon_frame, s->current_picture);
> + }
>
> pkt->size = ff_rac_terminate(c, 0);
> if (s->current_picture->key_frame)
> @@ -1934,7 +1940,9 @@ const FFCodec ff_snow_encoder = {
> CODEC_LONG_NAME("Snow"),
> .p.type = AVMEDIA_TYPE_VIDEO,
> .p.id = AV_CODEC_ID_SNOW,
> - .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> + .p.capabilities = AV_CODEC_CAP_DR1 |
> + AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
> + AV_CODEC_CAP_ENCODER_RECON_FRAME,
> .priv_data_size = sizeof(SnowContext),
> .init = encode_init,
> FF_CODEC_ENCODE_CB(encode_frame),
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support
2023-03-19 15:34 ` [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support James Almer
@ 2023-03-19 19:27 ` Michael Niedermayer
0 siblings, 0 replies; 6+ messages in thread
From: Michael Niedermayer @ 2023-03-19 19:27 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2152 bytes --]
On Sun, Mar 19, 2023 at 12:34:50PM -0300, James Almer wrote:
> On 3/19/2023 11:15 AM, Michael Niedermayer wrote:
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> > libavcodec/snowenc.c | 10 +++++++++-
> > 1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
> > index 658684c575..a03e4292ee 100644
> > --- a/libavcodec/snowenc.c
> > +++ b/libavcodec/snowenc.c
> > @@ -26,6 +26,7 @@
> > #include "avcodec.h"
> > #include "codec_internal.h"
> > #include "encode.h"
> > +#include "internal.h" //For AVCodecInternal.recon_frame
> > #include "me_cmp.h"
> > #include "packet_internal.h"
> > #include "snow_dwt.h"
> > @@ -1576,6 +1577,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> > {
> > SnowContext *s = avctx->priv_data;
> > RangeCoder * const c= &s->c;
> > + AVCodecInternal *avci = avctx->internal;
> > AVFrame *pic;
> > const int width= s->avctx->width;
> > const int height= s->avctx->height;
> > @@ -1877,6 +1879,10 @@ redo_frame:
> > s->encoding_error,
> > (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
> > s->current_picture->pict_type);
> > + if (avci->recon_frame) {
>
> The proper check is (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME).
> avci->recon_frame could start being allocated unconditionally in the future
> for whatever reason.
The docomentation says:
/**
* When the AV_CODEC_FLAG_RECON_FRAME flag is used. the encoder should store
* here the reconstructed frame corresponding to the last returned packet.
*
* Not allocated in other cases.
*/
AVFrame *recon_frame;
If thats not meant to be assumed to be true, the documentation should state
this differently
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-03-19 19:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19 14:15 [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support Michael Niedermayer
2023-03-19 14:15 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_uspp: add AV_CODEC_FLAG_RECON_FRAME support Michael Niedermayer
2023-03-19 14:24 ` James Almer
2023-03-19 19:39 ` Michael Niedermayer
2023-03-19 15:34 ` [FFmpeg-devel] [PATCH 1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support James Almer
2023-03-19 19:27 ` Michael Niedermayer
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git