yuvpic->pts = iframe;
The iframe is not incremented. It is only incremented when the encoder finished encoding one frame
int got_output;
int ret = avcodec_encode_video2(c, &pkt, yuvpic, &got_output);
if (got_output)
{
fflush(stdout);
// We set the packet PTS and DTS taking in the account our FPS (second argument),
// and the time base that our selected format uses (third argument).
av_packet_rescale_ts(&pkt, (AVRational){ 1, frameRate }, stream->time_base);
pkt.stream_index = stream->index;
printf("Writing frame %d (size = %d)\n", iframe++, pkt.size);
// Write the encoded frame to the mp4 file.
av_interleaved_write_frame(fc, &pkt);
av_packet_unref(&pkt);
}
The current code works because the libvpx-vp9 encoder won't complain about this.
AVCodec* codec = avcodec_find_encoder_by_name("libvpx-vp9");
But if I switch to libx264 encoder, it will complain something like:
In the line
yuvpic->pts = iframe;
Theiframe
is not incremented. It is only incremented when the encoder finished encoding one frameThe current code works because the
libvpx-vp9
encoder won't complain about this.AVCodec* codec = avcodec_find_encoder_by_name("libvpx-vp9");
But if I switch tolibx264
encoder, it will complain something like: