I figured out how to get - lets say default - values for x264 encoding which seems to work (encoding itself so far).
- Code: Select all
if(avcodec_get_context_defaults3 (c, codec) < 0)
{
std::cout << "Cannot get default codec context! \n" << std::endl;
std::cin.get();
exit(1);
}
c->bit_rate = BIT_RATE;
c->width = WIDTH;
c->height = HEIGHT;
c->time_base.den = FRAME_RATE;
c->time_base.num = 1;
c->gop_size = FRAME_RATE;
c->pix_fmt = PIX_FMT_YUV420P;
if(oc->oformat->flags & AVFMT_GLOBALHEADER)
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
Next step was to get rid of the "non-strictly-monotonic PTS"-Error. I figured out that i have to compute the right PTS for each AVFrame i want to encode. That way works for me so far:
- Code: Select all
picture->pts = (float) frame_count * (1000.0/(float)(FRAME_RATE)) * 90;
frame_count is the frame index (eg. 0, 1, 2, 3, ..)
Encoding works without any errors but the av_interleaved_write_frame function crashes on first call!
- Code: Select all
picture->pts = (float) frame_count * (1000.0/(float)(FRAME_RATE)) * 90;
int result, result2;
AVPacket pkt;
av_init_packet(&pkt);
pkt.dts = AV_NOPTS_VALUE;
pkt.stream_index = st->index;
pkt.data = video_outbuf;
pkt.size = video_outbuf_size;
result2 = avcodec_encode_video2(c, &pkt, picture, &result);
/* if zero size, it means the image was buffered */
if (result == 1 && result2 == 0) {
ret = av_interleaved_write_frame(oc, &pkt);
}
after exactly 32 frames - av_interleaved_write_frame is getting called.
Any ideas?