Home > Back-end >  Cannot open a video with OpenCV VideoCapture on HDFS (Hadoop) | Java
Cannot open a video with OpenCV VideoCapture on HDFS (Hadoop) | Java

Time:01-12

I'm trying to open a video file with OpenCv VideoCapture that is stored on HDFS. This is a case using Hadoop RecordReader and I can find the file but doesn't work in VideoCapture. Any help on solving this problem?

MyRecordReader.java

public void initialize(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
        // Set the current frame to 0 and the total number of frames to the length of the video
        currentFrame = 0;
        System.out.printf("%s#initialize(%s, %s)\n", this.toString(), split.toString(), context.getJobName());

        Configuration conf = context.getConfiguration();
        FileSystem fileSystem = FileSystem.get(conf);
        String pathString = "/user/usermr/input/projeto/traffic.mp4";
        Path path = new Path(pathString);
        if (fileSystem.exists(path))
            System.out.println("Found video : "   pathString);

        cap = new VideoCapture(path.toString());
        if ( !cap.isOpened() )
            System.out.println("Cannot open the video file");

        System.out.println("Frames: "   cap.get(Videoio.CAP_PROP_FRAME_COUNT));
}

Output: enter image description here

CodePudding user response:

VideoCapture argument assumes a local filepath, not a remote one, much less one that references a file that is split into blocks and distributed amongst multiple servers (datanodes).

HDFS isn't an ideal system for a "media server" for storing video assets. You will need to download the whole file, as mentioned in the comments before you can process it.

  • Related