@@ -852,51 +852,70 @@ static void ffmpeg_log_callback(void *ptr, int level, const char *fmt, va_list v
852852
853853class InternalFFMpegRegister
854854{
855- public:
856- InternalFFMpegRegister ()
855+ static void init_ ()
857856 {
858- AutoLock lock (_mutex);
859- if (!_initialized)
857+ static InternalFFMpegRegister instance;
858+ }
859+
860+ static void initLogger_ ()
861+ {
862+ #ifndef NO_GETENV
863+ char * debug_option = getenv (" OPENCV_FFMPEG_DEBUG" );
864+ if (debug_option != NULL )
860865 {
861- #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
862- avformat_network_init ();
866+ av_log_set_level (AV_LOG_VERBOSE);
867+ av_log_set_callback (ffmpeg_log_callback);
868+ }
869+ else
863870 #endif
871+ {
872+ av_log_set_level (AV_LOG_ERROR);
873+ }
874+ }
864875
865- /* register all codecs, demux and protocols */
866- av_register_all ();
867-
868- /* register a callback function for synchronization */
869- av_lockmgr_register (&LockCallBack);
870-
871- #ifndef NO_GETENV
872- char * debug_option = getenv (" OPENCV_FFMPEG_DEBUG" );
873- if (debug_option != NULL )
876+ public:
877+ static void init ()
878+ {
879+ if (!_initialized)
880+ {
881+ AutoLock lock (_mutex);
882+ if (!_initialized)
874883 {
875- av_log_set_level (AV_LOG_VERBOSE);
876- av_log_set_callback (ffmpeg_log_callback);
884+ init_ ();
877885 }
878- else
886+ }
887+ initLogger_ (); // update logger setup unconditionally (GStreamer's libav plugin may override these settings)
888+ }
889+
890+ InternalFFMpegRegister ()
891+ {
892+ #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0)
893+ avformat_network_init ();
879894#endif
880- {
881- av_log_set_level (AV_LOG_ERROR);
882- }
883895
884- _initialized = true ;
885- }
896+ /* register all codecs, demux and protocols */
897+ av_register_all ();
898+
899+ /* register a callback function for synchronization */
900+ av_lockmgr_register (&LockCallBack);
901+
902+ _initialized = true ;
886903 }
887904
888905 ~InternalFFMpegRegister ()
889906 {
890907 _initialized = false ;
891908 av_lockmgr_register (NULL );
909+ av_log_set_callback (NULL );
892910 }
893911};
894912
895- static InternalFFMpegRegister _init;
896-
897913bool CvCapture_FFMPEG::open ( const char * _filename )
898914{
915+ InternalFFMpegRegister::init ();
916+
899917 AutoLock lock (_mutex);
918+
900919 unsigned i;
901920 bool valid = false ;
902921
@@ -2288,6 +2307,10 @@ static inline void cv_ff_codec_tag_dump(const AVCodecTag *const *tags)
22882307bool CvVideoWriter_FFMPEG::open ( const char * filename, int fourcc,
22892308 double fps, int width, int height, bool is_color )
22902309{
2310+ InternalFFMpegRegister::init ();
2311+
2312+ AutoLock lock (_mutex);
2313+
22912314 CV_CODEC_ID codec_id = CV_CODEC (CODEC_ID_NONE);
22922315 int err, codec_pix_fmt;
22932316 double bitrate_scale = 1 ;
0 commit comments