Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpacifico authored Aug 7, 2024
1 parent 80e9d76 commit 214bde2
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 110 deletions.
218 changes: 110 additions & 108 deletions src/application/VideoPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/library/FFMPEG.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions src/library/FFPROBE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,6 +153,7 @@ public static void Data(final String file) {
&& extension.toLowerCase().equals(".pdf") == false)
{
previousImageWidth = imageWidth;
previousImageHeight = imageHeight;
}

timecode1 = "";
Expand Down
5 changes: 4 additions & 1 deletion src/settings/Overlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 214bde2

Please sign in to comment.