OpenCV cannot open video file - c++

I use
cv::VideoCapture video(mp4name);
But
video.isOpened()==false;
I use OpenCV 3.4.1.
Any ideas?
Thanks,
Yair

Related

How Disable Auto-focus of a webcam using opencv

I am trying to calibrate two cameras but my problem is the auto-focus. Im using the webcam logitech c920. Anyone knows a way to disable the auto-focus feature?? Im using C++ and opencv 2.4.9 in osx system.
You can try this.
cap = cv2.VideoCapture(1) // Generate camera object
cap.set(cv2.CAP_PROP_AUTOFOCUS, 0) // turn the autofocus off
You can find more information on how to set some properties at these links.
The VideoCapture class
http://docs.opencv.org/3.2.0/d8/dfe/classcv_1_1VideoCapture.html
The VideoCapture properties
http://docs.opencv.org/3.2.0/d4/d15/group__videoio__flags__base.html#ga023786be1ee68a9105bf2e48c700294d
Try v4l-utils:
Install: sudo apt-get install v4l-utils
Find your device v4l2-ctl --list-devices
Replace video0 with output from the previous command and disable autofocus with:
v4l2-ctl -d /dev/video0 --set-ctrl=focus_auto=0

VideoCapture::read always returns false

I'm running OS X El Capitan and trying to use OpenCV VideoCapture to read an .avi file. I've tried it on both opencv 2.4.1 and 3, both of which have the same outcome.
cv::VideoCapture capture("filename.avi");
cv::Mat currentFrame, prevFrame;
bool capPrevSuccess = capture.read(prevFrame);
bool capCurrSuccess = capture.read(currentFrame);
I've verified that the filename.avi is in the current working directory and I don't see any errors in the console.
I'm beginning to wonder if it's something with my machine. I have a similar problem running VideoReader in MATLAB on the same machine. I believe MATLAB uses OpenCV VideoReader as well, perhaps they're connected.
Error using VideoReader/init (line 619) Failed to initialize internal
resources.
Error in VideoReader (line 172)
obj.init(fileName);
EDIT: Looks like this has something to do with the video files I'm using. I downloaded an mp4 video, and had no trouble with it. Unfortunately I need to use the video files I'm using (all .avi), yet they all seem to not work with VideoCapture.

videocapture opencv (ubuntu 13.10, opencv 2.4.8)

when i tried to work with a video file i can't seem to open the file
when i test on isOpen() it gives me thats it did not open
what did i already check:
videofile working and in correct path
rebooting
reinstalling ffmpeg (with diferent configurations)
my code:
VideoCapture readVideo;
readVideo.open(argv[1]);
Mat frame;
if(!readVideo.isOpened()){
fprintf(stderr,"video niet geladen 0 \n");
return 2;
}
Example of the file i give in argv[1]:
out.avi (mpeg4 codex)
it works on someone elses setup so i know its not the code
The problem seemed to be with the installation of the ffmpeg that wasn't compleetly linked to the instalation of opencv, installed bouth again and worked like a charm

Video codec for H264 with opencv

I am trying to create a movie using opencv and I need that output file be in H264 format.
I used the following fourcc in opencv, but I am getting error that suitable codec is not installed.
fourcc=CV_FOURCC('H','2','6','4') ;
When I run my application I get the following error message:
Could not find encoder for codec id 28: Encoder not found
What do I need to be able to use this codec in OpenCV?
H264 is not a codec, but rather a standard, while for example x264 is an encoder that implements the H264 standard (CV_FOURCC('X','2','6','4') ;).
OpenCV can write videos using FFMPEG or VFW. You need to compile FFPMEG with x264-support (instructions can be found on FFMPEG's website)
If you are using VFW: Take a look at http://sourceforge.net/projects/x264vfw/

Possible bug in OpenCV2.4 capturing frames from video

Could it be that there is a bug in OpenCV2.4 highgui for capturing frames from video in windows?
I installed both the precompiled libraries, the ones compiled by me, I can compile everything perfectly and I can run my programs if
they are image based. The problem is only for videos. OpenCV crashes in this function always:
virtual IplImage* retrieveFrame(int)
{
unsigned char* data = 0;
int step=0, width=0, height=0, cn=0;
if(!ffmpegCapture ||
!icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) <-------CRASHES HERE
return 0;
cvInitImageHeader(&frame, cvSize(width, height), 8, cn);
cvSetData(&frame, data, step);
return &frame;
}
This is inside the class cap_ffmpeg.cpp and is called by VideoCapture.
I tried versions 2.4.2 and 2.4.9. My programes were working finde with opencv2
More information
Windows 7
Build the projects with cmake (important as it could be that cmake is not building/finding the right codecs)
VisualStudio 9 2008
OpenCV 2.4.2
EDIT
It looks like it is actually a bug, so, how can I solve this problem and change my code to be able to read avi files?
As a temporary solution I decided to re-encode the videos so OpenCV doesn't use the ffmpeg. I used VirtualDub with the microsoft video 1 compression, which uses "msvidc32.dll" driver.
It works with all my videos so it is enough by now as I can keep working with OpenCV in windows.
I had similar problem. I downloaded VirtualDub, but it did not open one of my avi video because of its FMP4 encode. So in the end, the solution that solved the problem was to install ffdshow, a decoder for windows. See this link: http://www.moviecodec.com/video-codecs/fmp4-codec-with-virtualdub-45814/
Then I do not need to use VirtualDub anymore to re-encode my video anymore!
if your using x64. Please use opencv_ffmpeg245_64.dll this solves may solve the problem. Or rename opencv_ffmpeg245_64.dll to opencv_ffmpeg245.dll may solve the problem.