Skip to content

Commit 83e1be9

Browse files
committed
Fix video timing when recording for the second time
1 parent a5e01ce commit 83e1be9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/jngl/record/VideoRecorder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct VideoRecorder::Impl {
3434
AVCodecContext* audioCodecContext = nullptr;
3535
AVFrame* audioFrame = nullptr;
3636
int64_t audioPts = 0;
37+
int64_t videoPts = 0;
3738
std::unique_ptr<uint8_t[]> backBuffer;
3839
std::unique_ptr<uint8_t[]> pixelBuffer;
3940
std::unique_ptr<std::thread> workerThread;
@@ -274,8 +275,7 @@ void VideoRecorder::draw() const {
274275
sws_scale(swsCtx, inData, inLinesize, 0, impl->codecContext->height, impl->frame->data,
275276
impl->frame->linesize);
276277

277-
static int64_t pts_counter = 0;
278-
impl->frame->pts = pts_counter++;
278+
impl->frame->pts = impl->videoPts++;
279279

280280
AVPacket* pkt = av_packet_alloc();
281281
if (avcodec_send_frame(impl->codecContext, impl->frame) < 0) {
@@ -315,7 +315,7 @@ void VideoRecorder::draw() const {
315315
frameData[i] = static_cast<int16_t>(impl->audioPacketSamples[i] * 32767.0f);
316316
}
317317
} else {
318-
auto* left = reinterpret_cast<float*>(impl->audioFrame->data[0]); // NOLINT
318+
auto* left = reinterpret_cast<float*>(impl->audioFrame->data[0]); // NOLINT
319319
auto* right = reinterpret_cast<float*>(impl->audioFrame->data[1]); // NOLINT
320320
for (int i = 0; i < impl->audioFrame->nb_samples; ++i) {
321321
left[i] = impl->audioPacketSamples[2 * static_cast<size_t>(i)];

0 commit comments

Comments
 (0)