zoukankan      html  css  js  c++  java
  • FFMPEG H264/H265 编码延迟问题

    最新使用 FFmpeg 进行 H264 的编码时,发现视频编码有延迟,不是实时编码,进过一番研究发现,只要在调用 avcodec_open2 函数

    打开编码器时,设置 AVDictionary 参数即可,关键代码如下:

    avcodec_open2函数:

    int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);

    解决方案:

    AVDictionary *param = NULL;    
    //H264, 设置为编码延迟为立即编码
    if(c->codec_id == AV_CODEC_ID_H264)
    {  
        av_dict_set(¶m, "preset", "superfast",   0);
        av_dict_set(¶m, "tune",   "zerolatency", 0);
    }  
    //H.265  
    if(c->codec_id == AV_CODEC_ID_H265)
    {  
        av_dict_set(¶m, "x265-params", "qp=20", 0); 
        av_dict_set(¶m, "preset", "ultrafast", 0);  
        av_dict_set(¶m, "tune", "zero-latency", 0); 
    }  
     
    //使用给定的AVCodec初始化AVCodecContext

    还有这种方式:
    // Set Option  
        AVDictionary *param = 0;  
        //H.264  
        if(pCodecCtx->codec_id == AV_CODEC_ID_H264) {  
            av_dict_set(?m, "preset", "slow", 0);  
            av_dict_set(?m, "tune", "zerolatency", 0);  
        }  
        //H.265  
        if(pCodecCtx->codec_id == AV_CODEC_ID_H265){  
            av_dict_set(&param, "x265-params", "qp=20", 0);  
            av_dict_set(&param, "preset", "ultrafast", 0);  
            av_dict_set(&param, "tune", "zero-latency", 0);  
        }  
      
        //Dump Information 输出格式信息  
        av_dump_format(pFormatCtx, 0, out_file, 1);  
      
        pCodec = avcodec_find_encoder(pCodecCtx->codec_id);  
        if (!pCodec){  
            printf("Can not find encoder! 没有找到合适的编码器! ");  
            return -1;  
        }  
        if (avcodec_open2(pCodecCtx, pCodec,&param) < 0){  
            printf("Failed to open encoder! 编码器打开失败! ");  
            return -1;  
        } 

  • 相关阅读:
    给 admin 新建的 hdfs 文件的权限
    linux 常用命令
    如何快速把hdfs数据动态导入到hive表
    Kylin查询性能低下原因分析
    hadoop+hive使用中遇到的问题汇总
    hadoop 突然断电数据丢失问题
    用puthivestreaming把hdfs里的数据流到hive表
    创建 kylin Module/Cube
    【MySQL】MySQL的索引
    【MySQL】MySQL的约束
  • 原文地址:https://www.cnblogs.com/lidabo/p/15071183.html
Copyright © 2011-2022 走看看