Skip to content

Commit c17d9b8

Browse files
committed
refactor: ffmpeg promise화
1 parent f4a9094 commit c17d9b8

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
rules: {
1313
"no-return-await": "off",
1414
"no-useless-catch": "off",
15-
"no-console": "error",
15+
"no-console": "warn",
1616
"no-unused-vars": [
1717
"error",
1818
{

src/services/trimVideo.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ffmpeg from "fluent-ffmpeg";
2-
import createError from "http-errors";
2+
// import createError from "http-errors";
33

4-
import { MESSAGES } from "../config/constants.js";
4+
// import { MESSAGES } from "../config/constants.js";
55
import env from "../config/env.js";
66
import { bucket } from "../config/gcs.js";
77

@@ -12,21 +12,16 @@ const trimVideo = async ({ videoId, trimStart, trimEnd }) => {
1212

1313
try {
1414
const stream = bucket.file(originalVideo).createReadStream();
15-
return (
16-
ffmpeg(stream)
15+
return new Promise((resolve, reject) => {
16+
const ffmpegStream = ffmpeg(stream)
1717
.setStartTime(trimStart)
1818
.duration(trimEnd - trimStart)
1919
.format("webm")
20-
.on("start", (commandLine) =>
21-
console.log("Spawned ffmpeg with command:", commandLine)
22-
)
23-
.on("error", (err) => console.error("ffmpeg error:", err))
24-
.on("end", () => console.log("ffmpeg processing finished"))
25-
// .on("error", () => {
26-
// throw createError.InternalServerError(MESSAGES.ERROR.FAILED_EDIT_VIDEO);
27-
// })
28-
.pipe()
29-
);
20+
.on("error", (err) => reject(err));
21+
22+
const outputStream = ffmpegStream.pipe();
23+
resolve(outputStream);
24+
});
3025
} catch (err) {
3126
throw err;
3227
}

0 commit comments

Comments
 (0)