Skip to content

Commit

Permalink
Feat: refactor ffmpeg config (#296)
Browse files Browse the repository at this point in the history
* bundle ffmpeg wasm in package

* remove ffmpeg discover & add ffmpeg-static

* fix ffprobe-static version

* fix metadata generate

* fix auto transcribe if pending

* remove console.log
  • Loading branch information
an-lee authored Feb 11, 2024
1 parent bc22a5e commit 57d6efa
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 703 deletions.
16 changes: 16 additions & 0 deletions enjoy/assets/libs/ffmpeg-core.js

Large diffs are not rendered by default.

Binary file added enjoy/assets/libs/ffmpeg-core.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions enjoy/assets/libs/ffmpeg-core.worker.js

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

2 changes: 2 additions & 0 deletions enjoy/forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const NATIVE_MODULES_TO_PACKAGE = [
"sqlite3",
"fluent-ffmpeg",
"electron-squirrel-startup",
"ffmpeg-static",
"@andrkrn/ffprobe-static",
];
const INCLUDE_NESTED_DEPS = true as const;
let nativeModuleDependenciesToPackage: Set<string>;
Expand Down
4 changes: 2 additions & 2 deletions enjoy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@electron-forge/plugin-vite": "^7.2.0",
"@electron-forge/publisher-github": "^7.2.0",
"@tailwindcss/typography": "^0.5.10",
"@types/adm-zip": "^0.5.5",
"@types/autosize": "^4.0.3",
"@types/command-exists": "^1.2.3",
"@types/fluent-ffmpeg": "^2.1.24",
Expand Down Expand Up @@ -64,6 +63,7 @@
"zx": "^7.2.3"
},
"dependencies": {
"@andrkrn/ffprobe-static": "^5.2.0",
"@ffmpeg/ffmpeg": "^0.12.10",
"@ffmpeg/util": "^0.12.1",
"@hookform/resolvers": "^3.3.4",
Expand Down Expand Up @@ -93,7 +93,6 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@uidotdev/usehooks": "^2.4.1",
"@vidstack/react": "^1.10.5",
"adm-zip": "^0.5.10",
"autosize": "^6.0.1",
"axios": "^1.6.7",
"camelcase": "^8.0.0",
Expand All @@ -111,6 +110,7 @@
"electron-log": "^5.1.1",
"electron-settings": "^4.0.2",
"electron-squirrel-startup": "^1.0.0",
"ffmpeg-static": "^5.2.0",
"fluent-ffmpeg": "^2.1.2",
"fs-extra": "^11.2.0",
"html-to-text": "^9.0.5",
Expand Down
7 changes: 4 additions & 3 deletions enjoy/src/main/db/models/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ export class Audio extends Model<Audio> {

@BeforeCreate
static async setupDefaultAttributes(audio: Audio) {
if (!settings.ffmpegConfig().ready) return;

try {
const ffmpeg = new Ffmpeg();
const fileMetadata = await ffmpeg.generateMetadata(audio.filePath);
audio.metadata = Object.assign(audio.metadata || {}, fileMetadata);
audio.metadata = Object.assign(audio.metadata || {}, {
...fileMetadata,
duration: fileMetadata.format.duration,
});
} catch (err) {
logger.error("failed to generate metadata", err.message);
}
Expand Down
8 changes: 4 additions & 4 deletions enjoy/src/main/db/models/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export class Video extends Model<Video> {
// generate cover and upload
async generateCover() {
if (this.coverUrl) return;
if (!settings.ffmpegConfig().ready) return;

const ffmpeg = new Ffmpeg();
const coverFile = await ffmpeg.generateCover(
Expand Down Expand Up @@ -202,12 +201,13 @@ export class Video extends Model<Video> {

@BeforeCreate
static async setupDefaultAttributes(video: Video) {
if (!settings.ffmpegConfig().ready) return;

try {
const ffmpeg = new Ffmpeg();
const fileMetadata = await ffmpeg.generateMetadata(video.filePath);
video.metadata = Object.assign(video.metadata || {}, fileMetadata);
video.metadata = Object.assign(video.metadata || {}, {
...fileMetadata,
duration: fileMetadata.format.duration,
});
} catch (err) {
logger.error("failed to generate metadata", err.message);
}
Expand Down
Loading

0 comments on commit 57d6efa

Please sign in to comment.