From 214bde29f9675f9eff9e96ba86b754fd97518372 Mon Sep 17 00:00:00 2001 From: Pacifico Paul <46673657+paulpacifico@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:13:06 +0400 Subject: [PATCH] Add files via upload --- src/application/VideoPlayer.java | 218 ++++++++++++++++--------------- src/library/FFMPEG.java | 2 +- src/library/FFPROBE.java | 2 + src/settings/Overlay.java | 5 +- 4 files changed, 117 insertions(+), 110 deletions(-) diff --git a/src/application/VideoPlayer.java b/src/application/VideoPlayer.java index 0e6d6aa6..900aec12 100644 --- a/src/application/VideoPlayer.java +++ b/src/application/VideoPlayer.java @@ -1353,8 +1353,8 @@ public void run() } //Watermark - if (Shutter.caseAddWatermark.isSelected() && FFPROBE.previousImageWidth != Shutter.logoWidth) - { + if (Shutter.caseAddWatermark.isSelected() && (FFPROBE.imageWidth != FFPROBE.previousImageWidth || FFPROBE.imageHeight != FFPROBE.previousImageHeight)) + { Shutter.textWatermarkSize.setText(String.valueOf(Math.round(Integer.parseInt(Shutter.textWatermarkSize.getText()) * scale))); } @@ -2146,7 +2146,7 @@ public void run() { waveformIcon.setIcon(resizedWaveform); waveformIcon.repaint(); - if ((RenderQueue.frame != null && RenderQueue.frame.isVisible() && FFMPEG.isRunning) || isPiping) + if ((RenderQueue.frame != null && RenderQueue.frame.isVisible() && FFMPEG.isRunning) || isPiping || videoPath == null) { waveformIcon.setVisible(false); } @@ -4601,124 +4601,126 @@ else if (line.isEmpty()) } public static boolean loadWatermark(int size) { - - try { - - if (Shutter.logoPNG == null) - { - int previousImageWidth = FFPROBE.previousImageWidth; - - //IMPORTANT - if (FFPROBE.isRunning) - { - do { - try { - Thread.sleep(100); - } catch (InterruptedException e) {} - } - while (FFPROBE.isRunning); + + if (FFPROBE.imageWidth != FFPROBE.previousImageWidth || FFPROBE.imageHeight != FFPROBE.previousImageHeight) + { + try { + + if (Shutter.logoPNG == null) + { + int previousImageWidth = FFPROBE.previousImageWidth; + + //IMPORTANT + if (FFPROBE.isRunning) + { + do { + try { + Thread.sleep(100); + } catch (InterruptedException e) {} + } + while (FFPROBE.isRunning); + } + + //Keep media size + FFPROBE.previousImageWidth = previousImageWidth; + + if (Shutter.overlayDeviceIsRunning) + { + RecordInputDevice.setOverlayDevice(); + } + else + { + FFPROBE.Data(Shutter.logoFile); + do { + try { + Thread.sleep(10); + } catch (InterruptedException e) {} + } while (FFPROBE.isRunning); + } + + Shutter.logoWidth = FFPROBE.imageWidth; + Shutter.logoHeight = FFPROBE.imageHeight; + + //IMPORTANT keeps original source file data + FunctionUtils.analyze(new File(videoPath), false); } + + int logoFinalSizeWidth = (int) Math.floor((float) Shutter.logoWidth / Shutter.playerRatio); + int logoFinalSizeHeight = (int) Math.floor((float) Shutter.logoHeight / Shutter.playerRatio); + + //Adapt to size + logoFinalSizeWidth = (int) Math.floor((float) logoFinalSizeWidth * ((double) size / 100)); + logoFinalSizeHeight = (int) Math.floor((float) logoFinalSizeHeight * ((double) size / 100)); - //Keep media size - FFPROBE.previousImageWidth = previousImageWidth; + if (logoFinalSizeWidth < 1) + logoFinalSizeWidth = 1; - if (Shutter.overlayDeviceIsRunning) - { - RecordInputDevice.setOverlayDevice(); - } - else + if (logoFinalSizeHeight < 1) + logoFinalSizeHeight = 1; + + //Preserve location + int newPosX = (int) Math.floor((Shutter.logo.getWidth() - logoFinalSizeWidth) / 2); + int newPosY = (int) Math.floor((Shutter.logo.getHeight() - logoFinalSizeHeight) / 2); + + if (Shutter.logoPNG == null) { - FFPROBE.Data(Shutter.logoFile); + if (Shutter.overlayDeviceIsRunning) + { + FFMPEG.run(" -v quiet -hide_banner " + RecordInputDevice.setOverlayDevice() + " -frames:v 1 -an -c:v png -pix_fmt bgra -sws_flags fast_bilinear -f image2pipe -"); + } + else if (Shutter.logoPNG == null) + { + FFMPEG.run(" -v quiet -hide_banner -i " + '"' + Shutter.logoFile + '"' + " -frames:v 1 -an -c:v png -pix_fmt bgra -sws_flags fast_bilinear -f image2pipe -"); + } + do { - try { - Thread.sleep(10); - } catch (InterruptedException e) {} - } while (FFPROBE.isRunning); + Thread.sleep(10); + } while (FFMPEG.process.isAlive() == false); + + InputStream videoInput = FFMPEG.process.getInputStream(); + InputStream is = new BufferedInputStream(videoInput); + fullSizeWatermark = ImageIO.read(is); } - Shutter.logoWidth = FFPROBE.imageWidth; - Shutter.logoHeight = FFPROBE.imageHeight; + Shutter.logoPNG = new ImageIcon(fullSizeWatermark).getImage().getScaledInstance(logoFinalSizeWidth, logoFinalSizeHeight, Image.SCALE_AREA_AVERAGING); + + if (Shutter.logo.getWidth() == 0) + { + Shutter.logo.setLocation((int) Math.floor(player.getWidth() / 2 - logoFinalSizeWidth / 2), (int) Math.floor(player.getHeight() / 2 - logoFinalSizeHeight / 2)); + } + else + Shutter.logo.setLocation(Shutter.logo.getLocation().x + newPosX, Shutter.logo.getLocation().y + newPosY); + + Shutter.logo.setSize(logoFinalSizeWidth, logoFinalSizeHeight); + + Shutter.textWatermarkPosX.setText(String.valueOf(Integer.valueOf((int) Math.floor(Shutter.logo.getLocation().x * Shutter.playerRatio) ) ) ); + Shutter.textWatermarkPosY.setText(String.valueOf(Integer.valueOf((int) Math.floor(Shutter.logo.getLocation().y * Shutter.playerRatio) ) ) ); - //IMPORTANT keeps original source file data - FunctionUtils.analyze(new File(videoPath), false); + //Saving location + Shutter.logoLocX = Shutter.logo.getLocation().x; + Shutter.logoLocY = Shutter.logo.getLocation().y; + Shutter.logo.repaint(); } - - int logoFinalSizeWidth = (int) Math.floor((float) Shutter.logoWidth / Shutter.playerRatio); - int logoFinalSizeHeight = (int) Math.floor((float) Shutter.logoHeight / Shutter.playerRatio); - - //Adapt to size - logoFinalSizeWidth = (int) Math.floor((float) logoFinalSizeWidth * ((double) size / 100)); - logoFinalSizeHeight = (int) Math.floor((float) logoFinalSizeHeight * ((double) size / 100)); - - if (logoFinalSizeWidth < 1) - logoFinalSizeWidth = 1; - - if (logoFinalSizeHeight < 1) - logoFinalSizeHeight = 1; - - //Preserve location - int newPosX = (int) Math.floor((Shutter.logo.getWidth() - logoFinalSizeWidth) / 2); - int newPosY = (int) Math.floor((Shutter.logo.getHeight() - logoFinalSizeHeight) / 2); - - if (Shutter.logoPNG == null) + catch (Exception e) { - if (Shutter.overlayDeviceIsRunning) - { - FFMPEG.run(" -v quiet -hide_banner " + RecordInputDevice.setOverlayDevice() + " -frames:v 1 -an -c:v png -pix_fmt bgra -sws_flags fast_bilinear -f image2pipe -"); - } - else if (Shutter.logoPNG == null) + e.printStackTrace(); + JOptionPane.showMessageDialog(Shutter.frame, Shutter.language.getProperty("cantLoadFile"), Shutter.language.getProperty("error"), JOptionPane.ERROR_MESSAGE); + } + finally { + + if (Shutter.watermarkPreset != null) { - FFMPEG.run(" -v quiet -hide_banner -i " + '"' + Shutter.logoFile + '"' + " -frames:v 1 -an -c:v png -pix_fmt bgra -sws_flags fast_bilinear -f image2pipe -"); + watermarkPositions(Shutter.watermarkPreset); } - do { - Thread.sleep(10); - } while (FFMPEG.process.isAlive() == false); + Shutter.btnStart.setEnabled(true); - InputStream videoInput = FFMPEG.process.getInputStream(); - InputStream is = new BufferedInputStream(videoInput); - fullSizeWatermark = ImageIO.read(is); - } - - Shutter.logoPNG = new ImageIcon(fullSizeWatermark).getImage().getScaledInstance(logoFinalSizeWidth, logoFinalSizeHeight, Image.SCALE_AREA_AVERAGING); - - if (Shutter.logo.getWidth() == 0) - { - Shutter.logo.setLocation((int) Math.floor(player.getWidth() / 2 - logoFinalSizeWidth / 2), (int) Math.floor(player.getHeight() / 2 - logoFinalSizeHeight / 2)); - } - else - Shutter.logo.setLocation(Shutter.logo.getLocation().x + newPosX, Shutter.logo.getLocation().y + newPosY); - - Shutter.logo.setSize(logoFinalSizeWidth, logoFinalSizeHeight); - - Shutter.textWatermarkPosX.setText(String.valueOf(Integer.valueOf((int) Math.floor(Shutter.logo.getLocation().x * Shutter.playerRatio) ) ) ); - Shutter.textWatermarkPosY.setText(String.valueOf(Integer.valueOf((int) Math.floor(Shutter.logo.getLocation().y * Shutter.playerRatio) ) ) ); - - //Saving location - Shutter.logoLocX = Shutter.logo.getLocation().x; - Shutter.logoLocY = Shutter.logo.getLocation().y; - Shutter.logo.repaint(); + if (RenderQueue.frame != null && RenderQueue.frame.isVisible()) + Shutter.btnStart.setText(Shutter.language.getProperty("btnAddToRender")); + else + Shutter.btnStart.setText(Shutter.language.getProperty("btnStartFunction")); + } } - catch (Exception e) - { - e.printStackTrace(); - JOptionPane.showMessageDialog(Shutter.frame, Shutter.language.getProperty("cantLoadFile"), Shutter.language.getProperty("error"), JOptionPane.ERROR_MESSAGE); - } - finally { - - if (Shutter.watermarkPreset != null) - { - watermarkPositions(Shutter.watermarkPreset); - } - - Shutter.btnStart.setEnabled(true); - - if (RenderQueue.frame != null && RenderQueue.frame.isVisible()) - Shutter.btnStart.setText(Shutter.language.getProperty("btnAddToRender")); - else - Shutter.btnStart.setText(Shutter.language.getProperty("btnStartFunction")); - } - return true; } @@ -5475,7 +5477,7 @@ else if (FFPROBE.totalLength > 40 && Shutter.caseEnableSequence.isSelected() == public static void resizeAll() { if (Shutter.frame.getWidth() > 332 && Shutter.doNotLoadImage == false) - { + { //Clear the buffer if (bufferedFrames.size() > 0) { @@ -5669,7 +5671,7 @@ else if (fullscreenPlayer) if (Shutter.caseAddWatermark.isSelected() && Shutter.btnStart.getText().equals(Shutter.language.getProperty("btnPauseFunction")) == false && Shutter.btnStart.getText().equals(Shutter.language.getProperty("btnStopRecording")) == false) - { + { loadWatermark(Integer.parseInt(Shutter.textWatermarkSize.getText())); if (Shutter.watermarkPreset != null) { diff --git a/src/library/FFMPEG.java b/src/library/FFMPEG.java index 0503ec3b..c52e3caa 100644 --- a/src/library/FFMPEG.java +++ b/src/library/FFMPEG.java @@ -179,7 +179,7 @@ else if (caseChangeFolder2.isSelected()) lblCurrentEncoding.setText(Shutter.language.getProperty("lblEncodageEnCours")); - Console.consoleFFMPEG.append(System.lineSeparator()); + Console.consoleFFMPEG.append(System.lineSeparator()); } else { diff --git a/src/library/FFPROBE.java b/src/library/FFPROBE.java index fca2ed1a..34bb05b9 100644 --- a/src/library/FFPROBE.java +++ b/src/library/FFPROBE.java @@ -66,6 +66,7 @@ public class FFPROBE extends Shutter { public static int imageDepth = 8; public static String imageResolution; public static int previousImageWidth; +public static int previousImageHeight; public static int imageWidth; public static int imageHeight; public static float imageRatio = 1.777777f; @@ -152,6 +153,7 @@ public static void Data(final String file) { && extension.toLowerCase().equals(".pdf") == false) { previousImageWidth = imageWidth; + previousImageHeight = imageHeight; } timecode1 = ""; diff --git a/src/settings/Overlay.java b/src/settings/Overlay.java index d1d6eaef..9b98d2c3 100644 --- a/src/settings/Overlay.java +++ b/src/settings/Overlay.java @@ -617,7 +617,10 @@ public static String setWatermark(String filterComplex) { VideoPlayer.resizeAll(); VideoPlayer.loadWatermark(Integer.parseInt(Shutter.textWatermarkSize.getText())); - Shutter.logo.setLocation((int) Math.floor(Integer.valueOf(Shutter.textWatermarkPosX.getText()) / Shutter.playerRatio), (int) Math.floor(Integer.valueOf(Shutter.textWatermarkPosY.getText()) / Shutter.playerRatio)); + if (Shutter.watermarkPreset != null) + { + Shutter.logo.setLocation((int) Math.floor(Integer.valueOf(Shutter.textWatermarkPosX.getText()) / Shutter.playerRatio), (int) Math.floor(Integer.valueOf(Shutter.textWatermarkPosY.getText()) / Shutter.playerRatio)); + } } float imageRatio = 1.0f;