diff --git a/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp b/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp index 99969a1a5..febc326e1 100644 --- a/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp +++ b/src/lib/image/MovieFFMpeg/MovieFFMpeg.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1420,14 +1421,14 @@ namespace TwkMovie { if (!videoToolboxInit(avCodec, avCodecContext, hardwareContext)) { - static bool hasDisplayedError = false; - if (!hasDisplayedError) - { - std::cout << "WARNING: Hardware decoder is not available " - "or failed to intialize." - << std::endl; - hasDisplayedError = true; - } + static std::once_flag warnOnce; + std::call_once(warnOnce, + []() + { + std::cout << "WARNING: Hardware decoder is not available " + "or failed to intialize." + << std::endl; + }); } } #endif @@ -3785,14 +3786,15 @@ namespace TwkMovie const AVPixFmtDescriptor* desc = av_pix_fmt_desc_get(nativeFormat); if (!desc && nativeFormat == AV_PIX_FMT_NONE) { - static bool warned = false; - if (!warned) - { - std::cout << "WARNING: FFmpeg detected pixel format " - "AV_PIX_FMT_NONE for frames in " - << m_filename << ". Using fallback pixel format: " << av_get_pix_fmt_name(m_pxlFormatOnOpen) << std::endl; - warned = true; - } + static std::once_flag warnOnce; + std::call_once(warnOnce, + [this]() + { + std::cout << "WARNING: FFmpeg detected pixel format " + "AV_PIX_FMT_NONE for frames in " + << m_filename << ". Using fallback pixel format: " << av_get_pix_fmt_name(m_pxlFormatOnOpen) + << std::endl; + }); // Use the pixel format detected when the file was opened as a // fallback. Assumes that m_pxlFormatOnOpen is set because the file // was opened.