Discussion:
[PATCH 1/2] lavc/qsvdec: set complete_frame flags for non-interlaced frames.
(too old to reply)
Zhong Li
2018-03-19 09:33:35 UTC
Permalink
Set the flag MFX_BITSTREAM_COMPLETE_FRAME when it is a completed frame.
This can fix vc1 decoding segment fault issues because can't set the start
code correctly.
See: ./avconv -hwaccel qsv -c:v vc1_qsv -i /fate-suite/vc1/SA00040.vc1
-vf "hwdownload, format=nv12" -f rawvideo /dev/null

Signed-off-by: Zhong Li <***@intel.com>
---
libavcodec/qsvdec.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c74ec68..dc44865 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -321,6 +321,9 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
bs.DataLength = avpkt->size;
bs.MaxLength = bs.DataLength;
bs.TimeStamp = avpkt->pts;
+ if (avctx->field_order == AV_FIELD_UNKNOWN ||
+ avctx->field_order == AV_FIELD_PROGRESSIVE)
+ bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
}

sync = av_mallocz(sizeof(*sync));
--
1.8.3.1
Zhong Li
2018-03-19 09:33:36 UTC
Permalink
And support nv12/yuyv422/rgb32 formats for qsv_transfer_data

Signed-off-by: ChaoX A Liu <***@intel.com>
Signed-off-by: Zhong Li <***@intel.com>
---
libavutil/hwcontext_qsv.c | 49 +++++++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 5018a05..47afa48 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -90,6 +90,7 @@ static const struct {
uint32_t fourcc;
} supported_pixel_formats[] = {
{ AV_PIX_FMT_NV12, MFX_FOURCC_NV12 },
+ { AV_PIX_FMT_RGB32,MFX_FOURCC_RGB4 },
{ AV_PIX_FMT_P010, MFX_FOURCC_P010 },
{ AV_PIX_FMT_PAL8, MFX_FOURCC_P8 },
};
@@ -730,6 +731,42 @@ static int qsv_transfer_data_child(AVHWFramesContext *ctx, AVFrame *dst,
return ret;
}

+static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
+{
+ switch (frame->format) {
+ case AV_PIX_FMT_NV12:
+ surface->Data.Y = frame->data[0];
+ surface->Data.UV = frame->data[1];
+ break;
+
+ case AV_PIX_FMT_YUV420P:
+ surface->Data.Y = frame->data[0];
+ surface->Data.U = frame->data[1];
+ surface->Data.V = frame->data[2];
+ break;
+
+ case AV_PIX_FMT_YUYV422:
+ surface->Data.Y = frame->data[0];
+ surface->Data.U = frame->data[0] + 1;
+ surface->Data.V = frame->data[0] + 3;
+ break;
+
+ case AV_PIX_FMT_RGB32:
+ surface->Data.B = frame->data[0];
+ surface->Data.G = frame->data[0] + 1;
+ surface->Data.R = frame->data[0] + 2;
+ surface->Data.A = frame->data[0] + 3;
+ break;
+
+ default:
+ return MFX_ERR_UNSUPPORTED;
+ }
+ surface->Data.Pitch = frame->linesize[0];
+ surface->Data.TimeStamp = frame->pts;
+
+ return 0;
+}
+
static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
@@ -749,11 +786,7 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
}

out.Info = in->Info;
- out.Data.PitchLow = dst->linesize[0];
- out.Data.Y = dst->data[0];
- out.Data.U = dst->data[1];
- out.Data.V = dst->data[2];
- out.Data.A = dst->data[3];
+ map_frame_to_surface(dst, &out);

do {
err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in, &out, NULL, &sync);
@@ -796,11 +829,7 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
}

in.Info = out->Info;
- in.Data.PitchLow = src->linesize[0];
- in.Data.Y = src->data[0];
- in.Data.U = src->data[1];
- in.Data.V = src->data[2];
- in.Data.A = src->data[3];
+ map_frame_to_surface(src, &in);

do {
err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, &in, out, NULL, &sync);
--
1.8.3.1
Maxym Dmytrychenko
2018-03-19 09:56:29 UTC
Permalink
indentation can be adjusted ,
AV_PIX_FMT_YUYV422 - we add it but dont use?
Post by Zhong Li
And support nv12/yuyv422/rgb32 formats for qsv_transfer_data
---
libavutil/hwcontext_qsv.c | 49 ++++++++++++++++++++++++++++++
+++++++----------
1 file changed, 39 insertions(+), 10 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 5018a05..47afa48 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -90,6 +90,7 @@ static const struct {
uint32_t fourcc;
} supported_pixel_formats[] = {
{ AV_PIX_FMT_NV12, MFX_FOURCC_NV12 },
+ { AV_PIX_FMT_RGB32,MFX_FOURCC_RGB4 },
{ AV_PIX_FMT_P010, MFX_FOURCC_P010 },
{ AV_PIX_FMT_PAL8, MFX_FOURCC_P8 },
};
@@ -730,6 +731,42 @@ static int qsv_transfer_data_child(AVHWFramesContext
*ctx, AVFrame *dst,
return ret;
}
+static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
+{
+ switch (frame->format) {
+ surface->Data.Y = frame->data[0];
+ surface->Data.UV = frame->data[1];
+ break;
+
+ surface->Data.Y = frame->data[0];
+ surface->Data.U = frame->data[1];
+ surface->Data.V = frame->data[2];
+ break;
+
+ surface->Data.Y = frame->data[0];
+ surface->Data.U = frame->data[0] + 1;
+ surface->Data.V = frame->data[0] + 3;
+ break;
+
+ surface->Data.B = frame->data[0];
+ surface->Data.G = frame->data[0] + 1;
+ surface->Data.R = frame->data[0] + 2;
+ surface->Data.A = frame->data[0] + 3;
+ break;
+
+ return MFX_ERR_UNSUPPORTED;
+ }
+ surface->Data.Pitch = frame->linesize[0];
+ surface->Data.TimeStamp = frame->pts;
+
+ return 0;
+}
+
static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
@@ -749,11 +786,7 @@ static int qsv_transfer_data_from(AVHWFramesContext
*ctx, AVFrame *dst,
}
out.Info = in->Info;
- out.Data.PitchLow = dst->linesize[0];
- out.Data.Y = dst->data[0];
- out.Data.U = dst->data[1];
- out.Data.V = dst->data[2];
- out.Data.A = dst->data[3];
+ map_frame_to_surface(dst, &out);
do {
err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in, &out, NULL, &sync);
@@ -796,11 +829,7 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
}
in.Info = out->Info;
- in.Data.PitchLow = src->linesize[0];
- in.Data.Y = src->data[0];
- in.Data.U = src->data[1];
- in.Data.V = src->data[2];
- in.Data.A = src->data[3];
+ map_frame_to_surface(src, &in);
do {
err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, &in, out, NULL, &sync);
--
1.8.3.1
_______________________________________________
libav-devel mailing list
https://lists.libav.org/mailman/listinfo/libav-devel
Li, Zhong
2018-03-20 08:18:46 UTC
Permalink
Maxym Dmytrychenko
Sent: Monday, March 19, 2018 5:56 PM
Subject: Re: [libav-devel] [PATCH 2/2] lavu/hwcontext_qsv: Add support for
pix_fmt RGB32.
indentation can be adjusted ,
It is to support RGB format overlay (e.g. lena-rgba.png).
AV_PIX_FMT_YUYV422 - we add it but dont use?
If the overlay input movie format is 4:2:2, it will be used. But I prefer to remove it in this patch to make it clearer.
How do you think?
Maxym Dmytrychenko
2018-03-21 11:55:08 UTC
Permalink
Clean and specific patch is always good, agree with you on removal here.
Post by Li, Zhong
Maxym Dmytrychenko
Sent: Monday, March 19, 2018 5:56 PM
Subject: Re: [libav-devel] [PATCH 2/2] lavu/hwcontext_qsv: Add support
for
pix_fmt RGB32.
indentation can be adjusted ,
It is to support RGB format overlay (e.g. lena-rgba.png).
AV_PIX_FMT_YUYV422 - we add it but dont use?
If the overlay input movie format is 4:2:2, it will be used. But I prefer
to remove it in this patch to make it clearer.
How do you think?
_______________________________________________
libav-devel mailing list
https://lists.libav.org/mailman/listinfo/libav-devel
Maxym Dmytrychenko
2018-03-19 09:59:24 UTC
Permalink
MFX_BITSTREAM_COMPLETE_FRAME support can be added as a param
or can be only such if() conditions sufficient for all cases and streams ?
Post by Zhong Li
Set the flag MFX_BITSTREAM_COMPLETE_FRAME when it is a completed frame.
This can fix vc1 decoding segment fault issues because can't set the start
code correctly.
See: ./avconv -hwaccel qsv -c:v vc1_qsv -i /fate-suite/vc1/SA00040.vc1
-vf "hwdownload, format=nv12" -f rawvideo /dev/null
---
libavcodec/qsvdec.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c74ec68..dc44865 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -321,6 +321,9 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
bs.DataLength = avpkt->size;
bs.MaxLength = bs.DataLength;
bs.TimeStamp = avpkt->pts;
+ if (avctx->field_order == AV_FIELD_UNKNOWN ||
+ avctx->field_order == AV_FIELD_PROGRESSIVE)
+ bs.DataFlag |= MFX_BITSTREAM_COMPLETE_FRAME;
}
sync = av_mallocz(sizeof(*sync));
--
1.8.3.1
_______________________________________________
libav-devel mailing list
https://lists.libav.org/mailman/listinfo/libav-devel
Li, Zhong
2018-03-20 06:38:25 UTC
Permalink
Maxym Dmytrychenko
Sent: Monday, March 19, 2018 5:59 PM
Subject: Re: [libav-devel] [PATCH 1/2] lavc/qsvdec: set complete_frame flags
for non-interlaced frames.
MFX_BITSTREAM_COMPLETE_FRAME support can be added as a param
or can be only such if() conditions sufficient for all cases and streams ?
Yes, I think this flag is a common flag for all codecs (Not only for VC1.). According to the comments of MFX_BITSTREAM_COMPLETE_FRAME and grep it in MSDK sample_utils.cpp.
I have run the full decoding test internally for all codecs.
Everything is ok but expect h264. Some interlace videos is treated as AV_FIELD_UNKNOWN(see https://github.com/libav/libav/blob/master/libavcodec/h264_parser.c#L463 ) thus making some h264 clips decoding failed.
I will update this patch. Thanks for your review!
Continue reading on narkive:
Loading...