Skip to content

Commit eae89ce

Browse files
committed
feat(libvideo2x): allow processing videos without PTS information
Signed-off-by: k4yt3x <[email protected]>
1 parent 43ecf9e commit eae89ce

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Multi-versioning to critical functions to enhance performance in generic architecture builds.
13+
- Support for processing videos without PTS information (#1278).
1314
- The feature to copy input streams' metadata to the output streams (#1282).
1415

1516
### Changed

include/libvideo2x/encoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Encoder {
6565
int in_vstream_idx
6666
);
6767

68-
int write_frame(AVFrame* frame, int64_t frame_idx);
68+
int write_frame(AVFrame* frame);
6969
int flush();
7070

7171
AVCodecContext* get_encoder_context() const;

src/encoder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,13 @@ int Encoder::init(
269269
}
270270

271271
[[gnu::target_clones("arch=x86-64-v4", "arch=x86-64-v3", "default")]]
272-
int Encoder::write_frame(AVFrame* frame, int64_t frame_idx) {
272+
int Encoder::write_frame(AVFrame* frame) {
273273
AVFrame* converted_frame = nullptr;
274274
int ret;
275275

276276
// Let the encoder decide the frame type
277277
frame->pict_type = AV_PICTURE_TYPE_NONE;
278278

279-
// Calculate this frame's presentation timestamp (PTS)
280-
frame->pts = av_rescale_q(frame_idx, av_inv_q(enc_ctx_->framerate), enc_ctx_->time_base);
281-
282279
// Convert the frame to the encoder's pixel format if needed
283280
if (frame->format != enc_ctx_->pix_fmt) {
284281
converted_frame = conversions::convert_avframe_pix_fmt(frame, enc_ctx_->pix_fmt);

src/libvideo2x.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "libvideo2x.h"
2+
#include <libavcodec/avcodec.h>
23

34
extern "C" {
45
#include <libavutil/avutil.h>
@@ -152,6 +153,7 @@ int VideoProcessor::process_frames(
152153
AVCodecContext* dec_ctx = decoder.get_codec_context();
153154
int in_vstream_idx = decoder.get_video_stream_index();
154155
AVFormatContext* ofmt_ctx = encoder.get_format_context();
156+
AVCodecContext* enc_ctx = encoder.get_encoder_context();
155157
int* stream_map = encoder.get_stream_map();
156158

157159
// Reference to the previous frame does not require allocation
@@ -235,6 +237,10 @@ int VideoProcessor::process_frames(
235237
return ret;
236238
}
237239

240+
// Calculate this frame's presentation timestamp (PTS)
241+
frame->pts =
242+
av_rescale_q(frame_idx_, av_inv_q(enc_ctx->framerate), enc_ctx->time_base);
243+
238244
// Process the frame based on the selected processing mode
239245
AVFrame* proc_frame = nullptr;
240246
switch (processor->get_processing_mode()) {
@@ -308,7 +314,7 @@ int VideoProcessor::write_frame(AVFrame* frame, encoder::Encoder& encoder) {
308314
int ret = 0;
309315

310316
if (!benchmark_) {
311-
ret = encoder.write_frame(frame, frame_idx_);
317+
ret = encoder.write_frame(frame);
312318
if (ret < 0) {
313319
av_strerror(ret, errbuf, sizeof(errbuf));
314320
logger()->critical("Error encoding/writing frame: {}", errbuf);

0 commit comments

Comments
 (0)