-import { CONFIG, HLS_PLAYLIST_DIRECTORY } from '../initializers'
-import { extname, join } from 'path'
-import { getVideoFileFPS, getVideoFileResolution, transcode } from '../helpers/ffmpeg-utils'
-import { copy, ensureDir, move, remove, stat } from 'fs-extra'
+import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants'
+import { join } from 'path'
+import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils'
+import { ensureDir, move, remove, stat } from 'fs-extra'
import { logger } from '../helpers/logger'
import { VideoResolution } from '../../shared/models/videos'
import { VideoFileModel } from '../models/video/video-file'
import { updateMasterHLSPlaylist, updateSha256Segments } from './hls'
import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type'
+import { CONFIG } from '../initializers/config'
async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
}
async function generateHlsPlaylist (video: VideoModel, resolution: VideoResolution, isPortraitMode: boolean) {
- const baseHlsDirectory = join(HLS_PLAYLIST_DIRECTORY, video.uuid)
- await ensureDir(join(HLS_PLAYLIST_DIRECTORY, video.uuid))
+ const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
+ await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid))
const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getOriginalFile()))
const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution))
outputPath,
resolution,
isPortraitMode,
- generateHlsPlaylist: true
+
+ hlsPlaylist: {
+ videoFilename: VideoStreamingPlaylistModel.getHlsVideoName(video.uuid, resolution)
+ }
}
await transcode(transcodeOptions)
await updateMasterHLSPlaylist(video)
await updateSha256Segments(video)
- const playlistUrl = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
+ const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
await VideoStreamingPlaylistModel.upsert({
videoId: video.id,
playlistUrl,
- segmentsSha256Url: CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid),
+ segmentsSha256Url: WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid),
p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrl, video.VideoFiles),
+ p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION,
type: VideoStreamingPlaylistType.HLS
})
}
-async function importVideoFile (video: VideoModel, inputFilePath: string) {
- const { videoFileResolution } = await getVideoFileResolution(inputFilePath)
- const { size } = await stat(inputFilePath)
- const fps = await getVideoFileFPS(inputFilePath)
-
- let updatedVideoFile = new VideoFileModel({
- resolution: videoFileResolution,
- extname: extname(inputFilePath),
- size,
- fps,
- videoId: video.id
- })
-
- const currentVideoFile = video.VideoFiles.find(videoFile => videoFile.resolution === updatedVideoFile.resolution)
-
- if (currentVideoFile) {
- // Remove old file and old torrent
- await video.removeFile(currentVideoFile)
- await video.removeTorrent(currentVideoFile)
- // Remove the old video file from the array
- video.VideoFiles = video.VideoFiles.filter(f => f !== currentVideoFile)
-
- // Update the database
- currentVideoFile.set('extname', updatedVideoFile.extname)
- currentVideoFile.set('size', updatedVideoFile.size)
- currentVideoFile.set('fps', updatedVideoFile.fps)
-
- updatedVideoFile = currentVideoFile
- }
-
- const outputPath = video.getVideoFilePath(updatedVideoFile)
- await copy(inputFilePath, outputPath)
-
- await video.createTorrentAndSetInfoHash(updatedVideoFile)
-
- await updatedVideoFile.save()
-
- video.VideoFiles.push(updatedVideoFile)
-}
-
export {
generateHlsPlaylist,
optimizeVideofile,
- transcodeOriginalVideofile,
- importVideoFile
+ transcodeOriginalVideofile
}