현재 로직에서는 /musics
로 DB에 음악 정보를 업로드하는 과정
⇒ 다만 이 과정이 완료되기까지 4초 후반~7초 중반이라는 긴 시간이 소요되어, 어떤 부분에서 시간 소요가 많이 발생하는지 알아보고 개선하고자 한다.
return await new Promise((resolve, reject) => {
const startTime = new Date().getTime();
ffmpeg(tempFilePath)
.addOption([
'-c:a aac',
'-b:a 192k',
'-hls_time 10',
'-hls_list_size 0',
'-f hls',
])
.output(outputPath)
.on('end', async () => {
const encodedPath = await this.uploadEncodedFiles(
outputMusicPath,
musicId,
);
resolve(encodedPath);
const finishTime = new Date().getTime();
console.log(finishTime - startTime);
})
.on('error', () => {
reject(new Error());
})
.run();
});
위의 코드에서 ffmpeg 모듈을 활용해 인코딩이 시작되는 시간(startTime
)과 인코딩이 끝나고 변환된 파일의 로컬 경로를 반환(resolve
)하는 시간(finishTime
)을 두어 정확히 인코딩에만 걸리는 시간을 계산해보았다.
3.2~3.3초 정도 걸렸는데, 5~7초가 전체 로직 작동 시간이라면 반 이상을 차지하기 때문에 개선이 필요할 것 같다.
→ 옵션 일단 써봤는데 별로 효과가 없다….
.inputOptions('-threads 2')
.audioBitrate('192k')
.outputOptions('-preset fast')