I am creating a project in c++ with QtCreator (5.14.1, MingGW compiler) and trying to use OpenCv (3.4.16) to read video files. I have tried many files of standard formats and codecs (H.264, yuv420, .mov etc). However, no matter what I try, VideoCapture() always silently fails. It doesn’t crash or show any error code, instead isOpened() is just always false.
I think the cause is that I am building opencv (via this tutorial https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows) without internet connection (I cannot have internet connection on this machine, so please do not ask me to) and therefore it can’t download the FFMPEG libraries during this process. I have been looking everywhere for information about how to download the FFMPEG libraries for opencv directly but I haven’t had any luck.
Can someone please explain what libraries I need to download and how opencv goes about looking for them? because at the moment I don’t know what I need, nor where to put them, and I cant find any information on the topic.
Or, can someone explain why calling VideoCapture(“video.mov”, cv::CAP_ANY) doesn’t have any effect? (despite being able to play the video easily in VLC, MediaPlayer etc).
Code:
`
int main()
{
VideoCapture cap(“C://video.mov”);
//VideoCapture cap(“C:/video.mov”);
//VideoCapture cap(“C:\video.mov”);
//VideoCapture cap(“C:\video.mov”);
if (!cap.isOpened()){
cout << "Error opening video stream or file"<< endl;
return -1;
}
}
`
I have tried downloading some ffmpeg DLLs and the EXEs and adding them to the PATH, no success. I have also tried downloading the shared GPL of ffmpeg (that comes with the libs and include) and added them my .pro file but no change in VideoCapture behavior.
I have also tried moving the opencv_ffmpeg_64.dll (found in opencv/build/bin) to my executable directory but that didn't fix anything.
In the end I used this guys answer,
How do i compile opencv_ffmpeg.dll file using mingw on windows 10 64 bit?
Just note that some of the directories are a little different now. You don't need to put them in a folder named after the hash, or in a 'download' subdirectory, and you need to copy all of them to opencv-build/3rd party/ffmpeg/. I also put them in opencv/source/3rd party/ffmpeg, but not sure if I needed to do that. Finally you need to go into the ffmpeg.cmake file and set 'status' to TRUE when the download fails (or just remove the download part altogether), this lets it call ffmpeg_version.cmake and set things up.
Related
I need a simple ffmpeg conversion task to be done inside an application:
ffmpeg -i input_file.m4v -vcodec copy -acodec copy -vbsf h264_mp4toannexb output_file.ts
This works well using the terminal. I've successfully compiled ffmpeg's static lib. Some examples work perfectly, that means the lib is working. How do I implement the behaviour of the above command line with this library?
I looked into ffmpeg.c. But there is so much code inside that it took me hours to get an idea on how it works. Finally I still don't really understand the whole structure.
I would be very happy if someone could help me understanding how to use the library to do the very same what the example command line does. (At the end I just want to transmux mp4 files to ts files without reencoding)
Thanks in advance
Jack
I have recently started working on a small program with SDL2 and c++. In this program I used IMG_LoadTexture() to load a texture however it just would not want to work, the program could not find the image. So I chanced my program to use SDL_loadBMP(), did not work. After hours of endlessly looking for bugs I still could not find anything.
When I started my project I saved it to my D: disk and not on my C: disk. So when I was about to give up on the whole project I copied my exe, image and libraries to my C: disk and Boom it worked.
So I have no idea why this happens. I refer to my image with a relative path but it just doesn't want to work on my D: disk. Is this a bug? or might it have something to do with settings related to my disk? And how can I make it work on my D: disk?
P.S. I am using windows 7
P.S.S. My apologies in advance for any horrible grammar and spelling mistakes.
Is the working directory of you executable the same you assume it is? On windows happened more than one time that working directory was not the path I believed. With certain compiler configurations the working directory is not the same on wich the executable is, you have to change working directory looking at documentation of your IDE.
What frequently happened to me
CURRENT WORKING DIR
D:/projectdir/
EXPECTED WORKING DIR
D:/projectdir/bin/debug/
where files really are:
D:/projectdir/bin/debug/app.exe
D:/projectdir/bin/debug/texture.png
which files app is trying to loading when launched from IDE:
D:/projectdir/app.exe
D:/projectdir/texture.png
You can quickly test wich is current working directory by calling equivalent on windows of
getcwd (answer from here )
#include <WinBase.h>
int main() {
TCHAR pwd[MAX_PATH];
GetCurrentDirectory(MAX_PATH,pwd);
MessageBox(NULL,pwd,pwd,0);
}
I'm using Wischik's example code for creating AVI files, however after I run the code and it exits successfully no AVI file is created. I looked through the code and cannot find where it writes/saves/creates an AVI file on your computer. Does anyone know where the code saves AVI file or if it doesn't, a way to make it save the AVI file created to your computer? Thanks
link to source code here
Wischik source code
You should find test.avi in the project directory. Since you know it's name, you could also use Windows explorer to search for it.
To examine further, (assuming you are using VC++), goto
Tools > Options > Projects and Solutions > VC++ Directories,
and Show Directories for Include files.
That will tell you where the headers are.
Alternatively, set a break point at the line where AVIFileOpen is called, and follow the execution path to see what it does.
I recently started working with WxWidgets (2.9.4) and was working through a tutorial I found, but it seems that I'm unable to load any images. I've already properly used the handler (for PNG) and the problem happens at run-time. Below is an image of the popup that is displayed when attempting to run the program.
Here is the code:
wxPNGHandler *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxBitmap exit;
exit.LoadFile(wxT("exit.png"), wxBITMAP_TYPE_PNG);
wxToolBar *toolbar = CreateToolBar();
toolbar->AddTool(wxID_EXIT, exit, wxT("Exit"));
toolbar->Realize();
Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(mainWindow::exitProg));
Any help is appreciated.
EDIT: I forgot to mention that when I click Cancel, this happens:
I placed the exit.png file in the build directory (/Debug or /Release) as well as the source code directory, but it still has yet to see it.
What is your working directory?
If you are using visual studio and running using the interface ( F5 or ctrl-F5 or the little run button in the toolbar ) then your working directory is the folder containing the project file. So try copying your image file there.
Or open a command window, cd to one of your build directories, and run your app from the command line.
In general, to avoid this sort of problem, I alter the project properties so that the executable is NOT stored in one of the build folders, but in a new folder ( which I usually call 'bin' - my unix roots are showing! ) and also alter the debugging properties so that the working directory is the bin folder.
There are a couple of advantages to this technique:
Both the release and trhe debug version use the same folder, so you only need one copy of any extra file, like your image file.
It is easy to see the executable and extra files in the working directory without being distracted by all the .obj files that end up in the build folders
IMHO this is well worth the little extra trouble in maintaining non default project properties.
First of all, to avoid problems deep inside wxToolBar, always check the return code of LoadFile() or, alternatively, use wxBitmap::IsOk() to check that the bitmap was successfully loaded.
Second, while adding the handler explicitly as you did is perfectly fine, I'd recommend to just call wxInitAllImageHandlers() as it's simpler and has no real drawbacks unless you are looking to create the smallest program possible.
Finally, to address your real problem, the file clearly doesn't exist at the path you're loading it from. You can, of course, solve this by being careful not to change your working directly (or restore it after changing it) in your program and by placing the file in the correct place. But this is, as you discovered, error-prone, so a better idea is to always use full paths to your resources. To construct them, you will find wxStandardPaths useful, in particular its GetResourcesDir() method.
I tried to work with the boost library to read/write configuration files but I just don't get it.
I even can't run the example code from boost.org (5 Minute Tutorial)
http://www.boost.org/doc/libs/1_49_0/libs/property_tree/examples/debug_settings.cpp
I've downloaded the boost_1_49_0.zip package and unzipped it to my c++ program folder. The code compiles (TheIDE - U++) but it always says "Error: debug_settings.xml: cannot open file" which basically means that the program works, but runs into the exception.
I didn't change the code, I just copy and pasted it to get a working example which I could try to understand then. But I don't even get this one to work. (Since it's exactly the same as in the link, I don't paste the code here... unless you think it's better.)
Please help me... or point to a different way to store variables in a file with some kind of structure (I wan't to learn a way that works for windows and linux, because some of my apps are cross-platform.)
Thanks.
EDIT: debug_settings.xml is in the same folder as the .cpp file
EDIT2: Working now, the debug_settings.xml is now in the folder where the executable is stored. (in my case, U++/TheIDE it's C:\upp\out\MyApps\MINGW.Debug.Debug_Full.Sse2 for debugging)
The configuration file would need to be in the working directory of the executable when it's running.