@@ -53,7 +53,7 @@ LibavStreamer::LibavStreamer(const async_web_server_cpp::HttpRequest &request,
5353 const std::string &format_name, const std::string &codec_name,
5454 const std::string &content_type) :
5555 ImageTransportImageStreamer (request, connection, nh), output_format_(0 ), format_context_(0 ), codec_(0 ), codec_context_(0 ), video_stream_(
56- 0 ), frame_(0 ), sws_context_(0 ), first_image_timestamp_(std:: nullopt ), format_name_(
56+ 0 ), frame_(0 ), sws_context_(0 ), first_image_received_( false ), first_image_time_( ), format_name_(
5757 format_name), codec_name_(codec_name), content_type_(content_type), opt_(0 ), io_buffer_(0 )
5858{
5959
@@ -261,8 +261,9 @@ void LibavStreamer::sendImage(
261261 const std::chrono::steady_clock::time_point & time)
262262{
263263 boost::mutex::scoped_lock lock (encode_mutex_);
264- if (!first_image_timestamp_.has_value ()) {
265- first_image_timestamp_ = time;
264+ if (!first_image_received_) {
265+ first_image_received_ = true ;
266+ first_image_time_ = time;
266267 }
267268 std::vector<uint8_t > encoded_frame;
268269#if (LIBAVUTIL_VERSION_MAJOR < 53)
@@ -355,7 +356,7 @@ void LibavStreamer::sendImage(
355356 uint8_t *output_buf;
356357
357358 double seconds = std::chrono::duration_cast<std::chrono::duration<double >>(time -
358- first_image_timestamp_. value () ).count ();
359+ first_image_time_ ).count ();
359360 // Encode video at 1/0.95 to minimize delay
360361 pkt.pts = (int64_t )(seconds / av_q2d (video_stream_->time_base ) * 0.95 );
361362 if (pkt.pts <= 0 )
0 commit comments