[Libav-user] Trouble Decoding with h264_qsv

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Trouble Decoding with h264_qsv

Philippe Noël
Hello,

I am trying to decode H264 video packets into AVFrames using Intel QSV. I am following these examples (1) (2), but the avcodec_decode_video2() function always outputs a value of 0 (unsuccessful decode). Below is my decode function:

-----------------------------------------------------------

avcodec_register_all();
AVCodec *codec;
AVCodecContext *context;

// INITIALIZE CODEC AND CONTEXT

codec = avcodec_find_decoder_by_name("h264_qsv");
context = avcodec_alloc_context3(codec);

// FUNCTION GET_FORMAT RETURNS AV_PIX_FMT_QSV
context->get_format  = get_format;

// CREATE QSV DEVICE, ATTACH TO CONTEXT

av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV, "auto", NULL, 0);
context->hw_device_ctx = av_buffer_ref(hw_device_ctx);

// CREATE HW FRAMES CONTEXT, ATTACH TO CONTEXT

av_buffer_unref(&context->hw_frames_ctx);
context->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx);

AVHWFramesContext *frames_ctx;

frames_ctx = (AVHWFramesContext*)context->hw_frames_ctx->data;
frames_ctx->format = AV_PIX_FMT_QSV;
frames_ctx->sw_format = AV_PIX_FMT_NV12;
frames_ctx->width = in_width;
frames_ctx->height = in_height;
frames_ctx->initial_pool_size = 32;

av_hwframe_ctx_init(context->hw_frames_ctx);

// OPEN THE CONTEXT, CREATE FRAMES

avcodec_open2(context, NULL, NULL);

AVFrame * sw_frame = av_frame_alloc();
AVFrame * hw_frame = av_frame_alloc();

// DECODE THE PACKET (Packet is initialized and filled elsewhere)

int success;
avcodec_decode_video2(context, hw_frame, &success, &packet);

-----------------------------------------------------------

I know that my packets are encoded correctly, because the decoding works well when I just use AV_CODEC_ID_H264. I've also tried the new decode functions (avcodec_send_packet and avcodec_receive_frame), but avcodec_send_packet() returns -11.

Does anyone have any ideas as to what I could be missing?

Thank you!

Philippe

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Decoding with h264_qsv

Carl Eugen Hoyos-2
Am Mi., 22. Jan. 2020 um 18:16 Uhr schrieb Philippe Noël
<[hidden email]>:

> I know that my packets are encoded correctly, because the decoding works
> well when I just use AV_CODEC_ID_H264.

I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Decoding with h264_qsv

Philippe Noël
I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Yes sorry, I have tested with ffmpeg cmd line and it works fine, so I'm fairly sure there's something I'm missing in the C code using libav. Not sure if that changes anything, but I am encoding with Nvenc and trying to decode with QSV.

Any ideas what I could be missing in the code above?

Philippe

On Wed, Jan 22, 2020 at 1:23 PM Carl Eugen Hoyos <[hidden email]> wrote:
Am Mi., 22. Jan. 2020 um 18:16 Uhr schrieb Philippe Noël
<[hidden email]>:

> I know that my packets are encoded correctly, because the decoding works
> well when I just use AV_CODEC_ID_H264.

I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Decoding with h264_qsv

Attila Krüpl
avcodec_decode_video2 is a deprecated function, so the success of usage depends on what version of LibAV you are using.
If decoding is not working for you it might be worth to turn on logging with av_log_set_level(AV_LOG_TRACE) and add an own logger callback so you can define the output with av_log_set_callback(). Once you receive error codes it's much simpler to configure the codec, because you can see what the mistake is.

Best Regards,

Attila


On Wed, 22 Jan 2020 at 19:56, Philippe Noël <[hidden email]> wrote:
I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Yes sorry, I have tested with ffmpeg cmd line and it works fine, so I'm fairly sure there's something I'm missing in the C code using libav. Not sure if that changes anything, but I am encoding with Nvenc and trying to decode with QSV.

Any ideas what I could be missing in the code above?

Philippe

On Wed, Jan 22, 2020 at 1:23 PM Carl Eugen Hoyos <[hidden email]> wrote:
Am Mi., 22. Jan. 2020 um 18:16 Uhr schrieb Philippe Noël
<[hidden email]>:

> I know that my packets are encoded correctly, because the decoding works
> well when I just use AV_CODEC_ID_H264.

I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Trouble Decoding with h264_qsv

Philippe Noël
avcodec_decode_video2 is a deprecated function, so the success of usage depends on what version of LibAV you are using.
If decoding is not working for you it might be worth to turn on logging with av_log_set_level(AV_LOG_TRACE) and add an own logger callback so you can define the output with av_log_set_callback(). Once you receive error codes it's much simpler to configure the codec, because you can see what the mistake is.

Thanks for the tip, I logged the error. The error I get is "Decoder: output is system memory surface" and I can't seem to find anything regarding this online. I verified and my CPU is supported (it is an i5-7200U). Any idea what the problem is, or where I could find more information on this specific error?

Cheers,

Philippe


On Wed, Jan 22, 2020 at 2:18 PM Attila Krüpl <[hidden email]> wrote:
avcodec_decode_video2 is a deprecated function, so the success of usage depends on what version of LibAV you are using.
If decoding is not working for you it might be worth to turn on logging with av_log_set_level(AV_LOG_TRACE) and add an own logger callback so you can define the output with av_log_set_callback(). Once you receive error codes it's much simpler to configure the codec, because you can see what the mistake is.

Best Regards,

Attila


On Wed, 22 Jan 2020 at 19:56, Philippe Noël <[hidden email]> wrote:
I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Yes sorry, I have tested with ffmpeg cmd line and it works fine, so I'm fairly sure there's something I'm missing in the C code using libav. Not sure if that changes anything, but I am encoding with Nvenc and trying to decode with QSV.

Any ideas what I could be missing in the code above?

Philippe

On Wed, Jan 22, 2020 at 1:23 PM Carl Eugen Hoyos <[hidden email]> wrote:
Am Mi., 22. Jan. 2020 um 18:16 Uhr schrieb Philippe Noël
<[hidden email]>:

> I know that my packets are encoded correctly, because the decoding works
> well when I just use AV_CODEC_ID_H264.

I don't think this is a sufficient test as no hardware decoder has as
many features
as the libavcodec h264 decoder. Did you test with ffmpeg (the command line
interface)?

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".