From 801c650e59764045a8c1495cc30e0226039d5dcb Mon Sep 17 00:00:00 2001 From: Dominic Matarese Date: Mon, 12 Jul 2021 16:12:43 +0000 Subject: required first commit --- src/getFrames.java | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 src/getFrames.java (limited to 'src/getFrames.java') diff --git a/src/getFrames.java b/src/getFrames.java new file mode 100755 index 0000000..e17f348 --- /dev/null +++ b/src/getFrames.java @@ -0,0 +1,91 @@ +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; + +import org.jcodec.api.FrameGrab; +import org.jcodec.api.JCodecException; +import org.jcodec.api.awt.AWTSequenceEncoder; +import org.jcodec.common.io.*; +import org.jcodec.common.io.NIOUtils; +import org.jcodec.common.io.SeekableByteChannel; +import org.jcodec.common.model.Picture; +import org.jcodec.common.model.Rational; +import org.jcodec.common.model.*; +import org.jcodec.scale.*; +import org.jcodec.scale.AWTUtil; + + +public class getFrames { + + //Splits the video into separate frames and dumps them in the frame-dump folder. + //Function is currently unused in the program + public static void splitVideo(File video) throws IOException, JCodecException{ + double startSec = 0; + int frameCount = 1292; + + FrameGrab grab = FrameGrab.createFrameGrab(NIOUtils.readableChannel(video)); + grab.seekToSecondPrecise(startSec); + + for (int i = 0; i < frameCount; i++) { + Picture picture = grab.getNativeFrame(); + System.out.println(picture.getWidth() + "x" + picture.getHeight() + " " + picture.getColor()); + + BufferedImage bufferedImage = AWTUtil.toBufferedImage(picture); + ImageIO.write(bufferedImage, "png", new File("frame-dump/frame"+i+".png")); + } + } + public static String encoded; + public static void editVideo(File video) throws IOException, JCodecException{ + + SeekableByteChannel sbc = NIOUtils.readableChannel(video); + + FrameGrab grab = FrameGrab.createFrameGrab(sbc); + + + + AWTSequenceEncoder encoder = AWTSequenceEncoder.create30Fps(new File("output.mp4")); + + + + Picture picture; + int i = 0; + while ((picture = grab.getNativeFrame()) != null) + + { + + BufferedImage image = AWTUtil.toBufferedImage(picture); + + + int width = image.getWidth(); + int height = image.getHeight(); + + for(int y = 0; y < height; y++){ + for(int x = 0; x < width; x++){ + + int p = image.getRGB(x,y); + int a = (p>>24)&0xff; + int r = (p>>16)&0xff; + int g = (p>>8)&0xff; + int b = p&0xff; + int avg = (r+g+b)/3; + + //apply a different alpha value to each pixel + p = (a<<20) | (avg<<16) | (avg<<8) | avg; + image.setRGB(x, y, p); + + } + } + + encoder.encodeImage(image); + i++; + encoded = "Encoded frame "+i; + System.out.println("Encoded frame "+i); + + } + + encoder.finish(); + } + + +} -- cgit v1.2.1