Commit 568515e8 authored by Nafis A Abeer's avatar Nafis A Abeer
Browse files

Merge branch 'rgbd_2' into 'master'

Rgbd 2

See merge request ec504/ec504_projects/group8!30
parents d3a68c7d e7e17203
Loading
Loading
Loading
Loading
(6 KiB)

File changed.

No diff preview for this file type.

+3 −1
Original line number Diff line number Diff line
@@ -12,8 +12,9 @@
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <exec.mainClass>top.BackendJava</exec.mainClass>
        <!-- <exec.mainClass>top.BackendJava</exec.mainClass> -->
        <!-- <exec.mainClass>yolo.YOLODetector</exec.mainClass> -->
        <exec.mainClass>vid2frames.Vid2Frames</exec.mainClass>
    </properties>

    <build>
@@ -111,5 +112,6 @@
            </exclusions>
        </dependency>


    </dependencies>
</project>
+2 KiB (10 KiB)

File changed.

No diff preview for this file type.

+6 KiB

File added.

No diff preview for this file type.

+53 −0
Original line number Diff line number Diff line
import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Vid2Frames {
    public static void main(String[] args) {
        String videoFilePath = "src/main/java/vid2frames/input_video.mov";
        String outputDirPath = "src/main/java/vid2frames/frames";

        File outputDir = new File(outputDirPath);
        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }

        extractFrames(videoFilePath, outputDirPath);
    }

    private static void extractFrames(String videoFilePath, String outputDirPath) {
        try (FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoFilePath)) {
            frameGrabber.start();

            Java2DFrameConverter converter = new Java2DFrameConverter();
            Frame frame;
            int frameNumber = 0;

            // Frame rate of the video file
            double frameRate = frameGrabber.getFrameRate();
            // Interval to capture the frame (every 0.2 seconds for 5 frames per second)
            int frameInterval = (int) Math.round(frameRate / 5);

            while ((frame = frameGrabber.grabFrame()) != null) {
                if (frame.image != null) {
                    if (frameNumber % frameInterval == 0) {
                        BufferedImage bi = converter.convert(frame);
                        String path = String.format("%s/frame_%d.png", outputDirPath, frameNumber);
                        ImageIO.write(bi, "png", new File(path));
                        System.out.println("Saved: " + path);
                    }
                    frameNumber++;
                }
            }

            frameGrabber.stop();
        } catch (IOException | FFmpegFrameGrabber.Exception e) {
            e.printStackTrace();
        }
    }
}
Loading