Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTS not incremented correctly #9

Open
flm8620 opened this issue May 1, 2022 · 1 comment
Open

PTS not incremented correctly #9

flm8620 opened this issue May 1, 2022 · 1 comment

Comments

@flm8620
Copy link

flm8620 commented May 1, 2022

In the line

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:

[libx264 @ 0x564948d1d560] non-strictly-monotonic PTS
@dmikushin
Copy link
Contributor

Hi @flm8620 thank you for this report, would you like to go ahead and make a pull request? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants