-
-
Save BasharHajhamad-exalt/27f02020cb9e75582eb49c13cf1d879b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void startExtracting() { | |
try (FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoPath)) { | |
OpenCVFrameConverter.ToOrgOpenCvCoreMat converter = new OpenCVFrameConverter.ToOrgOpenCvCoreMat(); | |
frameGrabber.start(); | |
for (Integer index : indexList) { | |
String frameName = filename + "_Frame" + String.format("%04d", index + 1) + "." + imageType; | |
if (!stopExecution && FrameMixerCore.isFrameIncluded(framesRanges, index)) { | |
if (replaceAll) { | |
// skip check for replace all | |
} else if (skipAll || !FramesProcessor.checkFileIfExistAndDecide(imagesPath + File.separator + frameName)) { | |
FramesProcessor.extractedFrames++; | |
continue; | |
} | |
frameGrabber.setVideoFrameNumber(index); | |
Frame frame = frameGrabber.grabImage(); | |
BufferedImage bufferedImage = Mat2BufferedImage(converter.convert(frame)); | |
String rotation = frameGrabber.getVideoMetadata("rotate"); | |
if (rotation != null) | |
bufferedImage = FrameMixerCore.rotateImageByDegrees(bufferedImage, Integer.parseInt(rotation)); | |
imagesNames.add(frameName); | |
if (bufferedImage != null) { | |
bufferedImage = SeedUtils.removeBackground(bufferedImage, seed); | |
bufferedImage = FrameMixerCore.processSeedImage(bufferedImage, channelWidth, channelHeight, scaling, isCrop, alignX, alignY); | |
if (imageType.equals("pdf")) { | |
PDFUtils.writePDF(PDFUtils.convertBufferedImageToPdf(bufferedImage, channelWidth, channelHeight, true, videoPath), new File(imagesPath + File.separator + frameName)); | |
} else { | |
ImageUtils.writeImage(bufferedImage, imageType, new File(imagesPath + File.separator + frameName), channelWidth, channelHeight, false, true, videoPath, null); | |
} | |
extractedFrames++; | |
} | |
} | |
} | |
frameGrabber.stop(); | |
} catch (Exception e) { | |
logger.error(e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment