From 8e129b171d583986d88a19aafe246d4ff88c0e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20S=C3=A4dtler?= Date: Tue, 13 May 2025 02:29:43 +0200 Subject: [PATCH] obs-outputs: Correct FLV composition time offset calculations The conversion to milliseconds rounds down. Rounding down DTS and CT values independently results in a cumulative error that results in the PTS (DTS + CT) being incorrect (off-by-one). --- plugins/obs-outputs/flv-mux.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/obs-outputs/flv-mux.c b/plugins/obs-outputs/flv-mux.c index 80b02e04f..c3f82dca1 100644 --- a/plugins/obs-outputs/flv-mux.c +++ b/plugins/obs-outputs/flv-mux.c @@ -307,7 +307,7 @@ static int32_t last_time = 0; static void flv_video(struct serializer *s, int32_t dts_offset, struct encoder_packet *packet, bool is_header) { - int64_t offset = packet->pts - packet->dts; + int32_t ct_offset_ms = get_ms_time(packet, packet->pts) - get_ms_time(packet, packet->dts); int32_t time_ms = get_ms_time(packet, packet->dts) - dts_offset; if (!packet->data || !packet->size) @@ -332,7 +332,7 @@ static void flv_video(struct serializer *s, int32_t dts_offset, struct encoder_p /* these are the 5 extra bytes mentioned above */ s_w8(s, packet->keyframe ? 0x17 : 0x27); s_w8(s, is_header ? 0 : 1); - s_wb24(s, get_ms_time(packet, offset)); + s_wb24(s, ct_offset_ms); s_write(s, packet->data, packet->size); write_previous_tag_size(s); @@ -486,7 +486,8 @@ void flv_packet_ex(struct encoder_packet *packet, enum video_id_t codec_id, int3 // H.264/HEVC composition time offset if ((codec_id == CODEC_H264 || codec_id == CODEC_HEVC) && type == PACKETTYPE_FRAMES) { - s_wb24(&s, get_ms_time(packet, packet->pts - packet->dts)); + int32_t ct_offset_ms = get_ms_time(packet, packet->pts) - get_ms_time(packet, packet->dts); + s_wb24(&s, ct_offset_ms); } // packet data