Skip to content

Commit

Permalink
fix: Remove .035ms delay after audio cut
Browse files Browse the repository at this point in the history
  • Loading branch information
richardscull committed Sep 11, 2023
1 parent bb7cd45 commit 7bc438f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"fluent-ffmpeg": "^2.1.2",
"inquirer": "^8.2.6",
"jsoning": "^0.13.23",
"mp3-cutter": "^1.0.6",
"open": "^8.4.0",
"osu-classes": "^3.0.0",
"osu-parsers": "^4.1.3",
Expand Down
55 changes: 44 additions & 11 deletions src/merge/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ import ffmpeg from "fluent-ffmpeg";
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import ffprobe from "@ffprobe-installer/ffprobe";
import { Difficulty } from "../locally/types";
const MP3Cutter = require("mp3-cutter");

export async function MergeAudioAndExport(
firstSong: Difficulty,
secondSong: Difficulty,
timecodes: { endOfFirstHalf: number; startOfSecondHalf: number },
pathToExport: string
) {
await MP3Cutter.cut({
src: `${firstSong.path}/${firstSong.difficulty.general.audioFilename}`,
target: "Temp/FirstPart.mp3",
end: timecodes.endOfFirstHalf / 1000 + 1, // +1s to avoid unsync audio after fading
});
await MP3Cutter.cut({
src: `${secondSong.path}/${secondSong.difficulty.general.audioFilename}`,
target: "Temp/SecondPart.mp3",
start: timecodes.startOfSecondHalf / 1000,
});
await cutMP3Audio(
`${firstSong.path}/${firstSong.difficulty.general.audioFilename}`,
"Temp/FirstPart.mp3",
{
end: timecodes.endOfFirstHalf / 1000 + 1, // +1s to avoid unsync audio after fading
}
);

await cutMP3Audio(
`${secondSong.path}/${secondSong.difficulty.general.audioFilename}`,
"Temp/SecondPart.mp3",
{
start: timecodes.startOfSecondHalf / 1000, // +1s to avoid unsync audio after fading
}
);

ffmpeg.setFfmpegPath(ffmpegInstaller.path);
ffmpeg.setFfprobePath(ffprobe.path);
Expand Down Expand Up @@ -47,3 +51,32 @@ export async function MergeAudioAndExport(
.run();
});
}

function cutMP3Audio(
path: string,
output: string,
time: {
start?: number;
end?: number;
}
) {
return new Promise((resolve, reject) => {
ffmpeg()
.input(path)
.outputOptions(
time.start !== undefined
? `-ss ${time.start || 0}`
: `-t ${time.end || 0}`
)
.output(output)
.on("error", function (err) {
console.log("An error occurred during cutting: " + err.message);
reject(err);
})
.on("end", function () {
resolve(undefined);
})

.run();
});
}
4 changes: 3 additions & 1 deletion src/merge/propmpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Jsoning from "jsoning";
import getLocalizationJson from "../lib/localization/main";
import inquirer from "inquirer";
import open from "open";
import fs from "fs";

export async function openOsz(config: Jsoning, oszPath: string) {
const localization = await getLocalizationJson(config);
Expand All @@ -17,7 +18,8 @@ export async function openOsz(config: Jsoning, oszPath: string) {
])
.then((options) => {
if (options.backToMenu) {
open(oszPath);
fs.copyFileSync(oszPath, `${oszPath}-exp.osz`);
open(`${oszPath}-exp.osz`);
}
});
}

0 comments on commit 7bc438f

Please sign in to comment.