fix(encoder): timestamp errors processing frames with PTS equal to 0

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x
2024-11-10 00:00:00 +00:00
parent c8f2acdea6
commit e477123e88
4 changed files with 26 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdint>
#include <spdlog/spdlog.h>
@@ -202,11 +203,17 @@ int write_frame(
AVFrame *frame,
AVCodecContext *enc_ctx,
AVFormatContext *ofmt_ctx,
int out_vstream_idx
int out_vstream_idx,
int64_t frame_idx
) {
AVFrame *converted_frame = nullptr;
int ret;
// Set the frame's presentation timestamp if not set
if (frame->pts <= 0) {
frame->pts = frame_idx;
}
// Convert the frame to the encoder's pixel format if needed
if (frame->format != enc_ctx->pix_fmt) {
converted_frame = convert_avframe_pix_fmt(frame, enc_ctx->pix_fmt);