Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Opencv ffmpeg: Video capture ("Filename.avi") crashes on a non development machine - MAC 10.8.2

[Solved]Opencv ffmpeg: Video capture ("Filename.avi") crashes on a non development machine - MAC 10.8.2

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 9.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JerryLouis
    wrote on last edited by
    #1

    I was trying to deploy a simple Qt Opencv Application, the following is the code:

    Qt: .pro file:

    @ QT += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = opencvVideoTest
    TEMPLATE = app

    SOURCES += main.cpp\
        mainwindow.cpp
    
    HEADERS  += mainwindow.h
    
    FORMS    += mainwindow.ui
    
    INCLUDEPATH = -I/usr/local/include
    
    LIBS += -lm -lopencv_core -lopencv_highgui -lopencv_imgproc
    

    @
    Mainwindow.cpp:

    @ #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <opencv2/core/core.hpp>
    #include <opencv/cv.h>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        cv::Mat img;
    
       cv::VideoCapture cap("video.avi");
    
       if(cap.isOpened()){
    
       for(;;){
           cap.read(img);
           cv::resize(img,img,cv::Size(604,480));
           cv::imshow("Opencv", img);
           cv::waitKey(33);
       }
       }
       else{
    
       }
    
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }@
    

    The above snippet works fine on the development machine, which by the has Opencv 2.4.3, ffmpeg 1.1.2 & Qt 5.0.1. This what happens when I try to deploy, running the otool before using macdeployqt and the output:

    @ > /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
    version 169.3.0) /usr/local/opt/opencv/lib/libopencv_core.2.4.3.dylib
    (compatibility version 2.4.0, current version 2.4.3)
    > /usr/local/opt/opencv/lib/libopencv_highgui.2.4.3.dylib
    (compatibility version 2.4.0, current version 2.4.3)
    > /usr/local/opt/opencv/lib/libopencv_imgproc.2.4.3.dylib
    (compatibility version 2.4.0, current version 2.4.3)
    > /usr/local/Qt5.0.1/5.0.1/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets
    (compatibility version 5.0.0, current version 5.0.1)
    > /usr/local/Qt5.0.1/5.0.1/clang_64/lib/QtGui.framework/Versions/5/QtGui
    (compatibility version 5.0.0, current version 5.0.1)
    > /usr/local/Qt5.0.1/5.0.1/clang_64/lib/QtCore.framework/Versions/5/QtCore
    (compatibility version 5.0.0, current version 5.0.1)
    > /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
    (compatibility version 1.0.0, current version 1.0.0)
    > /System/Library/Frameworks/AGL.framework/Versions/A/AGL
    (compatibility version 1.0.0, current version 1.0.0)
    > /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current
    version 56.0.0)@

    otool after macdeployqt output:

    @

    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    
      @executable_path/../Frameworks/libopencv_core.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3)
    
     @executable_path/../Frameworks/libopencv_highgui.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3)
     @executable_path/../Frameworks/libopencv_imgproc.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3)
     @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets
    

    (compatibility version 5.0.0, current version 5.0.1)

     @executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui (compatibility version 5.0.0, current version 5.0.1)
     @executable_path/../Frameworks/QtCore.framework/Versions/5/QtCore (compatibility version 5.0.0, current version 5.0.1)
     /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
     /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
     /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)@
    

    But after deploying it, when I try and run the app on the user's machine it crashes, no error reported either, the exact samething used to happen in Windows but when I copied the opencv_ffmpeg.dll into the exe folder it worked fine. I tried to use the same logic here and failed, then I manually addded each lib files of all the ffmpeg and its dependency into the project folder and still failed. Any other solution, please help? I'm a newbie to mac dpeloyment. Am i missing or overlooked something?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you also check that all dependencies have their path corrected ?
      MacDeployQt does that pretty good for the Qt/system stuff but sometimes misses external libraries. It might also not copy all required libraries. Inspect the framework content to ensure that you have all the libraries needed as well as opencv dependencies (IIRC libflann comes to my mind)

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JerryLouis
        wrote on last edited by
        #3

        Hi SGaist,

        Thanks for you help.

        These are the things I have tried:

        1. All the libraries of the opencv works just fine when deployed. But when I try to access libopencv_highgui which has a dozen more dependencies all of them related to ffmpeg, this is where the app crashes.
        2. I have ran otool on each of these libraries and there dependencies, after I deploy they all correctly point to appropriate path. E.g: @executable_path/../Frameworks/libopencv_highgui.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3).
          Also all its dependencies have the similar @executable_path.
        3. I have tried to update the ID's and change the library paths, but no luck.
        4. But strangely after usign macdeployqt, if I delete all the dependencies of libopencv_highgui(excluding opencv) from /../Frameworks folder and copy those dependencies to /usr/local/lib/ it works perfectly, but remember since its already deployed the path is @executable_path not /usr/local/lib, it still works.

        Not sure if this is a bug, looks like it though. The issue is only when a 3rd party shared library likeopencv_highgui has another dependency of its own like libavcode,libpng,libavformat, etc.

        Do you think I should try something else?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you it works with the dependencies in /usr/local/lib, it means that libopencv_highgui is searching them in that place so you have to update libopencv_highgui paths (all of them) to point to its dependencies inside the bundle. You might want to make a script to run "post macdeployqt" step for that

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JerryLouis
            wrote on last edited by
            #5

            Hi SGaist,

            The otool output looks correct for all the opencv_highgui dependencies including the one's within:

            Otool -L opencv_highgui gives me this:

            @@executable_path/../Frameworks/libswscale.2.1.103.dylib (compatibility version 2.4.0, current version 2.4.3)
            @executable_path/../Frameworks/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.3)
            @executable_path/../Frameworks/libopencv_imgproc.2.4.dylib (compatibility version 2.4.0, current version 2.4.3)
            /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
            @executable_path/../Frameworks/libpng15.15.dylib (compatibility version 29.0.0, current version 29.0.0)
            @executable_path/../Frameworks/libavcodec.54.86.100.dylib (compatibility version 54.0.0, current version 54.86.100)
            @executable_path/../Frameworks/libavformat.54.59.106.dylib (compatibility version 54.0.0, current version 54.59.106)
            @executable_path/../Frameworks/libavutil.52.13.100.dylib (compatibility version 52.0.0, current version 52.13.100)
            @executable_path/../Frameworks/libswscale.2.1.103.dylib (compatibility version 2.0.0, current version 2.1.103)
            /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
            /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
            /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
            /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
            /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
            /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.34.0)
            /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
            /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
            /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.12.0)
            /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)
            /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)@

            Stiil crashes, not sure whats wrong?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you also check the dependencies of libav (looks like libav from the names or is it ffmpeg) ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JerryLouis
                wrote on last edited by
                #7

                I did, here is the output for lib_avcodec.54.86.100.dylib:

                @executable_path/../Frameworks/libavcodec.54.86.100.dylib (compatibility version 54.0.0, current version 54.86.100)
                @executable_path/../Frameworks/libavutil.52.dylib (compatibility version 52.0.0, current version 52.13.100)
                @executable_path/../Frameworks/libx264.125.dylib (compatibility version 0.0.0, current version 0.0.0)
                @executable_path/../Frameworks/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
                @executable_path/../Frameworks/libfaac.0.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
                /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
                /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.12.0)
                /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
                /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
                /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
                /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
                /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)

                Yes, these are ffmpeg dependencies, and I have checked the ones within them as well, they all point to the @exec path.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Did you also corrected the paths from ffmpeg's dependencies ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JerryLouis
                    wrote on last edited by
                    #9

                    Yes SGaist tried those as well. But for seem reason at the runtime they throw error's. Only fix was to copy the libraries to the /usr/local/lib and it work fine now. Looks a bug in the macdeployqt mainly for third party libraries. Either way thanks for you help.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      I found out the macdeployqt has some issues for some dependencies. I wrote a script that would copy the missing libraries and corrected the paths for i.e. OpenCV, MySql).
                      Some path were also not corrected within Qt's framework (i.e libmysqlclient_r.16.dylib).

                      One last idea, does the id of the library contain the full path to the library ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved