gpt4 book ai didi

ffmpeg - 为什么在我曾经将一帧设置为 ffmpeg 的英特尔 qsv 的关键之后,每个编码帧的大小都会增加

转载 作者:行者123 更新时间:2023-12-04 23:11:22 25 4
gpt4 key购买 nike

我使用英特尔的 qsv 在 ffmpeg 中编码 h264 视频。我的 av 编解码器上下文设置如下:

 m_ctx->width = m_width;
m_ctx->height = m_height;
m_ctx->time_base = { 1, (int)fps };
m_ctx->qmin = 10;
m_ctx->qmax = 35;
m_ctx->gop_size = 3000;
m_ctx->max_b_frames = 0;
m_ctx->has_b_frames = false;
m_ctx->refs = 2;
m_ctx->slices = 0;
m_ctx->codec_id = m_encoder->id;
m_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
m_ctx->pix_fmt = m_h264InputFormat;
m_ctx->compression_level = 4;
m_ctx->flags &= ~AV_CODEC_FLAG_CLOSED_GOP;
AVDictionary *param = nullptr;
av_dict_set(&param, "idr_interval", "0", 0);
av_dict_set(&param, "async_depth", "1", 0);
av_dict_set(&param, "forced_idr", "1", 0);
在编码中,当需要关键帧时,我将 AVFrame 设置为 AV_PICTURE_TYPE_I:
  if(key_frame){
encodeFrame->pict_type = AV_PICTURE_TYPE_I;
}else{
encodeFrame->pict_type = AV_PICTURE_TYPE_NONE;
}
avcodec_send_frame(m_ctx, encodeFrame);
avcodec_receive_packet(m_ctx, m_packet);
std::cerr<<"packet size is "<<m_packet->size<<",is key frame "<<key_frame<<std::endl;
奇怪的现象是,如果我将一帧设置为 AV_PICTURE_TYPE_I,那么关键帧之后每个编码帧的大小都会增加。如果我把h264编码器改成x264,那就没问题了。
在我调用“encodeFrame->pict_type = AV_PICTURE_TYPE_I”之前,数据包大小如下:
packet size is 26839
packet size is 2766
packet size is 2794
packet size is 2193
packet size is 1820
packet size is 2542
packet size is 2024
packet size is 1692
packet size is 2095
packet size is 2550
packet size is 1685
packet size is 1800
packet size is 2276
packet size is 1813
packet size is 2206
packet size is 2745
packet size is 2334
packet size is 2623
packet size is 2055
如果我调用“encodeFrame->pict_type = AV_PICTURE_TYPE_I”,那么数据包大小如下:
packet size is 23720,is key frame 1
packet size is 23771,is key frame 0
packet size is 23738,is key frame 0
packet size is 23752,is key frame 0
packet size is 23771,is key frame 0
packet size is 23763,is key frame 0
packet size is 23715,is key frame 0
packet size is 23686,is key frame 0
packet size is 23829,is key frame 0
packet size is 23774,is key frame 0
packet size is 23850,is key frame 0

最佳答案

FFMPEG 在编码下一帧时不会重置 mfxEncodeCtrl 的 FrameType,它会导致关键帧之后的每一帧都是 IDR 帧

关于ffmpeg - 为什么在我曾经将一帧设置为 ffmpeg 的英特尔 qsv 的关键之后,每个编码帧的大小都会增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67192978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com