ffmpeg H264编码前面有文章介绍下,本文主要介绍一些参数配置。
int InitEncoderCodec( int iWidth, int iHeight) { AVCodec * pH264Codec = avcodec_find_encoder(AV_CODEC_ID_H264); if(NULL == pH264Codec) { printf("%s", "avcodec_find_encoder failed"); return -1; } outPutEncContext = avcodec_alloc_context3(pH264Codec); outPutEncContext->gop_size = 30; outPutEncContext->has_b_frames = 0; outPutEncContext->max_b_frames = 0; outPutEncContext->codec_id = pH264Codec->id; outPutEncContext->time_base.num = 2; outPutEncContext->time_base.den = 15; outPutEncContext->pix_fmt = *pH264Codec->pix_fmts; outPutEncContext->width = iWidth; outPutEncContext->height = iHeight; outPutEncContext->qmin = 34; outPutEncContext->qmax = 50; AVDictionary *options = nullptr; outPutEncContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; av_opt_set(outPutEncContext->priv_data,"tune","zerolatency",0); int ret = avcodec_open2(outPutEncContext, pH264Codec, &options); if (ret < 0) { printf("%s", "open codec failed"); return ret; } return 1; }
codec 的time_base实际上表示视频的帧率,qmin,qmax决定了编码的质量,qmin,qmax越大编码的质量越差。zerolatency参数的作用是提搞编码的实时性。
如需交流请加qq群流媒体/Ffmpeg/音视频 127903734 ,或加QQ350197870。
时间: 2024-10-12 09:07:00