Skip to content

Commit 8e129b1

Browse files
dsaedtlerRytoEX
authored andcommitted
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).
1 parent 16cb051 commit 8e129b1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

plugins/obs-outputs/flv-mux.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static int32_t last_time = 0;
307307

308308
static void flv_video(struct serializer *s, int32_t dts_offset, struct encoder_packet *packet, bool is_header)
309309
{
310-
int64_t offset = packet->pts - packet->dts;
310+
int32_t ct_offset_ms = get_ms_time(packet, packet->pts) - get_ms_time(packet, packet->dts);
311311
int32_t time_ms = get_ms_time(packet, packet->dts) - dts_offset;
312312

313313
if (!packet->data || !packet->size)
@@ -332,7 +332,7 @@ static void flv_video(struct serializer *s, int32_t dts_offset, struct encoder_p
332332
/* these are the 5 extra bytes mentioned above */
333333
s_w8(s, packet->keyframe ? 0x17 : 0x27);
334334
s_w8(s, is_header ? 0 : 1);
335-
s_wb24(s, get_ms_time(packet, offset));
335+
s_wb24(s, ct_offset_ms);
336336
s_write(s, packet->data, packet->size);
337337

338338
write_previous_tag_size(s);
@@ -486,7 +486,8 @@ void flv_packet_ex(struct encoder_packet *packet, enum video_id_t codec_id, int3
486486

487487
// H.264/HEVC composition time offset
488488
if ((codec_id == CODEC_H264 || codec_id == CODEC_HEVC) && type == PACKETTYPE_FRAMES) {
489-
s_wb24(&s, get_ms_time(packet, packet->pts - packet->dts));
489+
int32_t ct_offset_ms = get_ms_time(packet, packet->pts) - get_ms_time(packet, packet->dts);
490+
s_wb24(&s, ct_offset_ms);
490491
}
491492

492493
// packet data

0 commit comments

Comments
 (0)