ffmpeg+x264编码,AVCodecContext的gop_size与max_b_frames设置无效,求解决方案

mstlq 2011-10-08 04:33:17
如题。

小弟分别试过自行编译ffmpeg0.8.1+x264(116版本)和直接使用从http://ffmpeg.zeranoe.com/builds/win32/shared/上下载的ffmpeg-0.8-win32-shared.7z(x264为115版)

修改muxing-example.c,使其输出h264编码的flv文件,
add_video_stream函数中写入

static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id)
{
AVCodecContext *c;
AVStream *st;
int br = 100000;
st = av_new_stream(oc, 0);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}

c = st->codec;
c->codec_id = codec_id;
c->codec_type = AVMEDIA_TYPE_VIDEO;
/* put sample parameters */
c->flags &= ~CODEC_FLAG_QSCALE;
c->rc_max_rate=br;
c->rc_min_rate=br;
c->bit_rate = br;
c->rc_buffer_size=br;
c->rc_initial_buffer_occupancy = c->rc_buffer_size*3/4;
c->rc_buffer_aggressivity= (float)1.0;
c->rc_initial_cplx= 0.5;

c->thread_count = 1;

/* resolution must be a multiple of two */
c->width = 352;
c->height = 288;
c->time_base.den = STREAM_FRAME_RATE;
c->time_base.num = 1;
c->gop_size = 500;
c->pix_fmt = STREAM_PIX_FMT;
c->max_b_frames = 0;
// some formats want stream headers to be separate
if(oc->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
return st;
}


在上面我把gop_size与max_b_frames分别设置成了500与0

可是av_dump_format函数却报告下列信息
[libx264 @ 003D6700] Default settings detected, using medium profile
[libx264 @ 003D6700] using cpu capabilities: MMX2 SSE2Fast FastShuffle SSEMisali
gn LZCNT
[libx264 @ 003D6700] profile High, level 1.3
[libx264 @ 003D6700] 264 - core 115 r2008 4c552d8 - H.264/MPEG-4 AVC codec - Cop
yleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
ma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_c
ompat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 we
ightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=
0 rc_lookahead=40 rc=cbr mbtree=1 bitrate=100 ratetol=1.0 qcomp=0.60 qpmin=0 qpm
ax=69 qpstep=4 vbv_maxrate=100 vbv_bufsize=100 nal_hrd=none ip_ratio=1.40 aq=1:1
.00

keyint与bframes参数并没有随我的设定而更改。
请问造成上述问题的原因是什么,我可以怎么解决呢?

ps:我使用ffmpeg FULL SDK V3.2时并未出现上面的问题,不过由于其对码率控制不好,我决定换个更新的版本。
...全文
4549 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
openlqh1990 2013-12-17
  • 打赏
  • 举报
回复
楼主请教一个问题,为什么FFMPEG 视频转为FLV的时候,时间不对,帧数改不了。
神-气 2012-10-15
  • 打赏
  • 举报
回复
额,好像br的单位是 bit/s ,不是kbps ,设置10000的时候简直不能看。。
神-气 2012-10-15
  • 打赏
  • 举报
回复
设置了这个参数标志:CODEC_FLAG_QSCALE ,bit rate高点低点都没影响。。。
CyberLogix 2011-11-29
  • 打赏
  • 举报
回复
参数应该改为合理的,有的参数之间有显示
redan01 2011-11-29
  • 打赏
  • 举报
回复
楼主你好, 你使用的x264的116版应该和我使用的119版差不多。 你的116版是不是使用mingw翻译生成的?

如果是的话能不能请教 一下源码库中的四个全局变量你是怎么导出的?如下的四个全局变量:

extern const cli_output_t raw_output;
extern const cli_output_t mkv_output;
extern const cli_output_t mp4_output;
extern const cli_output_t flv_output;
wenzheng101 2011-11-29
  • 打赏
  • 举报
回复
楼主你好,我将编码好的h264用ffmpeg转码成avi文件(不用ffmpeg编码),然后得出的avi文件每次用vlc播放的时候,大约每隔11秒左右就会在运动物体处出现马赛克,请问这是什么原因造成的?
美丽海洋 2011-10-11
  • 打赏
  • 举报
回复
对这些参数头疼,要是运动是有马赛克不知道怎么设置参数才能把马赛克去掉,应该是那个参数?
mstlq 2011-10-11
  • 打赏
  • 举报
回复
跟踪ffmpeg中的libx264.c,总算发现是下面几行代码导致……
    if (!x4->preset)
check_default_settings(avctx);

if (x4->preset || x4->tune) {
if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0)
return -1;
}

针对其做修改后,运行达到我预定目标了
希望有高人能帮忙分析一下此处代码的意义,当初开发人员这么写是基于什么考虑呢?
mstlq 2011-10-08
  • 打赏
  • 举报
回复
请大家留意一下第一段中的
……
c->gop_size = 500;
c->pix_fmt = STREAM_PIX_FMT;
c->max_b_frames = 0;
……

与第二段中的
…… bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 we
ightb=1 open_gop=0 weightp=2 keyint=250 ……
mstlq 2011-10-08
  • 打赏
  • 举报
回复
加颜色失败了,请大家留意第一段代码中的
c->gop_size = 500;
c->pix_fmt = STREAM_PIX_FMT;
c->max_b_frames = 0;

与第二段输出当中的
……bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 we
ightb=1 open_gop=0 weightp=2 keyint=250 ……

2,553

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧