[Libav-user] Trouble Decoding with h264_qsv

Philippe Noël philippe_noel at college.harvard.edu
Wed Jan 22 19:08:57 EET 2020


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20200122/e61d09f9/attachment.html>


More information about the Libav-user mailing list