Skip to content

Commit

Permalink
v2.2.0 update
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezos committed Mar 13, 2022
1 parent 455d4a9 commit db432ae
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 2,077 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ffmpeg2pass-0.log
ffmpeg2pass-0.log.mbtree
video-compressor-build*
package-lock.json
Bepto*
Bepto*
package-lock.json
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
## Bepto Video Compressor

A beautiful, simple video compressor.
An elegant, simple video compressor.

### Features

- Compress multiple videos in a queue system.
- Compress videos to any file size.
- Remove audio from videos.
- H.265 codec option.
- Set a minimum video bitrate.

### Preview

![Preview](https://github.com/slugnasty/video-compressor/blob/main/preview.gif)

### Love this app?

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/slugnasty)
![Preview](https://github.com/cheezos/video-compressor/blob/main/preview.png)
12 changes: 12 additions & 0 deletions dist/css/bootstrap.min.css

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ let currentProgress = 1;
let totalProgress = 1;
let cmd = null;
electron_1.app.on("ready", () => {
electron_1.app.setAppUserModelId("Bepto Video Compressor");
exports.mainWindow = new electron_1.BrowserWindow({
width: 350,
height: 415,
width: 310,
height: 390,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
Expand All @@ -41,31 +42,31 @@ electron_1.app.on("window-all-closed", () => {
electron_1.ipcMain.on("droppedVideos", (event, vids) => {
videoData = (0, utils_1.getVideoData)(vids);
});
electron_1.ipcMain.on("requestCompress", (event, removeAudio, h265, minBitrate, targetFileSize) => {
electron_1.ipcMain.on("requestCompress", (event, removeAudio, h265, targetFileSize) => {
currentIndex = 0;
currentProgress = 0;
compressQueue(exports.mainWindow, videoData, removeAudio, h265, minBitrate, targetFileSize)
compressQueue(exports.mainWindow, videoData, removeAudio, h265, targetFileSize)
.then(() => {
event.reply("compressionComplete");
new electron_1.Notification({ title: "Compression complete", body: "Your new videos are located in the same directory" }).show();
new electron_1.Notification({ title: "Compression complete!" }).show();
})
.catch((err) => {
event.reply("compressionError", err);
new electron_1.Notification({ title: "Error", body: "There was an error during compression" }).show();
new electron_1.Notification({ title: "Aborted!" }).show();
});
});
electron_1.ipcMain.on("requestAbort", (event) => {
killFFmpeg();
});
function compressQueue(window, videoData, removeAudio, h265, minBitrate, targetFileSize) {
function compressQueue(window, videoData, removeAudio, h265, targetFileSize) {
return new Promise((resolve, reject) => {
window.webContents.send("compressionStart");
totalProgress = videoData.length * 2;
const compress = () => {
console.log(`Compressing ${currentIndex + 1}/${videoData.length}...`);
(0, utils_1.getVideoDuration)(videoData[currentIndex].base)
.then((duration) => {
const bitrate = (0, utils_1.getCalculatedVideoBitrate)(duration, minBitrate, targetFileSize);
const bitrate = (0, utils_1.getCalculatedVideoBitrate)(duration, targetFileSize);
compressVideo(window, videoData[currentIndex], bitrate, removeAudio, h265)
.then(() => {
if (currentIndex + 1 < videoData.length) {
Expand All @@ -91,16 +92,16 @@ exports.compressQueue = compressQueue;
function compressVideo(window, videoData, bitrate, removeAudio, h265) {
return new Promise((resolve, reject) => {
cmd = (0, fluent_ffmpeg_1.default)();
let audioArg = "-b:a 128k";
let audio = "-b:a 128k";
let codec = "-c:v libx264";
if (removeAudio) {
audioArg = "-an";
audio = "-an";
}
if (h265) {
codec = "-c:v libx265";
}
let pass1 = [`-y`, codec, `-b:v ${bitrate}k`, `-pass 1`, `-an`, `-f mp4`];
let pass2 = [codec, `-b:v ${bitrate}k`, `-pass 2`, `-c:a aac`, audioArg];
let pass1 = [`-y`, codec, `-b:v ${bitrate}k`, `-r 24`, `-vf scale=-1:540`, `-pass 1`, `-an`, `-f mp4`];
let pass2 = [codec, `-b:v ${bitrate}k`, `-r 24`, `-vf scale=-1:540`, `-pass 2`, `-c:a aac`, audio];
cmd.setFfmpegPath((0, utils_1.getFFmpeg)()[0]);
cmd.setFfprobePath((0, utils_1.getFFmpeg)()[1]);
cmd.input(videoData.base);
Expand All @@ -118,6 +119,7 @@ function compressVideo(window, videoData, bitrate, removeAudio, h265) {
cmd.on("end", () => {
currentProgress += 1;
window.webContents.send("progressUpdate", currentProgress, totalProgress);
electron_1.shell.openPath(videoData.path);
console.log(`Compressed ${videoData.name}`);
resolve(true);
});
Expand Down
38 changes: 21 additions & 17 deletions dist/renderer/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,44 @@ const dropZone = document.getElementById("drop-zone");
const progressBar = document.getElementById("progress-bar");
const checkRemoveAudio = document.getElementById("check-remove-audio");
const checkH265 = document.getElementById("check-h265");
const inputMinBitrate = document.getElementById("input-min-bitrate");
const inputFileSize = document.getElementById("input-file-size");
let videoPaths = [];
let compressing = false;
btnCompress?.addEventListener("click", () => {
const removeAudio = checkRemoveAudio.checked;
const h265 = checkH265.checked;
const minBitrate = parseFloat(inputMinBitrate.value) || 100;
const fileSize = parseFloat(inputFileSize.value) || 8.0;
btnCompress.disabled = true;
electron_1.ipcRenderer.send("requestCompress", removeAudio, h265, minBitrate, fileSize);
electron_1.ipcRenderer.send("requestCompress", removeAudio, h265, fileSize);
});
btnAbort?.addEventListener("click", () => {
electron_1.ipcRenderer.send("requestAbort");
});
btnSupport?.addEventListener("click", () => {
electron_1.shell.openExternal("https://ko-fi.com/slugnasty");
});
btnGithub?.addEventListener("click", () => {
electron_1.shell.openExternal("https://github.com/slugnasty/video-compressor");
electron_1.shell.openExternal("https://github.com/cheezos/video-compressor");
});
dropZone?.addEventListener("dragover", (event) => {
if (compressing)
return;
event.stopPropagation();
event.preventDefault();
});
dropZone?.addEventListener("drop", (event) => {
if (compressing)
return;
event.stopPropagation();
event.preventDefault();
videoPaths = [];
const files = event.dataTransfer?.files;
for (const file of files) {
videoPaths.push(file.path);
}
lblStatus.innerText = `${videoPaths.length} video(s) ready to compress`;
lblStatusSmall.innerText = "Click 'Compress' to begin";
let text = `${videoPaths.length} videos ready!`;
if (videoPaths.length < 2) {
text = `1 video ready!`;
}
lblStatus.innerText = text;
lblStatusSmall.innerText = "Click 'Compress' to begin.";
btnCompress.disabled = false;
electron_1.ipcRenderer.send("droppedVideos", videoPaths);
});
Expand All @@ -62,34 +66,34 @@ electron_1.ipcRenderer.on("progressUpdate", (event, currentValue, totalValue) =>
});
electron_1.ipcRenderer.on("compressionStart", (event) => {
lblStatus.innerText = "Compressing, please wait...";
lblStatusSmall.innerText = "Large videos can take a long time!";
lblStatusSmall.innerText = "Large videos can take a long time.";
btnCompress.disabled = true;
btnAbort.disabled = false;
checkRemoveAudio.disabled = true;
checkH265.disabled = true;
inputMinBitrate.disabled = true;
inputFileSize.disabled = true;
progressBar.style.width = "0%";
compressing = true;
});
electron_1.ipcRenderer.on("compressionComplete", (event) => {
lblStatus.innerText = "Compression complete";
lblStatusSmall.innerText = "Your new videos are located in the same directory";
lblStatus.innerText = "Compression complete!";
lblStatusSmall.innerText = "Your compressed videos are now available.";
btnCompress.disabled = true;
btnAbort.disabled = true;
checkRemoveAudio.disabled = false;
checkH265.disabled = false;
inputMinBitrate.disabled = false;
inputFileSize.disabled = false;
progressBar.style.width = "100%";
compressing = false;
});
electron_1.ipcRenderer.on("compressionError", (event, err) => {
lblStatus.innerText = "Aborted compression";
lblStatusSmall.innerText = "Drop your videos here and try again";
lblStatus.innerText = "Compression aborted!";
lblStatusSmall.innerText = "Drop your videos here and try again.";
btnCompress.disabled = true;
btnAbort.disabled = true;
checkRemoveAudio.disabled = false;
checkH265.disabled = false;
inputMinBitrate.disabled = false;
inputFileSize.disabled = false;
progressBar.style.width = "100%";
compressing = false;
});
4 changes: 2 additions & 2 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function getVideoDuration(videoPath) {
});
}
exports.getVideoDuration = getVideoDuration;
function getCalculatedVideoBitrate(duration, minBitrate, targetFileSize) {
const magic = Math.max((targetFileSize * 8192.0) / (1.048576 * duration) - 128, minBitrate);
function getCalculatedVideoBitrate(duration, targetFileSize) {
const magic = Math.max((targetFileSize * 8192.0) / (1.048576 * duration) - 128, 100);
console.log(`Calculated bitrate: ${magic}`);
return magic;
}
Expand Down
14 changes: 5 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://bootswatch.com/5/darkly/bootstrap.min.css" />
<link rel="stylesheet" href="dist/css/bootstrap.min.css" />
<title>Bepto Video Compressor</title>
</head>

Expand All @@ -26,8 +26,8 @@
background: rgb(25, 25, 25);
"
>
<h5 id="lbl-status" class="text-muted">Drop your videos here</h5>
<small id="lbl-status-small" class="text-muted">Then click 'Compress' when ready</small>
<h5 id="lbl-status" class="text-muted">Drop your videos here.</h5>
<small id="lbl-status-small" class="text-muted"></small>
</div>

<!-- Progress -->
Expand Down Expand Up @@ -61,13 +61,9 @@ <h5 id="lbl-status" class="text-muted">Drop your videos here</h5>
<label style="margin-right: 10px; text-align: right">H.265 Codec</label>
<input style="margin-left: 10px" id="check-h265" class="form-check-input" type="checkbox" />

<!-- Minimum Bitrate -->
<label style="margin-right: 10px; text-align: right">Min Bitrate (Kbps)</label>
<input style="margin-left: 10px; width: 70px; height: 25px; border-radius: 5px" id="input-min-bitrate" type="text" placeholder="100.0" />

<!-- File Size -->
<label style="margin-right: 10px; text-align: right">File Size (MB)</label>
<input style="margin-left: 10px; width: 70px; height: 25px; border-radius: 5px" id="input-file-size" type="text" placeholder="8.0" />
<input style="margin-left: 8px; width: 50px; height: 25px; border-radius: 5px" id="input-file-size" type="text" placeholder="8.0" />
</div>

<!-- Footer -->
Expand All @@ -79,7 +75,7 @@ <h5 id="lbl-status" class="text-muted">Drop your videos here</h5>
class="text-muted"
style="background: none; border: none; margin-left: 25px; margin-right: 25px; padding: 0; cursor: pointer"
>
<small class="text-muted">v2.1.1 - Created by slugnasty</small>
<small class="text-muted">v2.2.0</small>
</button>
</div>
<script>
Expand Down
Loading

0 comments on commit db432ae

Please sign in to comment.