mirror of
https://github.com/k4yt3x/video2x.git
synced 2024-12-28 06:59:11 +00:00
fix(encoder): timestamp errors processing frames with PTS equal to 0
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
parent
c8f2acdea6
commit
e477123e88
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Timestamp errors processing frames with PTS equal to 0 (#1222).
|
||||||
|
|
||||||
## [6.1.1] - 2024-11-07
|
## [6.1.1] - 2024-11-07
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -28,7 +28,8 @@ int write_frame(
|
|||||||
AVFrame *frame,
|
AVFrame *frame,
|
||||||
AVCodecContext *enc_ctx,
|
AVCodecContext *enc_ctx,
|
||||||
AVFormatContext *ofmt_ctx,
|
AVFormatContext *ofmt_ctx,
|
||||||
int out_vstream_idx
|
int out_vstream_idx,
|
||||||
|
int64_t frame_idx
|
||||||
);
|
);
|
||||||
|
|
||||||
int flush_encoder(AVCodecContext *enc_ctx, AVFormatContext *ofmt_ctx, int out_vstream_idx);
|
int flush_encoder(AVCodecContext *enc_ctx, AVFormatContext *ofmt_ctx, int out_vstream_idx);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
@ -202,11 +203,17 @@ int write_frame(
|
|||||||
AVFrame *frame,
|
AVFrame *frame,
|
||||||
AVCodecContext *enc_ctx,
|
AVCodecContext *enc_ctx,
|
||||||
AVFormatContext *ofmt_ctx,
|
AVFormatContext *ofmt_ctx,
|
||||||
int out_vstream_idx
|
int out_vstream_idx,
|
||||||
|
int64_t frame_idx
|
||||||
) {
|
) {
|
||||||
AVFrame *converted_frame = nullptr;
|
AVFrame *converted_frame = nullptr;
|
||||||
int ret;
|
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
|
// Convert the frame to the encoder's pixel format if needed
|
||||||
if (frame->format != enc_ctx->pix_fmt) {
|
if (frame->format != enc_ctx->pix_fmt) {
|
||||||
converted_frame = convert_avframe_pix_fmt(frame, enc_ctx->pix_fmt);
|
converted_frame = convert_avframe_pix_fmt(frame, enc_ctx->pix_fmt);
|
||||||
|
@ -124,7 +124,13 @@ static int process_frames(
|
|||||||
return ret;
|
return ret;
|
||||||
} else if (ret == 0 && processed_frame != nullptr) {
|
} else if (ret == 0 && processed_frame != nullptr) {
|
||||||
if (!benchmark) {
|
if (!benchmark) {
|
||||||
ret = write_frame(processed_frame, enc_ctx, ofmt_ctx, out_vstream_idx);
|
ret = write_frame(
|
||||||
|
processed_frame,
|
||||||
|
enc_ctx,
|
||||||
|
ofmt_ctx,
|
||||||
|
out_vstream_idx,
|
||||||
|
proc_ctx->processed_frames
|
||||||
|
);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||||
spdlog::critical("Error encoding/writing frame: {}", errbuf);
|
spdlog::critical("Error encoding/writing frame: {}", errbuf);
|
||||||
@ -174,7 +180,9 @@ static int process_frames(
|
|||||||
|
|
||||||
// Encode and write all flushed frames
|
// Encode and write all flushed frames
|
||||||
for (AVFrame *&flushed_frame : flushed_frames) {
|
for (AVFrame *&flushed_frame : flushed_frames) {
|
||||||
ret = write_frame(flushed_frame, enc_ctx, ofmt_ctx, out_vstream_idx);
|
ret = write_frame(
|
||||||
|
flushed_frame, enc_ctx, ofmt_ctx, out_vstream_idx, proc_ctx->processed_frames
|
||||||
|
);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||||
spdlog::critical("Error encoding/writing flushed frame: {}", errbuf);
|
spdlog::critical("Error encoding/writing flushed frame: {}", errbuf);
|
||||||
|
Loading…
Reference in New Issue
Block a user