aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/videos.ts
blob: 96bdd42e9ffc62917a42e5be475087c31491ec49 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile } from '@server/typings/models'
import { VideoTranscodingPayload } from '@server/lib/job-queue/handlers/video-transcoding'
import { DEFAULT_AUDIO_RESOLUTION } from '@server/initializers/constants'
import { JobQueue } from '@server/lib/job-queue'

function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
  return isStreamingPlaylist(videoOrPlaylist)
    ? videoOrPlaylist.Video
    : videoOrPlaylist
}

function addOptimizeOrMergeAudioJob (video: MVideo, videoFile: MVideoFile) {
  let dataInput: VideoTranscodingPayload

  if (videoFile.isAudio()) {
    dataInput = {
      type: 'merge-audio' as 'merge-audio',
      resolution: DEFAULT_AUDIO_RESOLUTION,
      videoUUID: video.uuid,
      isNewVideo: true
    }
  } else {
    dataInput = {
      type: 'optimize' as 'optimize',
      videoUUID: video.uuid,
      isNewVideo: true
    }
  }

  return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: dataInput })
}

export {
  addOptimizeOrMergeAudioJob,
  extractVideo
}