I tried to do it using OpenCV:
std::string input_name = "<path to file>";
cv::VideoCapture cap(input_name);
if(!cap.isOpened()) printf("Invalid video\n");
However, when I try passing a .txt file, VideoCapture reads it successfully for unknown reasons. When I try to find the number of frames in the video,
if(cap.get(cv::CV_CAP_PROP_FRAME_COUNT) == 0) printf("Invalid video\n");
I get a different number of frames each time I execute. I also tried finding the width and height of a frame in the file,
cv::Mat Frame;
if(!cap.read(Frame)) printf("Cannot read frame\n");
else
{
printf("Frame width is %d\n", Frame.cols);
printf("Frame height is %d\n", Frame.rows);
}
their values are 640 and 400 respectively. Why is this happening? Is there a way to check if a given file is a valid video file preferably using OpenCV?