I try to encode raw image data to x264 with libav:
AVPacket vpkt = { 0 };
av_init_packet(&vpkt);
int got;
int ret = avcodec_encode_video2(vcodec, &vpkt, frameyuv.get(), &got);
if (!ret && got && vpkt.size) {
if (vpkt.pts != AV_NOPTS_VALUE) {
vpkt.pts = av_rescale_q(vpkt.pts, vcodec->time_base, videost->time_base);
}
if (vpkt.dts != AV_NOPTS_VALUE) {
vpkt.dts = av_rescale_q(vpkt.dts, vcodec->time_base, videost->time_base);
}
vpkt.stream_index = videost->index;
if(vcodec->coded_frame->key_frame) {
vpkt.flags |= AV_PKT_FLAG_KEY;
}
/* -> will return -22 if max_b_frames > 0 */
ret = av_interleaved_write_frame(oc, &vpkt);
}
Runs fine when vcodec->max_b_frames is set to 0, but on any other value av_interleaved_write_frame returns -22 (invalid argument).
/* will fail */
c->max_b_frames = 3;
/* -> ok*/
c->max_b_frames = 0;
Why? Am i missing something?
Codec options are
AVDictionary *opts = NULL;
av_dict_set(&opts, "vprofile", "baseline", 0);
/* ... */
c->codec_type = AVMEDIA_TYPE_VIDEO;
c->bit_rate = 500 * 1000;
c->width = VideoWidth;
c->height = VideoHeight;
c->time_base.den = fps;
c->time_base.num = 1;
c->pix_fmt = AV_PIX_FMT_YUV420P;
Container format is mp4.