[Solved]Opencv ffmpeg: Video capture ("Filename.avi") crashes on a non development machine - MAC 10.8.2
-
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 = appSOURCES += 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?
-
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
-
Hi SGaist,
Thanks for you help.
These are the things I have tried:
- 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.
- 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. - I have tried to update the ID's and change the library paths, but no luck.
- 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?
-
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
-
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?
-
Did you also check the dependencies of libav (looks like libav from the names or is it ffmpeg) ?
-
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.
-
Did you also corrected the paths from ffmpeg's dependencies ?
-
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.
-
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 ?