Hi
I was wondering how I would go about to build opencv with ffmpeg.
Is it correct to add '-DWITH_FFMPEG=ON' to setup-opencv.js in the opencv-build project?
If so I have also have the problem on how to actually do the building. When I tried the setup-opencv.js file always gets overwritten with the original, hence not building with ffmpeg.
Probably the proper way to do it would be to clone the opencv-build repo, make the adjustments and then include the modified version in your package.json.
Not sure why you can't modify it in the node_modules folder directly, for me it works, maybe depends on the npm version/ the package manager you use.
Thanks for the quick answer. I will look into the cloning the repo.
Why the simple way didn't work, probably my fault. Maybe the reason was that I was using yarn? Or maybe I did not have the most recent version of both opencv-build and opencv4nodejs installed.
@fakob you can check my docker image build:
https://github.com/SkeLLLa/docker-ffmpeg-opencv
It also requires ffmpeg-dev package with properly linked libav* libraries.
@SkeLLLa thanks. I have to admit that I never used docker. If I understood correctly, it would not help me as I am building a desktop app.
@justadudewhohacks you were right. It worked when all was up to date and I built them separately.
But now I noticed that there apparently was a misunderstanding on my side what '-DWITH_FFMPEG=ON' actually does. I thought that it will also build ffmpeg and include it in the opencv install. This does not seem to be the case. I found somewhere a reference saying that this flag only enables support for ffmpeg.
My original problem was that libopencv_videoio.3.4.1.dylib links to ffmpegs libavcodec.57.dylib, but is looking for it on a local path. This happens btw even without setting '-DWITH_FFMPEG=ON'.
As many users of my app might not have ffmpeg installed, I wanted to make sure that i also include ffmpeg in the bundle.
@fakob Dockerfile contain compilation steps that you could use in your application.
Also if you're building desktop app you may need to compile opencv statically or just use standalone ffmpeg for extracting images and then pass it to opencv (that could be compiled without ffmpeg support)
Yeah I don't think OpenCV builds ffmpeg for you, it only enables support for it. Also I think the cmake script of OpenCV will auto detect ffmpeg on your system and compile it with ffmpeg support unless you explicitly set '-DWITH_FFMPEG=OFF'.
@SkeLLLa ah ok, that sounds valuable. Thanks I will look into it.
@justadudewhohacks that explains a lot :-) Thanks. Now I just have to include the ffmpeg libraries and do the linking right.
@fakob did you ever find out how to include ffmpeg support? I'm having the same issue...
@alberto2000, I have now a version which works for me. It is more of a brute force method and I am sure that can be done in a more elegant way.
brew to install ffmpeglibopencv_videoio.dylib to the copied filesHere is the script which works for me https://github.com/fakob/MoviePrint_v004/blob/master/scripts/ffmpeg.js
@fakob Hi, i have the same issue, your link is not working. could you update it? thx.
@dreambit link is fixed.
Can you explain to me how to properly install ffmpeg, so that the opencv build recognizes ffmpeg. Tried several times and still encountered "NO" in the build los
@FloStar3000 I had used brew to install ffmpeg. And this was then apparently recognised by the opencv-build package. Not sure though what is exactly needed, so that package recognises ffmpeg.
For my own reference in the future, and of course for others looking into this --- I managed to get it enabled in Ubuntu 18.04 LTS
Video I/O:
-- DC1394: NO
-- FFMPEG: YES
-- avcodec: YES (ver 57.107.100)
-- avformat: YES (ver 57.83.100)
-- avutil: YES (ver 55.78.100)
-- swscale: YES (ver 4.8.100)
-- avresample: YES (ver 3.7.0)
-- GStreamer: NO
-- libv4l/libv4l2: NO
-- v4l/v4l2: linux/videodev2.h
Prior to this, I had NO for ffmpeg. I noticed in the build logs:
Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
-- No package 'libavcodec' found
-- No package 'libavformat' found
-- No package 'libavutil' found
-- No package 'libswscale' found
-- Checking for module 'libavresample'
-- No package 'libavresample' found
In the end, it was quite simple. Before installing opencv4nodejs with npm, I simply apt-get installed the following packages:
apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev
Note, I am no linux master here, so I may have extra packages in, or even a missing one, but once I installed it, and removed/re-added the npm package, the build process detected it. I hope this works on my end, but wanted to internet-document how to at least git it "enabled".
Most helpful comment
For my own reference in the future, and of course for others looking into this --- I managed to get it enabled in Ubuntu 18.04 LTS
Prior to this, I had NO for ffmpeg. I noticed in the build logs:
In the end, it was quite simple. Before installing
opencv4nodejswith npm, I simply apt-get installed the following packages:apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-devNote, I am no linux master here, so I may have extra packages in, or even a missing one, but once I installed it, and removed/re-added the npm package, the build process detected it. I hope this works on my end, but wanted to internet-document how to at least git it "enabled".