Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8498859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:31:01+00:00 2026-06-11T00:31:01+00:00

I have a c++-cli code that is capturing videos from a folder in opencv

  • 0

I have a c++-cli code that is capturing videos from a folder in opencv using capture and then retrieving frames using cvquery frame. I then process frames and once all frames are processed i release the capture. It works fine but when I try to multithread it gives me a warning and cannot capture some of the videos in the folder with warning ” insufficient thread locking around avcodec_open/close()”.

//for each video in folder do
{
    capture=cvCreateFileCapture(filename);

    while(1)
    {
        img=cvqueryframe(capture) 

        if !img break;
        ///process img
    }

    cvreleasecapture(&capture);
}

Is there a way to fix the problem for multithreading? I was thinking of using

while(!capture) 
    capture=cvCreateFileCapture(filename);

but there should a more efficient way, maybe using locking Monitor::Enter(obj) or lock(obj)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:31:02+00:00Added an answer on June 11, 2026 at 12:31 am

    The open and close functions in avcodec are not thread safe. To prevent issues in multi-threaded apps they have a simple mechanism that detects when two threads are inside these functions at the same time and when that happens they write the “insufficient thread locking” message.

    The way to prevent this message is to lock the calls to cvCreateFileCapture and cvreleasecapture (which in turn call avcodec_open and avcodec_close) to ensure that these calls are always serialized. For example, if you had a mutex class called Mutex you could do something like this:

    extern Mutex m; // application-wide mutex
    
    //for each video in folder do
    {
        m.lock();
        capture=cvCreateFileCapture(filename);
        m.unlock();
    
        while(1)
        {
            img=cvqueryframe(capture) 
    
            if !img break;
            ///process img
        }
    
        m.lock();
        cvreleasecapture(&capture);
        m.unlock();
    }
    

    There are many Mutex implementations. On Linux or OS X you can use pthread mutexes. On Windows you can use Win32 mutexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that contains C# code, C++\CLI code and native c++ code.
I have C++/CLI code and I'm using Visual Studio 2008 Team Suite Code Coverage.
I understand that a .exe PE file can have CLI code in it. But
Well I have this code in my Managed C++/Cli in Visual Studio 2008, I
I have a cli application that doesn't like the usage of wildcards. In this
I have a C++/CLI project that wraps around an unmanaged C compression library, and
Im using Debian testing, i have installed php-cli and when i try to execute
I have implemented a web crawler that crawls and retrieves content from .edu TLD.
I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code
I have a class, A , in C++/CLI which derives from a templated base

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.