MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / encode_frame

Function encode_frame

libavcodec/qsvenc.c:2458–2576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2456}
2457
2458static int encode_frame(AVCodecContext *avctx, QSVEncContext *q,
2459 const AVFrame *frame)
2460{
2461 QSVPacket pkt = { { 0 } };
2462 mfxExtAVCEncodedFrameInfo *enc_info = NULL;
2463 mfxExtBuffer **enc_buf = NULL;
2464
2465 mfxFrameSurface1 *surf = NULL;
2466 QSVFrame *qsv_frame = NULL;
2467 mfxEncodeCtrl* enc_ctrl = NULL;
2468 int ret;
2469
2470 if (frame) {
2471 ret = submit_frame(q, frame, &qsv_frame);
2472 if (ret < 0) {
2473 av_log(avctx, AV_LOG_ERROR, "Error submitting the frame for encoding.\n");
2474 return ret;
2475 }
2476 }
2477 if (qsv_frame) {
2478 surf = &qsv_frame->surface;
2479 enc_ctrl = &qsv_frame->enc_ctrl;
2480
2481 if (frame->pict_type == AV_PICTURE_TYPE_I) {
2482 enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
2483 if ((frame->flags & AV_FRAME_FLAG_KEY) || q->forced_idr)
2484 enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
2485 }
2486 }
2487
2488 ret = av_new_packet(&pkt.pkt, q->packet_size);
2489 if (ret < 0) {
2490 av_log(avctx, AV_LOG_ERROR, "Error allocating the output packet\n");
2491 return ret;
2492 }
2493
2494 pkt.bs = av_mallocz(sizeof(*pkt.bs));
2495 if (!pkt.bs)
2496 goto nomem;
2497 pkt.bs->Data = pkt.pkt.data;
2498 pkt.bs->MaxLength = pkt.pkt.size;
2499
2500 if (avctx->codec_id == AV_CODEC_ID_H264) {
2501 enc_info = av_mallocz(sizeof(*enc_info));
2502 if (!enc_info)
2503 goto nomem;
2504
2505 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
2506 enc_info->Header.BufferSz = sizeof (*enc_info);
2507 pkt.bs->NumExtParam = 1;
2508 enc_buf = av_mallocz(sizeof(mfxExtBuffer *));
2509 if (!enc_buf)
2510 goto nomem;
2511 enc_buf[0] = (mfxExtBuffer *)enc_info;
2512
2513 pkt.bs->ExtParam = enc_buf;
2514 }
2515

Callers 2

update_parametersFunction · 0.70
ff_qsv_encodeFunction · 0.70

Calls 13

av_logFunction · 0.85
av_new_packetFunction · 0.85
set_roi_encode_ctrlFunction · 0.85
av_usleepFunction · 0.85
ff_qsv_print_warningFunction · 0.85
ff_qsv_print_errorFunction · 0.85
print_interlace_msgFunction · 0.85
av_fifo_writeFunction · 0.85
av_freepFunction · 0.85
av_packet_unrefFunction · 0.85
submit_frameFunction · 0.70

Tested by

no test coverage detected