@@ -45,8 +45,8 @@ LibavStreamer::LibavStreamer(
4545 const std::string & content_type)
4646: ImageTransportImageStreamer(request, connection, node), format_context_(0 ), codec_(0 ),
4747 codec_context_ (0 ), video_stream_(0 ), frame_(0 ), sws_context_(0 ),
48- first_image_timestamp_(std:: nullopt ), format_name_(format_name ), codec_name_(codec_name ),
49- content_type_(content_type), opt_(0 ), io_buffer_(0 )
48+ first_image_received_( false ), first_image_time_( ), format_name_(format_name ),
49+ codec_name_(codec_name), content_type_(content_type), opt_(0 ), io_buffer_(0 )
5050{
5151 bitrate_ = request.get_query_param_value_or_default <int >(" bitrate" , 100000 );
5252 qmin_ = request.get_query_param_value_or_default <int >(" qmin" , 10 );
@@ -220,8 +220,9 @@ void LibavStreamer::sendImage(
220220 const std::chrono::steady_clock::time_point & time)
221221{
222222 std::scoped_lock lock (encode_mutex_);
223- if (!first_image_timestamp_.has_value ()) {
224- first_image_timestamp_ = time;
223+ if (!first_image_received_) {
224+ first_image_received_ = true ;
225+ first_image_time_ = time;
225226 }
226227
227228 AVPixelFormat input_coding_format = AV_PIX_FMT_BGR24;
@@ -277,7 +278,7 @@ void LibavStreamer::sendImage(
277278 uint8_t * output_buf;
278279
279280 double seconds = std::chrono::duration_cast<std::chrono::duration<double >>(
280- time - first_image_timestamp_. value () ).count ();
281+ time - first_image_time_ ).count ();
281282 // Encode video at 1/0.95 to minimize delay
282283 pkt->pts = (int64_t )(seconds / av_q2d (video_stream_->time_base ) * 0.95 );
283284 if (pkt->pts <= 0 ) {
0 commit comments