我使用 libx264 通过 RTP 流式传输视频捕获。现在,我只是流式传输到本地主机。为了观看流,我使用了 ffmpeg 库。当我将 GOP 大小设置为大于 1(仅 I 帧)时,我会在接收器端出现伪影
. 奇怪的是,当我使用ffplay时,图像是完美的
. 我究竟做错了什么?
编码设置
output_codec_ctx->bit_rate = 5000000;
output_codec_ctx->width = 1920;
output_codec_ctx->height = 1080;
output_codec_ctx->time_base.den = 30; // frames per second
output_codec_ctx->time_base.num = 1;
output_codec_ctx->gop_size = 10; // gop size
output_codec_ctx->max_b_frames = 0; // B frames
output_codec_ctx->pix_fmt = AV_PIX_FMT_YUV420P; // output pixel format
output_codec_ctx->codec_type = AVMEDIA_TYPE_VIDEO;
av_opt_set(output_codec_ctx->priv_data, "preset", "ultrafast", 0);
av_opt_set(output_codec_ctx->priv_data, "tune", "zerolatency", 0);
Run Code Online (Sandbox Code Playgroud)
解码代码
AVFormatContext *pFormatCtx;
AVCodecContext *input_codec_ctx;
AVCode *pCodec;
avdevice_register_all(); // for device
avformat_network_init();
pFormatCtx = …Run Code Online (Sandbox Code Playgroud)