From bf97248a818b74223a915fd30830c65bd73159b4 Mon Sep 17 00:00:00 2001 From: Norihiro Kamae Date: Wed, 22 Jun 2022 22:58:25 +0900 Subject: [PATCH] mac-vth264: Fix PTS passed to the encoder It is reported that the encoder does not follow the bitrate settings. This commit tries to correct the timestamps so that the bitrate control in the encoder works. --- plugins/mac-vth264/encoder.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/mac-vth264/encoder.c b/plugins/mac-vth264/encoder.c index 4fec74de7..8551a1aee 100644 --- a/plugins/mac-vth264/encoder.c +++ b/plugins/mac-vth264/encoder.c @@ -660,17 +660,15 @@ static bool parse_sample(struct vt_h264_encoder *enc, CMSampleBufferRef buffer, CMTime pts = CMSampleBufferGetPresentationTimeStamp(buffer); CMTime dts = CMSampleBufferGetDecodeTimeStamp(buffer); - pts = CMTimeMultiplyByFloat64(pts, - ((Float64)enc->fps_num / enc->fps_den)); - dts = CMTimeMultiplyByFloat64(dts, - ((Float64)enc->fps_num / enc->fps_den)); - if (CMTIME_IS_INVALID(dts)) dts = pts; // imitate x264's negative dts when bframes might have pts < dts else if (enc->bframes) dts = CMTimeSubtract(dts, off); + pts = CMTimeMultiply(pts, enc->fps_num); + dts = CMTimeMultiply(dts, enc->fps_num); + bool keyframe = is_sample_keyframe(buffer); da_resize(enc->packet_data, 0); @@ -772,7 +770,7 @@ static bool vt_h264_encode(void *data, struct encoder_frame *frame, CMTime dur = CMTimeMake(enc->fps_den, enc->fps_num); CMTime off = CMTimeMultiply(dur, 2); - CMTime pts = CMTimeMultiply(dur, frame->pts); + CMTime pts = CMTimeMake(frame->pts, enc->fps_num); CVPixelBufferRef pixbuf = NULL;