Note that there are some explanatory texts on larger screens.

plurals
  1. POOpen and read avi files with OpenCV - Ubuntu
    text
    copied!<p>I have just read this in the book OpenCV 2 Computer Vision Application Programming Cookbook by R. Laganiere :</p> <blockquote> <p>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.</p> </blockquote> <p>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.</p> <p>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...</p> <p>Thanks !!</p> <p>[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.</p> <pre><code>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-&gt;isOpened()) cout &lt;&lt; "probleme ouverture fichier video" &lt;&lt; endl; //delay between each frame in ms rate = capture-&gt;get(CV_CAP_PROP_FPS); delay = 1000 / rate; //start Qtimer recordId recordId = startTimer(delay); //capture first frame if(!capture-&gt;read(in)) cout &lt;&lt; "probleme lecture frame fichier video" &lt;&lt; endl; } </code></pre> <p>[EDIT 2] test on Windows 7</p> <pre><code>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 &lt;&lt; "Path is good!" &lt;&lt; endl; //ouvrir .avi capture = new VideoCapture(current_locale_text); //check ouverture if(!capture-&gt;isOpened()) cout &lt;&lt; "probleme ouverture fichier video" &lt;&lt; endl; //calculer delay between each frame in ms // rate = capture-&gt;get(CV_CAP_PROP_FPS); // delay = 1000 / rate; //demarrer timer recordId recordId = startTimer(100); //capture premiere frame if(!capture-&gt;read(in)) cout &lt;&lt; "probleme lecture frame fichier video" &lt;&lt; endl; } </code></pre> <p>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.</p> <p>[EDIT 3] As suggested by <a href="https://stackoverflow.com/users/461338/etienne">Etienne</a>, I followed instructions <a href="http://opencv.willowgarage.com/wiki/VideoCodecs" rel="nofollow noreferrer">here</a> 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.</p> <p><a href="https://stackoverflow.com/questions/6971231/first-time-using-open-cv-not-able-to-play-avi-file">THERE IS A LOT OF UNSOLVED CASES</a> similar to mine on Stack Overflow...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload