Message ID | 20240508151950.28555-1-ramiro.polla@gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v2,1/2] libavcodec/mpegvideo_enc: fix multi-threaded motion estimation rounding for mpeg4 | expand |
On Wed, May 08, 2024 at 05:19:49PM +0200, Ramiro Polla wrote: > ff_init_me() was being called after ff_update_duplicate_context(), > which caused the propagation of the initialization to other thread > contexts to be delayed by one frame. > > In the case of mpeg4 (or flipflop_rounding), this would make the > hpel_put functions differ between the first thread (which would be > correctly initialized) and the other threads (which would be stale > from the previous frame). > --- > libavcodec/mpegvideo_enc.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) have you confirmed the actual used rounding matches after this encoder & decoder side ? if yes then this should be ok thx [...]
On Thu, May 9, 2024 at 2:44 AM Michael Niedermayer <michael@niedermayer.cc> wrote: > On Wed, May 08, 2024 at 05:19:49PM +0200, Ramiro Polla wrote: > > ff_init_me() was being called after ff_update_duplicate_context(), > > which caused the propagation of the initialization to other thread > > contexts to be delayed by one frame. > > > > In the case of mpeg4 (or flipflop_rounding), this would make the > > hpel_put functions differ between the first thread (which would be > > correctly initialized) and the other threads (which would be stale > > from the previous frame). > > --- > > libavcodec/mpegvideo_enc.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > have you confirmed the actual used rounding matches after this > encoder & decoder side ? Yes, I just rechecked it. It used to be wrong (only the first slice would use the correct hpel/qpel functions in the encoder according to the no_rounding flag in the bitstream). > if yes then this should be ok Thanks. Pushed.
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 2a75973ac4..b601a1a9e4 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3623,6 +3623,9 @@ static int encode_picture(MpegEncContext *s) s->q_chroma_intra_matrix16 = s->q_intra_matrix16; } + if(ff_init_me(s)<0) + return -1; + s->mb_intra=0; //for the rate distortion & bit compare functions for(i=1; i<context_count; i++){ ret = ff_update_duplicate_context(s->thread_context[i], s); @@ -3630,9 +3633,6 @@ static int encode_picture(MpegEncContext *s) return ret; } - if(ff_init_me(s)<0) - return -1; - /* Estimate motion for every MB */ if(s->pict_type != AV_PICTURE_TYPE_I){ s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8;