1
0
Эх сурвалжийг харах

obs-outputs: Set FLV DTS offset based on first audio or video packet

derrod 1 жил өмнө
parent
commit
31963f8dac

+ 10 - 4
plugins/obs-outputs/flv-output.c

@@ -51,7 +51,7 @@ struct flv_output {
 
 	pthread_mutex_t mutex;
 
-	bool got_first_video;
+	bool got_first_packet;
 	int32_t start_dts_offset;
 };
 
@@ -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);
 
@@ -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]) {
@@ -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);

+ 9 - 3
plugins/obs-outputs/rtmp-stream.c

@@ -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,
@@ -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]) {
@@ -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);
 	}
 

+ 1 - 1
plugins/obs-outputs/rtmp-stream.h

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