Skip to content

Commit

Permalink
obs-outputs: Set FLV DTS offset based on first audio or video packet
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod authored and RytoEX committed Jul 22, 2024
1 parent 7cf4974 commit 31963f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions plugins/obs-outputs/flv-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct flv_output {

pthread_mutex_t mutex;

bool got_first_video;
bool got_first_packet;
int32_t start_dts_offset;
};

Expand Down Expand Up @@ -500,7 +500,7 @@ static bool flv_output_start(void *data)
if (!obs_output_initialize_encoders(stream->output, 0))
return false;

stream->got_first_video = false;
stream->got_first_packet = false;
stream->sent_headers = false;
os_atomic_set_bool(&stream->stopping, false);

Expand Down Expand Up @@ -579,10 +579,10 @@ static void flv_output_data(void *data, struct encoder_packet *packet)
}

if (packet->type == OBS_ENCODER_VIDEO) {
if (!stream->got_first_video) {
if (!stream->got_first_packet) {
stream->start_dts_offset =
get_ms_time(packet, packet->dts);
stream->got_first_video = true;
stream->got_first_packet = true;
}

switch (stream->video_codec[packet->track_idx]) {
Expand Down Expand Up @@ -616,6 +616,12 @@ static void flv_output_data(void *data, struct encoder_packet *packet)
}
obs_encoder_packet_release(&parsed_packet);
} else {
if (!stream->got_first_packet) {
stream->start_dts_offset =
get_ms_time(packet, packet->dts);
stream->got_first_packet = true;
}

if (packet->track_idx != 0) {
write_audio_packet_ex(stream, packet, false,
packet->track_idx);
Expand Down
12 changes: 9 additions & 3 deletions plugins/obs-outputs/rtmp-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ static bool init_connect(struct rtmp_stream *stream)
stream->total_bytes_sent = 0;
stream->dropped_frames = 0;
stream->min_priority = 0;
stream->got_first_video = false;
stream->got_first_packet = false;

settings = obs_output_get_settings(stream->output);
dstr_copy(&stream->path,
Expand Down Expand Up @@ -1761,10 +1761,10 @@ static void rtmp_stream_data(void *data, struct encoder_packet *packet)
}

if (packet->type == OBS_ENCODER_VIDEO) {
if (!stream->got_first_video) {
if (!stream->got_first_packet) {
stream->start_dts_offset =
get_ms_time(packet, packet->dts);
stream->got_first_video = true;
stream->got_first_packet = true;
}

switch (stream->video_codec[packet->track_idx]) {
Expand All @@ -1788,6 +1788,12 @@ static void rtmp_stream_data(void *data, struct encoder_packet *packet)
break;
}
} else {
if (!stream->got_first_packet) {
stream->start_dts_offset =
get_ms_time(packet, packet->dts);
stream->got_first_packet = true;
}

obs_encoder_packet_ref(&new_packet, packet);
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/obs-outputs/rtmp-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct rtmp_stream {
struct deque packets;
bool sent_headers;

bool got_first_video;
bool got_first_packet;
int64_t start_dts_offset;

volatile bool connecting;
Expand Down

0 comments on commit 31963f8

Please sign in to comment.