我使用以下代码对传入的h264流进行编码:
int ret;
ffmpeg::AVDictionary *opts2 = NULL;
av_dict_set(&opts2, "preset", "medium", 0);
av_dict_set(&opts2, "crf", "29", 0);
av_dict_set(&opts2, "profile", "baseline", 0);
av_dict_set(&opts2, "level", "30", 0);
av_dict_set(&opts2, "maxrate", "200000", 0);
av_dict_set(&opts2, "minrate", "0", 0);
av_dict_set(&opts2, "bufsize", "2000000", 0);
ffmpeg::AVOutputFormat* fmt = ffmpeg::av_guess_format("mpeg", NULL, NULL);
// Open the context
//---------------------------------------------------------------------
outFormatCtx = ffmpeg::avformat_alloc_context();
if (!outFormatCtx)
{
return false;
}
//Set the output format
//----------------------------------------------------------------------
outFormatCtx->oformat = fmt;
// Open the output file
//-------------------------------------
if (!(outFormatCtx->flags & AVFMT_NOFILE))
{
ret = ffmpeg::avio_open2(&outFormatCtx->pb, "Record.avi", AVIO_FLAG_WRITE, NULL, NULL);
if (ret < 0)
{
return false;
}
}
// Create the output stream
// -------------------------------------
ffmpeg::AVStream* out_stream = ffmpeg::avformat_new_stream(outFormatCtx, inputStream->codec->codec);
if (!out_stream)
{
return false;
}
//Set the stream parameters
//-------------------------------------
ret = ffmpeg::avcodec_copy_context(out_stream->codec, inputStream->codec);
if (ret < 0)
{
return false;
}
// Check then setup for global headers
//-------------------------------------
if (outFormatCtx->oformat->flags & AVFMT_GLOBALHEADER)
out_stream->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
av_dump_format(outFormatCtx, 0, "Record.avi", 1);
//Write the header
//--------------------------------------
ret = ffmpeg::avformat_write_header(outFormatCtx, &opts2);
if (ret < 0)
{
return false;
}
但是我总是收到警告:
"VBV buffer size not set, using default size of 130KB\n"
"If you want the mpeg file to be compliant to some specification\n"
"Like DVD, VCD or others, make sure you set the correct buffer size\n"
我已经非常努力了,但我怎么能设置这个VBV缓冲区大小?