HLS 기반 라이브 플레이리스트 실행에 관한 정리

File extension에 관한 정리

Express에서 필요한 패키지 정리

yarn install fluent-ffmpeg @ffmpeg-installer/ffmpeg
yarn install hls-server

인덱스 파일과 ts 파일 generation 순서

ffmpeg라는 라이브러리를 기반으로 HLS 형식으로 변환 및 index file 생성을 지원. ffmpeg 역할:

HLS 테스트 진행

테스트 진행 목적

FFmpeg 코드 : 포맷 변환 및 파일 분할 작업 진행

FfmpegService

async convertToHLS(inputPath: string, outputPath: string): Promise<void> {
  return new Promise((resolve, reject) => {
    ffmpeg(inputPath, { timeout: 432000 })
      .addOptions([
        '-c:a aac',
        '-b:a 128k',
        '-hls_time 10',
        '-hls_list_size 0',
        '-f hls',
      ])
      .output(outputPath)
      .on('progress', (progress) => {
        console.log('Processing: ', progress.percent, '% done');
      })
      .on('start', (commandLine) => {
        console.log('FFmpeg command:', commandLine);
      })
      .on('stderr', (stderrLine) => {
        console.log('FFmpeg stderr:', stderrLine);
      })
      .on('end', () => {
        console.log('Processing finished successfully');
        resolve();
      })
      .on('error', (err, stdout, stderr) => {
        console.error('FFmpeg Error:', err);
        console.error('FFmpeg stdout:', stdout);
        console.error('FFmpeg stderr:', stderr);
        reject(err);
      })
      .run();
  });
}