diff --git a/plugins/obs-outputs/flv-output.c b/plugins/obs-outputs/flv-output.c index 5be1c5f2c..f28e9e163 100644 --- a/plugins/obs-outputs/flv-output.c +++ b/plugins/obs-outputs/flv-output.c @@ -36,6 +36,7 @@ struct flv_output { struct dstr path; FILE *file; bool active; + bool sent_headers; int64_t last_packet_ts; }; @@ -176,7 +177,6 @@ static bool flv_output_start(void *data) /* write headers and start capture */ stream->active = true; - write_headers(stream); obs_output_begin_data_capture(stream->output, 0); info("Writing FLV file '%s'...", stream->path.array); @@ -188,6 +188,11 @@ static void flv_output_data(void *data, struct encoder_packet *packet) struct flv_output *stream = data; struct encoder_packet parsed_packet; + if (!stream->sent_headers) { + write_headers(stream); + stream->sent_headers = true; + } + if (packet->type == OBS_ENCODER_VIDEO) { obs_parse_avc_packet(&parsed_packet, packet); write_packet(stream, &parsed_packet, false); diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c index e7d5727bf..edad9fd01 100644 --- a/plugins/obs-outputs/rtmp-stream.c +++ b/plugins/obs-outputs/rtmp-stream.c @@ -43,6 +43,7 @@ struct rtmp_stream { pthread_mutex_t packets_mutex; struct circlebuf packets; + bool sent_headers; bool connecting; pthread_t connect_thread; @@ -155,6 +156,8 @@ static void rtmp_stream_stop(void *data) } os_event_reset(stream->stop_event); + + stream->sent_headers = false; } static inline void set_rtmp_str(AVal *val, const char *str) @@ -207,10 +210,15 @@ static int send_packet(struct rtmp_stream *stream, return ret; } +static inline void send_headers(struct rtmp_stream *stream); + static bool send_remaining_packets(struct rtmp_stream *stream) { struct encoder_packet packet; + if (!stream->sent_headers) + send_headers(stream); + while (get_next_packet(stream, &packet)) if (send_packet(stream, &packet, false) < 0) return false; @@ -230,6 +238,10 @@ static void *send_thread(void *data) break; if (!get_next_packet(stream, &packet)) continue; + + if (!stream->sent_headers) + send_headers(stream); + if (send_packet(stream, &packet, false) < 0) { disconnected = true; break; @@ -299,9 +311,9 @@ static void send_video_header(struct rtmp_stream *stream) send_packet(stream, &packet, true); } -static void send_headers(struct rtmp_stream *stream) +static inline void send_headers(struct rtmp_stream *stream) { - send_meta_data(stream); + stream->sent_headers = true; send_audio_header(stream); send_video_header(stream); } @@ -351,7 +363,7 @@ static int init_send(struct rtmp_stream *stream) } stream->active = true; - send_headers(stream); + send_meta_data(stream); obs_output_begin_data_capture(stream->output, 0); return OBS_OUTPUT_SUCCESS;