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.
This commit is contained in:
Norihiro Kamae 2022-06-22 22:58:25 +09:00 committed by Jim
parent ee59905be1
commit bf97248a81

View File

@ -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;