8000 OpenCV VideoCapture::read reads an empty matrix mid video · Issue #15352 · opencv/opencv · GitHub
[go: up one dir, main page]

Skip to content
OpenCV VideoCapture::read reads an empty matrix mid video #15352
@Sharan123

Description

@Sharan123
System information
  • OpenCV => 4.1
  • Operating System / Platform => x86_64 GNU/Linux (Debian-based)
  • Compiler => g++ (8.3.0)
Detailed description

OpenCV VideoCapture::read fails to read certain video file formats until the end.
Three test videos were tested (videos provided below):
rottest.avi (fps: 24; total frames: 337, reads 107 frames - 108th was unsuccessful)
rottest.mp4 (fps: 24; total frames: 337, reads 337 frames - 338th was unsuccessful; as expected)
rottest.webm (fps: 30; total frames: 423, reads 107 frames - 108th was unsuccessful)

All videos have the same content, only underwent format conversion.
The expected behavior is for rottest.webm to successfully read 423 frames and fail on 424th,
while for rottest.avi is should read 337 frames successfully and fail on the 338th frame.

To be more specific, in all instances I have checked manually and the call cap.read(curr_img); returns false on the unsuccessful frame numbers given above.

I did not try to visualize the images using cv::imshow but can do that as well if someone considers it necessary.

Steps to reproduce

testvideoin.cpp

#include <opencv2/videoio.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <string>

int main(int argc, char const *argv[])
{
	if (argc<2)
		return 0;
	std::string path(argv[1]);
	cv::VideoCapture cap(path);
	cv::Mat curr_img;
	unsigned frame_no=1;
	bool success=false;
	std::cout << "Video total frame number: " << static_cast<int>(cap.get(cv::CAP_PROP_FRAME_COUNT)) << std::endl;

	success=cap.read(curr_img);
	while (!curr_img.empty())
	{
		std::cout << "Frame no: " << frame_no <<"; SUCCESS: "<< success << std::endl;
		success=cap.read(curr_img);
		if (!success)
			curr_img=cv::Mat();
		frame_no++;
	}

	std::cout <<"Frame no: " << frame_no << "; Image empty: " << curr_img.empty() << std::endl;
	return 0;
}

Compilation:
g++ -std=c++14 -Wall -Wextra -g -O0 -I/usr/local/include/opencv4 -L/usr/local/lib -o testvideoin -lopencv_core -lopencv_videoio -lopencv_imgproc -lopencv_imgcodecs testvideoin.cpp

Test set: https://drive.google.com/open?id=1FdyrYWi7qNGB3KSaELLQDZ2ugAnxp2OL
(rottest.webm, rottest.avi, rottest.mp4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCbugcategory: videoioconfirmedThere is stable reproducer / investigation completefutureThis issue can't be fixed during restrictions of the compatibility requirements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0