如何减少FFmpeg h264_qsv编码器的延迟?

时间:2017-11-03 12:58:09

标签: ffmpeg h.264

我在我的相机实时软件中使用FFmpeg(3.4)h264_qsv编码器,我发现在发送40帧后收到的编码数据!有大约1.5秒的延迟,它不适合实时情况。如何配置编码器?非常感谢。

我的代码:

$emailid = $_POST['email'];
    $phoneno = $_POST['phoneno'];
     $to = "demoemail@gmail.com"; // this is your Email address
    $from = $emailid;  // this is the sender's Email address
    $subject = "Intrested in scheduling appointment.";
     $message = "<a href='http://www.google.com'>Click Here</a>";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  $headers = "From:" . $from;

  $retval = mail($to,$subject,$message,$headers);

1 个答案:

答案 0 :(得分:0)

感谢Mulvya的小费。现在只有5帧延迟。

AVCodecContext* OpenH264Codec(int width, int height, int bitrate, int framerate)
{
    AVCodecContext* ctx = 0;
    AVCodec* c = 0;
    c = avcodec_find_encoder_by_name("h264_qsv");
    if (c == NULL) return NULL;
    ctx = avcodec_alloc_context3(c);
    if (ctx == NULL) return NULL;
    ctx->width = width;
    ctx->height = height;
    ctx->pix_fmt = c->pix_fmts[0];
    ctx->bit_rate = bitrate;
    ctx->bit_rate_tolerance = ctx->bit_rate / 2;
    ctx->time_base.den = framerate;
    ctx->time_base.num = 1;
    ctx->framerate.den = 1;
    ctx->framerate.num = framerate;
    ctx->gop_size = framerate*5;
    ctx->max_b_frames = 0;
    av_opt_set(ctx->priv_data, "preset", "medium", 0);
    av_opt_set(ctx->priv_data, "look_ahead", "0", 0);
    //av_opt_set(ctx->priv_data, "look_ahead_depth", "8", 0);
    if (avcodec_open2(ctx, c, 0) < 0)
    {
        avcodec_free_context(&ctx);
        return NULL;
    }
    return ctx;
}