Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
On Sun, Jan 12, 2020 at 9:02 PM Andriy Gelman wrote: > Hello Asaf, > > If you compile the code, there are many warning about mixed declaration > and code. > Hi Andriy, I will take a look again and try to avoid those warnings. Also i will fix the points you mention, thank you for your time. Will update patch soon. I had a quick look code and have comments below: > > On Sun, 29. Dec 16:08, Asaf Kave wrote: > > --- > > libavcodec/hevc_refs.c | 15 > > libavcodec/hevcdec.c | 173 - > > libavcodec/hevcdec.h | 13 > > 3 files changed, 200 insertions(+), 1 deletion(-) > > > > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c > > index 7870a72fd6..20f028fa73 100644 > > --- a/libavcodec/hevc_refs.c > > +++ b/libavcodec/hevc_refs.c > > @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame > *frame, int flags) > > av_buffer_unref(&frame->tab_mvf_buf); > > frame->tab_mvf = NULL; > > > > +av_buffer_unref(&frame->cuh_buf); > > +frame->cuh = NULL; > > + > > av_buffer_unref(&frame->rpl_buf); > > av_buffer_unref(&frame->rpl_tab_buf); > > frame->rpl_tab= NULL; > > @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) > > goto fail; > > frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; > > > > +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); > > +if (!frame->cuh_buf) > > +goto fail; > > +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; > > + > > frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); > > if (!frame->rpl_tab_buf) > > goto fail; > > frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; > > frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; > > +frame->cu_count = 0; > > for (j = 0; j < frame->ctb_count; j++) > > frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; > > > > @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame > **frame, int poc) > > else > > ref->flags = HEVC_FRAME_FLAG_SHORT_REF; > > > > +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { > > +ref->flags |= HEVC_FRAME_FLAG_MV; > > +} > > + > > ref->poc = poc; > > ref->sequence = s->seq_decode; > > ref->frame->crop_left = s->ps.sps->output_window.left_offset; > > @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame > *out, int flush) > > if (ret < 0) > > return ret; > > > > +s->output_frame_poc = frame->poc; > > + > > av_log(s->avctx, AV_LOG_DEBUG, > > "Output frame with POC %d.\n", frame->poc); > > return 1; > > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > > index 19b0cd815d..aedc559283 100644 > > --- a/libavcodec/hevcdec.c > > +++ b/libavcodec/hevcdec.c > > @@ -32,6 +32,7 @@ > > #include "libavutil/opt.h" > > #include "libavutil/pixdesc.h" > > #include "libavutil/stereo3d.h" > > +#include "libavutil/motion_vector.h" > > > > #include "bswapdsp.h" > > #include "bytestream.h" > > @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) > > av_freep(&s->sh.offset); > > > > av_buffer_pool_uninit(&s->tab_mvf_pool); > > +av_buffer_pool_uninit(&s->cuh_pool); > > av_buffer_pool_uninit(&s->rpl_tab_pool); > > } > > > > @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const > HEVCSPS *sps) > > > > s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), > >av_buffer_allocz); > > +s->cuh_pool = av_buffer_pool_init(min_pu_size * > sizeof(CodingUnitHelper), > > + av_buffer_allocz); > > s->rpl_tab_pool = av_buffer_pool_init(ctb_count * > sizeof(RefPicListTab), > >av_buffer_allocz); > > -if (!s->tab_mvf_pool || !s->rpl_tab_pool) > > +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) > > goto fail; > > > > return 0; > > @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, > int x0, int y0, > > int min_pu_width = s->ps.sps->min_pu_width; > > > > MvField *tab_mvf = s->ref->tab_mvf; > > +CodingUnitHelper *cuh = s->ref->cuh; > > RefPicList *refPicList = s->ref->refPicList; > > HEVCFrame *ref0 = NULL, *ref1 = NULL; > > uint8_t *dst0 = POS(0, x0, y0); > > @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, > int x0, int y0, > > for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) > > tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; > > > > > +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; > > do you need this stack variable? > Yes, i am assigning it to the ' cuh' that is alias to 's->ref->cuh' , that hol
Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
Hello Asaf, If you compile the code, there are many warning about mixed declaration and code. I had a quick look code and have comments below: On Sun, 29. Dec 16:08, Asaf Kave wrote: > --- > libavcodec/hevc_refs.c | 15 > libavcodec/hevcdec.c | 173 - > libavcodec/hevcdec.h | 13 > 3 files changed, 200 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c > index 7870a72fd6..20f028fa73 100644 > --- a/libavcodec/hevc_refs.c > +++ b/libavcodec/hevc_refs.c > @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, > int flags) > av_buffer_unref(&frame->tab_mvf_buf); > frame->tab_mvf = NULL; > > +av_buffer_unref(&frame->cuh_buf); > +frame->cuh = NULL; > + > av_buffer_unref(&frame->rpl_buf); > av_buffer_unref(&frame->rpl_tab_buf); > frame->rpl_tab= NULL; > @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) > goto fail; > frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; > > +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); > +if (!frame->cuh_buf) > +goto fail; > +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; > + > frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); > if (!frame->rpl_tab_buf) > goto fail; > frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; > frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; > +frame->cu_count = 0; > for (j = 0; j < frame->ctb_count; j++) > frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; > > @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, > int poc) > else > ref->flags = HEVC_FRAME_FLAG_SHORT_REF; > > +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { > +ref->flags |= HEVC_FRAME_FLAG_MV; > +} > + > ref->poc = poc; > ref->sequence = s->seq_decode; > ref->frame->crop_left = s->ps.sps->output_window.left_offset; > @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, > int flush) > if (ret < 0) > return ret; > > +s->output_frame_poc = frame->poc; > + > av_log(s->avctx, AV_LOG_DEBUG, > "Output frame with POC %d.\n", frame->poc); > return 1; > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > index 19b0cd815d..aedc559283 100644 > --- a/libavcodec/hevcdec.c > +++ b/libavcodec/hevcdec.c > @@ -32,6 +32,7 @@ > #include "libavutil/opt.h" > #include "libavutil/pixdesc.h" > #include "libavutil/stereo3d.h" > +#include "libavutil/motion_vector.h" > > #include "bswapdsp.h" > #include "bytestream.h" > @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) > av_freep(&s->sh.offset); > > av_buffer_pool_uninit(&s->tab_mvf_pool); > +av_buffer_pool_uninit(&s->cuh_pool); > av_buffer_pool_uninit(&s->rpl_tab_pool); > } > > @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS > *sps) > > s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), >av_buffer_allocz); > +s->cuh_pool = av_buffer_pool_init(min_pu_size * sizeof(CodingUnitHelper), > + av_buffer_allocz); > s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab), >av_buffer_allocz); > -if (!s->tab_mvf_pool || !s->rpl_tab_pool) > +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) > goto fail; > > return 0; > @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, > int y0, > int min_pu_width = s->ps.sps->min_pu_width; > > MvField *tab_mvf = s->ref->tab_mvf; > +CodingUnitHelper *cuh = s->ref->cuh; > RefPicList *refPicList = s->ref->refPicList; > HEVCFrame *ref0 = NULL, *ref1 = NULL; > uint8_t *dst0 = POS(0, x0, y0); > @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, int x0, > int y0, > for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) > tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; > > +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; do you need this stack variable? > +cuh[s->ref->cu_count++] = cuh_; > + > if (current_mv.pred_flag & PF_L0) { > ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; > if (!ref0) > @@ -3192,6 +3200,160 @@ static int hevc_decode_extradata(HEVCContext *s, > uint8_t *buf, int length, int f > return 0; > } > > +static int set_mv(AVMotionVector *mv, int puW, int puH, > + int dst_x, int dst_y, > + int motion_x, int motion_y, int motion_scale, > +
Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
On Wed, Jan 8, 2020 at 11:30 AM Asaf Kave wrote: > > > On Tue, Jan 7, 2020 at 4:49 AM Zhong Li wrote: > >> Haven't tested but patch LGTM >> > > Thanks Li for the feedback. > > >> >> Asaf Kave 于2019年12月29日周日 下午10:08写道: >> > >> > --- >> > libavcodec/hevc_refs.c | 15 >> > libavcodec/hevcdec.c | 173 - >> > libavcodec/hevcdec.h | 13 >> > 3 files changed, 200 insertions(+), 1 deletion(-) >> > >> > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c >> > index 7870a72fd6..20f028fa73 100644 >> > --- a/libavcodec/hevc_refs.c >> > +++ b/libavcodec/hevc_refs.c >> > @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame >> *frame, int flags) >> > av_buffer_unref(&frame->tab_mvf_buf); >> > frame->tab_mvf = NULL; >> > >> > +av_buffer_unref(&frame->cuh_buf); >> > +frame->cuh = NULL; >> > + >> > av_buffer_unref(&frame->rpl_buf); >> > av_buffer_unref(&frame->rpl_tab_buf); >> > frame->rpl_tab= NULL; >> > @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) >> > goto fail; >> > frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; >> > >> > +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); >> > +if (!frame->cuh_buf) >> > +goto fail; >> > +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; >> > + >> > frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); >> > if (!frame->rpl_tab_buf) >> > goto fail; >> > frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; >> > frame->ctb_count = s->ps.sps->ctb_width * >> s->ps.sps->ctb_height; >> > +frame->cu_count = 0; >> > for (j = 0; j < frame->ctb_count; j++) >> > frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; >> > >> > @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame >> **frame, int poc) >> > else >> > ref->flags = HEVC_FRAME_FLAG_SHORT_REF; >> > >> > +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { >> > +ref->flags |= HEVC_FRAME_FLAG_MV; >> > +} >> > + >> > ref->poc = poc; >> > ref->sequence = s->seq_decode; >> > ref->frame->crop_left = s->ps.sps->output_window.left_offset; >> > @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame >> *out, int flush) >> > if (ret < 0) >> > return ret; >> > >> > +s->output_frame_poc = frame->poc; >> > + >> > av_log(s->avctx, AV_LOG_DEBUG, >> > "Output frame with POC %d.\n", frame->poc); >> > return 1; >> > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c >> > index 19b0cd815d..aedc559283 100644 >> > --- a/libavcodec/hevcdec.c >> > +++ b/libavcodec/hevcdec.c >> > @@ -32,6 +32,7 @@ >> > #include "libavutil/opt.h" >> > #include "libavutil/pixdesc.h" >> > #include "libavutil/stereo3d.h" >> > +#include "libavutil/motion_vector.h" >> > >> > #include "bswapdsp.h" >> > #include "bytestream.h" >> > @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) >> > av_freep(&s->sh.offset); >> > >> > av_buffer_pool_uninit(&s->tab_mvf_pool); >> > +av_buffer_pool_uninit(&s->cuh_pool); >> > av_buffer_pool_uninit(&s->rpl_tab_pool); >> > } >> > >> > @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const >> HEVCSPS *sps) >> > >> > s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * >> sizeof(MvField), >> >av_buffer_allocz); >> > +s->cuh_pool = av_buffer_pool_init(min_pu_size * >> sizeof(CodingUnitHelper), >> > + av_buffer_allocz); >> > s->rpl_tab_pool = av_buffer_pool_init(ctb_count * >> sizeof(RefPicListTab), >> >av_buffer_allocz); >> > -if (!s->tab_mvf_pool || !s->rpl_tab_pool) >> > +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) >> > goto fail; >> > >> > return 0; >> > @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, >> int x0, int y0, >> > int min_pu_width = s->ps.sps->min_pu_width; >> > >> > MvField *tab_mvf = s->ref->tab_mvf; >> > +CodingUnitHelper *cuh = s->ref->cuh; >> > RefPicList *refPicList = s->ref->refPicList; >> > HEVCFrame *ref0 = NULL, *ref1 = NULL; >> > uint8_t *dst0 = POS(0, x0, y0); >> > @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, >> int x0, int y0, >> > for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) >> > tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; >> > >> > +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; >> > +cuh[s->ref->cu_count++] = cuh_; >> > + >> > if (current_mv.pred_flag & PF_L0) { >> > ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; >> > if (!ref0) >> >
Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
On Tue, Jan 7, 2020 at 4:49 AM Zhong Li wrote: > Haven't tested but patch LGTM > Thanks Li for the feedback. > > Asaf Kave 于2019年12月29日周日 下午10:08写道: > > > > --- > > libavcodec/hevc_refs.c | 15 > > libavcodec/hevcdec.c | 173 - > > libavcodec/hevcdec.h | 13 > > 3 files changed, 200 insertions(+), 1 deletion(-) > > > > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c > > index 7870a72fd6..20f028fa73 100644 > > --- a/libavcodec/hevc_refs.c > > +++ b/libavcodec/hevc_refs.c > > @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame > *frame, int flags) > > av_buffer_unref(&frame->tab_mvf_buf); > > frame->tab_mvf = NULL; > > > > +av_buffer_unref(&frame->cuh_buf); > > +frame->cuh = NULL; > > + > > av_buffer_unref(&frame->rpl_buf); > > av_buffer_unref(&frame->rpl_tab_buf); > > frame->rpl_tab= NULL; > > @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) > > goto fail; > > frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; > > > > +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); > > +if (!frame->cuh_buf) > > +goto fail; > > +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; > > + > > frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); > > if (!frame->rpl_tab_buf) > > goto fail; > > frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; > > frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; > > +frame->cu_count = 0; > > for (j = 0; j < frame->ctb_count; j++) > > frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; > > > > @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame > **frame, int poc) > > else > > ref->flags = HEVC_FRAME_FLAG_SHORT_REF; > > > > +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { > > +ref->flags |= HEVC_FRAME_FLAG_MV; > > +} > > + > > ref->poc = poc; > > ref->sequence = s->seq_decode; > > ref->frame->crop_left = s->ps.sps->output_window.left_offset; > > @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame > *out, int flush) > > if (ret < 0) > > return ret; > > > > +s->output_frame_poc = frame->poc; > > + > > av_log(s->avctx, AV_LOG_DEBUG, > > "Output frame with POC %d.\n", frame->poc); > > return 1; > > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > > index 19b0cd815d..aedc559283 100644 > > --- a/libavcodec/hevcdec.c > > +++ b/libavcodec/hevcdec.c > > @@ -32,6 +32,7 @@ > > #include "libavutil/opt.h" > > #include "libavutil/pixdesc.h" > > #include "libavutil/stereo3d.h" > > +#include "libavutil/motion_vector.h" > > > > #include "bswapdsp.h" > > #include "bytestream.h" > > @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) > > av_freep(&s->sh.offset); > > > > av_buffer_pool_uninit(&s->tab_mvf_pool); > > +av_buffer_pool_uninit(&s->cuh_pool); > > av_buffer_pool_uninit(&s->rpl_tab_pool); > > } > > > > @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const > HEVCSPS *sps) > > > > s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), > >av_buffer_allocz); > > +s->cuh_pool = av_buffer_pool_init(min_pu_size * > sizeof(CodingUnitHelper), > > + av_buffer_allocz); > > s->rpl_tab_pool = av_buffer_pool_init(ctb_count * > sizeof(RefPicListTab), > >av_buffer_allocz); > > -if (!s->tab_mvf_pool || !s->rpl_tab_pool) > > +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) > > goto fail; > > > > return 0; > > @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, > int x0, int y0, > > int min_pu_width = s->ps.sps->min_pu_width; > > > > MvField *tab_mvf = s->ref->tab_mvf; > > +CodingUnitHelper *cuh = s->ref->cuh; > > RefPicList *refPicList = s->ref->refPicList; > > HEVCFrame *ref0 = NULL, *ref1 = NULL; > > uint8_t *dst0 = POS(0, x0, y0); > > @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, > int x0, int y0, > > for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) > > tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; > > > > +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; > > +cuh[s->ref->cu_count++] = cuh_; > > + > > if (current_mv.pred_flag & PF_L0) { > > ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; > > if (!ref0) > > @@ -3192,6 +3200,160 @@ static int hevc_decode_extradata(HEVCContext *s, > uint8_t *buf, int length, int f > > return 0; > > } > > > > +static int set_mv(AVMotionVector *mv, int puW, int
Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
Haven't tested but patch LGTM Asaf Kave 于2019年12月29日周日 下午10:08写道: > > --- > libavcodec/hevc_refs.c | 15 > libavcodec/hevcdec.c | 173 - > libavcodec/hevcdec.h | 13 > 3 files changed, 200 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c > index 7870a72fd6..20f028fa73 100644 > --- a/libavcodec/hevc_refs.c > +++ b/libavcodec/hevc_refs.c > @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, > int flags) > av_buffer_unref(&frame->tab_mvf_buf); > frame->tab_mvf = NULL; > > +av_buffer_unref(&frame->cuh_buf); > +frame->cuh = NULL; > + > av_buffer_unref(&frame->rpl_buf); > av_buffer_unref(&frame->rpl_tab_buf); > frame->rpl_tab= NULL; > @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) > goto fail; > frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; > > +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); > +if (!frame->cuh_buf) > +goto fail; > +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; > + > frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); > if (!frame->rpl_tab_buf) > goto fail; > frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; > frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; > +frame->cu_count = 0; > for (j = 0; j < frame->ctb_count; j++) > frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; > > @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, > int poc) > else > ref->flags = HEVC_FRAME_FLAG_SHORT_REF; > > +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { > +ref->flags |= HEVC_FRAME_FLAG_MV; > +} > + > ref->poc = poc; > ref->sequence = s->seq_decode; > ref->frame->crop_left = s->ps.sps->output_window.left_offset; > @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, > int flush) > if (ret < 0) > return ret; > > +s->output_frame_poc = frame->poc; > + > av_log(s->avctx, AV_LOG_DEBUG, > "Output frame with POC %d.\n", frame->poc); > return 1; > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > index 19b0cd815d..aedc559283 100644 > --- a/libavcodec/hevcdec.c > +++ b/libavcodec/hevcdec.c > @@ -32,6 +32,7 @@ > #include "libavutil/opt.h" > #include "libavutil/pixdesc.h" > #include "libavutil/stereo3d.h" > +#include "libavutil/motion_vector.h" > > #include "bswapdsp.h" > #include "bytestream.h" > @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) > av_freep(&s->sh.offset); > > av_buffer_pool_uninit(&s->tab_mvf_pool); > +av_buffer_pool_uninit(&s->cuh_pool); > av_buffer_pool_uninit(&s->rpl_tab_pool); > } > > @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS > *sps) > > s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), >av_buffer_allocz); > +s->cuh_pool = av_buffer_pool_init(min_pu_size * sizeof(CodingUnitHelper), > + av_buffer_allocz); > s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab), >av_buffer_allocz); > -if (!s->tab_mvf_pool || !s->rpl_tab_pool) > +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) > goto fail; > > return 0; > @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, int x0, > int y0, > int min_pu_width = s->ps.sps->min_pu_width; > > MvField *tab_mvf = s->ref->tab_mvf; > +CodingUnitHelper *cuh = s->ref->cuh; > RefPicList *refPicList = s->ref->refPicList; > HEVCFrame *ref0 = NULL, *ref1 = NULL; > uint8_t *dst0 = POS(0, x0, y0); > @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, int x0, > int y0, > for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) > tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; > > +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; > +cuh[s->ref->cu_count++] = cuh_; > + > if (current_mv.pred_flag & PF_L0) { > ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; > if (!ref0) > @@ -3192,6 +3200,160 @@ static int hevc_decode_extradata(HEVCContext *s, > uint8_t *buf, int length, int f > return 0; > } > > +static int set_mv(AVMotionVector *mv, int puW, int puH, > + int dst_x, int dst_y, > + int motion_x, int motion_y, int motion_scale, > + int direction) > +{ > +mv->w = puW; > +mv->h = puH; > +mv->motion_x = motion_x; > +mv->motion_y = motion_y; > +mv->motion_scale = motion_scale; > +mv->ds
Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
On Thu, Jan 2, 2020 at 11:59 AM Asaf Kave wrote: > > > On Sun, Dec 29, 2019 at 4:08 PM Asaf Kave wrote: > >> --- >> libavcodec/hevc_refs.c | 15 >> libavcodec/hevcdec.c | 173 - >> libavcodec/hevcdec.h | 13 >> 3 files changed, 200 insertions(+), 1 deletion(-) >> >> diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c >> index 7870a72fd6..20f028fa73 100644 >> --- a/libavcodec/hevc_refs.c >> +++ b/libavcodec/hevc_refs.c >> @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame >> *frame, int flags) >> av_buffer_unref(&frame->tab_mvf_buf); >> frame->tab_mvf = NULL; >> >> +av_buffer_unref(&frame->cuh_buf); >> +frame->cuh = NULL; >> + >> av_buffer_unref(&frame->rpl_buf); >> av_buffer_unref(&frame->rpl_tab_buf); >> frame->rpl_tab= NULL; >> @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) >> goto fail; >> frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; >> >> +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); >> +if (!frame->cuh_buf) >> +goto fail; >> +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; >> + >> frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); >> if (!frame->rpl_tab_buf) >> goto fail; >> frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; >> frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; >> +frame->cu_count = 0; >> for (j = 0; j < frame->ctb_count; j++) >> frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; >> >> @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame >> **frame, int poc) >> else >> ref->flags = HEVC_FRAME_FLAG_SHORT_REF; >> >> +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { >> +ref->flags |= HEVC_FRAME_FLAG_MV; >> +} >> + >> ref->poc = poc; >> ref->sequence = s->seq_decode; >> ref->frame->crop_left = s->ps.sps->output_window.left_offset; >> @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame >> *out, int flush) >> if (ret < 0) >> return ret; >> >> +s->output_frame_poc = frame->poc; >> + >> av_log(s->avctx, AV_LOG_DEBUG, >> "Output frame with POC %d.\n", frame->poc); >> return 1; >> diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c >> index 19b0cd815d..aedc559283 100644 >> --- a/libavcodec/hevcdec.c >> +++ b/libavcodec/hevcdec.c >> @@ -32,6 +32,7 @@ >> #include "libavutil/opt.h" >> #include "libavutil/pixdesc.h" >> #include "libavutil/stereo3d.h" >> +#include "libavutil/motion_vector.h" >> >> #include "bswapdsp.h" >> #include "bytestream.h" >> @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) >> av_freep(&s->sh.offset); >> >> av_buffer_pool_uninit(&s->tab_mvf_pool); >> +av_buffer_pool_uninit(&s->cuh_pool); >> av_buffer_pool_uninit(&s->rpl_tab_pool); >> } >> >> @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const >> HEVCSPS *sps) >> >> s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), >>av_buffer_allocz); >> +s->cuh_pool = av_buffer_pool_init(min_pu_size * >> sizeof(CodingUnitHelper), >> + av_buffer_allocz); >> s->rpl_tab_pool = av_buffer_pool_init(ctb_count * >> sizeof(RefPicListTab), >>av_buffer_allocz); >> -if (!s->tab_mvf_pool || !s->rpl_tab_pool) >> +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) >> goto fail; >> >> return 0; >> @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, int >> x0, int y0, >> int min_pu_width = s->ps.sps->min_pu_width; >> >> MvField *tab_mvf = s->ref->tab_mvf; >> +CodingUnitHelper *cuh = s->ref->cuh; >> RefPicList *refPicList = s->ref->refPicList; >> HEVCFrame *ref0 = NULL, *ref1 = NULL; >> uint8_t *dst0 = POS(0, x0, y0); >> @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, int >> x0, int y0, >> for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) >> tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; >> >> +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; >> +cuh[s->ref->cu_count++] = cuh_; >> + >> if (current_mv.pred_flag & PF_L0) { >> ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; >> if (!ref0) >> @@ -3192,6 +3200,160 @@ static int hevc_decode_extradata(HEVCContext *s, >> uint8_t *buf, int length, int f >> return 0; >> } >> >> +static int set_mv(AVMotionVector *mv, int puW, int puH, >> + int dst_x, int dst_y, >> + int motion_x, int motion_y, int motion_scale, >> + int direction)
Re: [FFmpeg-devel] [PATCH] HEVC: Export motion vectors to frame side data.
On Sun, Dec 29, 2019 at 4:08 PM Asaf Kave wrote: > --- > libavcodec/hevc_refs.c | 15 > libavcodec/hevcdec.c | 173 - > libavcodec/hevcdec.h | 13 > 3 files changed, 200 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c > index 7870a72fd6..20f028fa73 100644 > --- a/libavcodec/hevc_refs.c > +++ b/libavcodec/hevc_refs.c > @@ -42,6 +42,9 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame > *frame, int flags) > av_buffer_unref(&frame->tab_mvf_buf); > frame->tab_mvf = NULL; > > +av_buffer_unref(&frame->cuh_buf); > +frame->cuh = NULL; > + > av_buffer_unref(&frame->rpl_buf); > av_buffer_unref(&frame->rpl_tab_buf); > frame->rpl_tab= NULL; > @@ -101,11 +104,17 @@ static HEVCFrame *alloc_frame(HEVCContext *s) > goto fail; > frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; > > +frame->cuh_buf = av_buffer_pool_get(s->cuh_pool); > +if (!frame->cuh_buf) > +goto fail; > +frame->cuh = (CodingUnitHelper *)frame->cuh_buf->data; > + > frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); > if (!frame->rpl_tab_buf) > goto fail; > frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; > frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; > +frame->cu_count = 0; > for (j = 0; j < frame->ctb_count; j++) > frame->rpl_tab[j] = (RefPicListTab *)frame->rpl_buf->data; > > @@ -161,6 +170,10 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame > **frame, int poc) > else > ref->flags = HEVC_FRAME_FLAG_SHORT_REF; > > +if (s->avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) { > +ref->flags |= HEVC_FRAME_FLAG_MV; > +} > + > ref->poc = poc; > ref->sequence = s->seq_decode; > ref->frame->crop_left = s->ps.sps->output_window.left_offset; > @@ -216,6 +229,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, > int flush) > if (ret < 0) > return ret; > > +s->output_frame_poc = frame->poc; > + > av_log(s->avctx, AV_LOG_DEBUG, > "Output frame with POC %d.\n", frame->poc); > return 1; > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > index 19b0cd815d..aedc559283 100644 > --- a/libavcodec/hevcdec.c > +++ b/libavcodec/hevcdec.c > @@ -32,6 +32,7 @@ > #include "libavutil/opt.h" > #include "libavutil/pixdesc.h" > #include "libavutil/stereo3d.h" > +#include "libavutil/motion_vector.h" > > #include "bswapdsp.h" > #include "bytestream.h" > @@ -80,6 +81,7 @@ static void pic_arrays_free(HEVCContext *s) > av_freep(&s->sh.offset); > > av_buffer_pool_uninit(&s->tab_mvf_pool); > +av_buffer_pool_uninit(&s->cuh_pool); > av_buffer_pool_uninit(&s->rpl_tab_pool); > } > > @@ -128,9 +130,11 @@ static int pic_arrays_init(HEVCContext *s, const > HEVCSPS *sps) > > s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), >av_buffer_allocz); > +s->cuh_pool = av_buffer_pool_init(min_pu_size * > sizeof(CodingUnitHelper), > + av_buffer_allocz); > s->rpl_tab_pool = av_buffer_pool_init(ctb_count * > sizeof(RefPicListTab), >av_buffer_allocz); > -if (!s->tab_mvf_pool || !s->rpl_tab_pool) > +if (!s->tab_mvf_pool || !s->rpl_tab_pool || !s->cuh_pool) > goto fail; > > return 0; > @@ -1806,6 +1810,7 @@ static void hls_prediction_unit(HEVCContext *s, int > x0, int y0, > int min_pu_width = s->ps.sps->min_pu_width; > > MvField *tab_mvf = s->ref->tab_mvf; > +CodingUnitHelper *cuh = s->ref->cuh; > RefPicList *refPicList = s->ref->refPicList; > HEVCFrame *ref0 = NULL, *ref1 = NULL; > uint8_t *dst0 = POS(0, x0, y0); > @@ -1843,6 +1848,9 @@ static void hls_prediction_unit(HEVCContext *s, int > x0, int y0, > for (i = 0; i < nPbW >> s->ps.sps->log2_min_pu_size; i++) > tab_mvf[(y_pu + j) * min_pu_width + x_pu + i] = current_mv; > > +struct CodingUnitHelper cuh_ = {lc->cu, log2_cb_size }; > +cuh[s->ref->cu_count++] = cuh_; > + > if (current_mv.pred_flag & PF_L0) { > ref0 = refPicList[0].ref[current_mv.ref_idx[0]]; > if (!ref0) > @@ -3192,6 +3200,160 @@ static int hevc_decode_extradata(HEVCContext *s, > uint8_t *buf, int length, int f > return 0; > } > > +static int set_mv(AVMotionVector *mv, int puW, int puH, > + int dst_x, int dst_y, > + int motion_x, int motion_y, int motion_scale, > + int direction) > +{ > +mv->w = puW; > +mv->h = puH; > +mv->motion_x = motion_x; > +mv->motion_y = motion_y; > +mv->motion_scale = motion_scale; > +mv->dst_x = dst_x; > +mv