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

  • Home
  • SEARCH
  • 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 8159927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:04:49+00:00 2026-06-06T18:04:49+00:00

I have just read this in the book OpenCV 2 Computer Vision Application Programming

  • 0

I have just read this in the book OpenCV 2 Computer Vision Application Programming Cookbook by R. Laganiere :

It is important to note that in order to open the specified video
file, your computer must have the corresponding codec installed,
otherwise cv::VideoCapture will not be able to understand the input
file. Normally, if you are able to open your video file with a video
player on your machine (such as the Windows Media Player), then OpenCV
should also be able to read this file.

Unfortunately, things aren’t that easy for me. Yes, I can read avi files on my video player, however it does not work with my OpenCV-Qt application. VideoCapture isOpen() method returns false, despite the fact that the path is correct, and every codec needed seem to be here. I tried several files, so it is not related to one particular format.

Does someone here has experience in opening avi files in Ubuntu using OpenCV ? I think this is a big issue, can’t find any trully relevant solution on the internet…

Thanks !!

[EDIT] Here is the function I am working on; some of the variables here are class members, so it may looks incomplete. However, it is this very piece of code that is not working. In particular, the line where I instanciate a new VideoCapture object.

void MainWindow::on_actionOuvrir_fichier_triggered()
{
    //mettre a -1 streamId
    streamId = -1;
    //get path to the avi file
    QString fileName = QFileDialog::getOpenFileName(this,tr("Ouvrir fichier video"),"/home", tr("Videos (*.avi)"));
    std::string utf8_text = fileName.toUtf8().constData();
    //open .avi
    capture = new VideoCapture(utf8_text);
    //check 
    if(!capture->isOpened())
        cout << "probleme ouverture fichier video" << endl;
    //delay between each frame in ms
    rate = capture->get(CV_CAP_PROP_FPS);
    delay = 1000 / rate;
    //start Qtimer recordId
    recordId = startTimer(delay);
    //capture first frame
    if(!capture->read(in))
        cout << "probleme lecture frame fichier video" << endl;
}

[EDIT 2] test on Windows 7

void MainWindow::on_actionOuvrir_fichier_triggered()
{
    //mettre a -1 streamId
    streamId = -1;
    //ouvrir fenetre navigation fichiers pour recuperer path vers .avi
    QString fileName = QFileDialog::getOpenFileName(this,tr("Ouvrir fichier video"),"/home",
                                                    tr("Videos (*.avi)"));
    //std::string utf8_text = fileName.toUtf8().constData();
    std::string current_locale_text = fileName.toLocal8Bit().constData();
    if(QDir().exists(current_locale_text.c_str())) std::cout << "Path is good!" << endl;
    //ouvrir .avi
    capture = new VideoCapture(current_locale_text);
    //check ouverture
    if(!capture->isOpened())
        cout << "probleme ouverture fichier video" << endl;
    //calculer delay between each frame in ms
//    rate = capture->get(CV_CAP_PROP_FPS);
//    delay = 1000 / rate;
    //demarrer timer recordId
    recordId = startTimer(100);
    //capture premiere frame
    if(!capture->read(in))
        cout << "probleme lecture frame fichier video" << endl;
}

With that code I was able to open SOME avi files, but not all (actually far from that). So I guess I definitely have a codec issue… does anyone can tell me how to fix this under Ubuntu ? Don’t let me go on bounty for that one ! Thank you very much.

[EDIT 3]
As suggested by Etienne, I followed instructions here and tried to convert my video to the I420 format supposedly supported by OpenCV on all platforms, using mencoder with the command line given. So I went from 24 bits RGB (RV24) codec to Planar 4:2:0 YUV (I420), according to VLC. Same behavior though, I’m still unable to instanciate the VideoCapture object.

THERE IS A LOT OF UNSOLVED CASES similar to mine on Stack Overflow…

  • 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-06T18:04:51+00:00Added an answer on June 6, 2026 at 6:04 pm

    I finally managed to solve my problem.

    What I did :

    • try to open some video to finally find one that would work. Fortunately it only took me 3 videos to find one that work.

    • check the codec with VLC. It is MPEG-4 XVID.

    • use mencoder to convert the file I wanted to read to XVID:

      sudo mencoder myFile.avi -ovc lavc vcodec=mpeg4:mbd=2:cbp:trell:vbitrate=300 -ffourcc XVID -o test.avi

    I also switched to old C function cvCaptureFromFile(). I will go back to C++ interface to make sure it was indeed a codec issue, but I am pretty sure it was ([EDIT] it was a codec issue).

    What did not work :

    • recompile OpenCV with Qt support enabled
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read in the K&R II C Programming ANSI C book that the
Just have read sass changelog and found out that FSSM (the gem that had
I am new to Java. I just read that class variables in Java have
I just read this statement in a java book saying Objects in java reside
I just read a book on object-oriented programming patterns. It describes a Factory pattern
I've read about this operator on a book but being that I don't use
i have just started using Moq ver (3.1) and i have read blogs and
I have just switched from svn to mercurial and have read some tutorials about
I've written an XML parser in Python and have just added functionality to read
I recall I have read about a parser which you just have to feed

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.