如何连接code H.264与libav codeC / X264? [英] How to encode h.264 with libavcodec/x264?

查看:168
本文介绍了如何连接code H.264与libav codeC / X264?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用libav codeC / libavformat依次尝试连接code视频。音频的伟大工程,但是当我尝试连接code视频我收到以下错误:

I am attempting to encode video using libavcodec/libavformat. Audio works great, but when I try to encode video I get the following errors:

[libx264 @ 0x10182a000]broken ffmpeg default settings detected  
[libx264 @ 0x10182a000]use an encoding preset (vpre)  

容易解决使用命令行的ffmpeg,但我想这样做是C.
我的选择是

easy to fix using the command line ffmpeg, but I am trying to do this in C. my options are

AVStream *pVideoOutStream = av_new_stream(pOutFormatCtx, 0);  
AVCodecContext *pVideoOutCodecCtx  = pVideoOutStream->codec;  

pVideoOutCodecCtx->codec_id        = CODEC_ID_H264;    
pVideoOutCodecCtx->codec_type      = CODEC_TYPE_VIDEO;  
pVideoOutCodecCtx->bit_rate        = pVideoInCodecCtx->bit_rate;  
pVideoOutCodecCtx->width           = pVideoInCodecCtx->width;    
pVideoOutCodecCtx->height          = pVideoInCodecCtx->height;  
pVideoOutCodecCtx->pix_fmt         = pVideoInCodecCtx->pix_fmt;    
pVideoOutCodecCtx->sample_rate     = pVideoInCodecCtx->sample_rate;    
pVideoOutCodecCtx->gop_size        = 30;  

但AV codec_open()失败。

but avcodec_open() fails.

还有什么其他价值,我需要设置为使X264的幸福吗?

What other values do I need to set to make x264 happy?

推荐答案

不知道你是否懂了工作,但下面的参数为我工作。

Not sure whether you got it working, but the following parameters work for me.

ctx->bit_rate = 500*1000;
ctx->bit_rate_tolerance = 0;
ctx->rc_max_rate = 0;
ctx->rc_buffer_size = 0;
ctx->gop_size = 40;
ctx->max_b_frames = 3;
ctx->b_frame_strategy = 1;
ctx->coder_type = 1;
ctx->me_cmp = 1;
ctx->me_range = 16;
ctx->qmin = 10;
ctx->qmax = 51;
ctx->scenechange_threshold = 40;
ctx->flags |= CODEC_FLAG_LOOP_FILTER;
ctx->me_method = ME_HEX;
ctx->me_subpel_quality = 5;
ctx->i_quant_factor = 0.71;
ctx->qcompress = 0.6;
ctx->max_qdiff = 4;
ctx->directpred = 1;
ctx->flags2 |= CODEC_FLAG2_FASTPSKIP;


有可能通过FFmpeg的源$ C ​​$ C寻找并确定preSET文件是如何映射到AV codecContext参数,但我忘了究竟在何处的奇迹发生。


It is possible to look through the FFmpeg source code and determine how the preset files map to AVCodecContext parameters, but I forget exactly where the magic happens.

这篇关于如何连接code H.264与libav codeC / X264?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆