Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cv::VideoCapture::read cannot read any frame at all #10378

Closed
teongleng opened this issue Dec 21, 2017 · 7 comments
Closed

cv::VideoCapture::read cannot read any frame at all #10378

teongleng opened this issue Dec 21, 2017 · 7 comments
Labels
invalid question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org

Comments

@teongleng
Copy link

teongleng commented Dec 21, 2017

System information (version)
  • OpenCV => 3.3
  • Operating System / Platform => Windows 10 64 Bit
  • Compiler => Visual Studio 2015
Detailed description
Steps to reproduce

Duplicate of #10377

@teongleng
Copy link
Author

teongleng commented Dec 21, 2017

Just to make it clear:

  1. My PATH (OPENCV_DIR aka C:\opencv\build\x64\vc14) is pointing to the directory %OPENCV_DIR%\bin where opencv_ffmpeg330_64.dll is located.
  2. I have also make a copy of opencv_ffmpeg330_64.dll & place it next to app EXE file.
  3. I have added cap.isOpened() for checking.
    But the result still the same.

Below is my updated code (cap.isOpened() added) & the result it produced:

#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

int main()
{
	cv::namedWindow("Example 3", cv::WINDOW_AUTOSIZE);
	cv::VideoCapture cap;

	cap.open("movie.avi");

	/***** Newly Added *****/
	if (!cap.isOpened())
	{
		std::cout << "Cannot open file...\n";
		return -1;
	}

	cv::Mat frame;
	double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
	double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
	std::cout << "Frame size : " << dWidth << " x " << dHeight << std::endl;
	for (;;)
	{
		cap.read(frame);
		if (frame.empty());
		{
			std::cout << "Frame empty...\n";
			break;
		}
		cv::imshow("Example 3", frame);
	}
	cv::waitKey(0);
    return 0;
}

Result (Same as before):

Frame size : 1920 x 1080
Frame empty...
Press any key to continue . . .

@alalek
Copy link
Member

alalek commented Dec 21, 2017

Try to run with OPENCV_VIDEOCAPTURE_DEBUG=1 environment variable.
Could you try OpenCV's video file (vtest.avi from samples/data) or share your file (or part of this file) somehow?

@teongleng
Copy link
Author

teongleng commented Dec 22, 2017

Hi Sir,

  • Can you please provide me the step to run with OPENCV_VIDEOCAPTURE_DEBUG=1 environment variable?
    Is it go to Control Panel > System > Advanced system settings > Advanced Tab > Environment Variables... > System variables > Path > Edit... > New > Type "OPENCV_VIDEOCAPTURE_DEBUG=1" ?

  • I have uploaded the entire Example 2-3.cpp file, all code is similar to the previous comment.
    Example 2-3.zip

  • If you need the entire project directory you can download from below link:
    https://1drv.ms/f/s!AnE7WULnZpCwjxM9eDEpK0WU90nC

  • Please import below global property sheets into VS IDE for debugging:
    Global Property Sheets.zip

Thank you.

@teongleng
Copy link
Author

Hi Sir,
I've tried to run the program again, this time with OPENCV_VIDEOCAPTURE_DEBUG=1 included inside VS2015 IDE (Project > Properties... > Configuration Properties > Debugging > Environment).

Code:
#include "stdafx.h"
#include
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

int main()
{
cv::namedWindow("Example 3", cv::WINDOW_AUTOSIZE);
cv::VideoCapture cap;

cap.open("vtest.avi");

/***** Newly Added *****/
if (!cap.isOpened())
{
	std::cout << "Cannot open file...\n";
	return -1;
}

cv::Mat frame;
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH);
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
std::cout << "Frame size : " << dWidth << " x " << dHeight << std::endl;
for (;;)
{
	cap.read(frame);
	if (frame.empty());
	{
		std::cout << "Frame empty...\n";
		break;
	}
	cv::imshow("Example 3", frame);
}
cv::waitKey(0);
return 0;

}

Result:
VIDEOIO(cvCreateFileCapture_FFMPEG_proxy (filename)): trying ...
VIDEOIO(cvCreateFileCapture_FFMPEG_proxy (filename)): result=000002A75A90D060 ...
Frame size : 768 x 576
Frame empty...
Press any key to continue . . .

Thank you.

@alalek
Copy link
Member

alalek commented Dec 22, 2017

VIDEOIO(cvCreateFileCapture_FFMPEG_proxy (filename)): result=000002A75A90D060

This mean that ffmpeg backend is selected and opencv_ffmpeg330_64.dll is loaded successfully.

@alalek
Copy link
Member

alalek commented Dec 22, 2017

In next time you should start from using samples from OpenCV.
Your sample has several issues:

  • invalid semicolon (;) in this line:
+std::cout << frame.size() << std::endl; // check real frame size
-if (frame.empty());
+if (frame.empty())
{
  • "cv::waitKey(0);" must be placed right after "cv::imshow()" with some non-zero delay:
cv::imshow("Example 3", frame);
cv::waitKey(30); // ~30 fps

Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org
Only confirmed issues should be reported here. This tracker is for issues and bugs that needs fix in OpenCV.

@teongleng
Copy link
Author

teongleng commented Dec 22, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid question (invalid tracker) ask questions and other "no action" items here: https://forum.opencv.org
Projects
None yet
Development

No branches or pull requests

2 participants