X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fvideo-transcoding.ts;h=9882a14db2c9b0fee03d6101230bb42e58a32dba;hb=6bff8ce23ac9a2de8c6ddcea9df5f7bd2b653156;hp=a7b73a30db2a4be67525bc33f2af52868afc4ae0;hpb=c6c0fa6cd8fe8f752463d8982c3dbcd448739c4e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts index a7b73a30d..9882a14db 100644 --- a/server/lib/video-transcoding.ts +++ b/server/lib/video-transcoding.ts @@ -1,5 +1,9 @@ -import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants' +import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' import { basename, extname as extnameUtil, join } from 'path' +import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' +import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoWithAllFiles, MVideoWithFile } from '@server/types/models' +import { VideoResolution } from '../../shared/models/videos' +import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' import { canDoQuickTranscode, getDurationFromVideoFile, @@ -9,18 +13,13 @@ import { TranscodeOptions, TranscodeOptionsType } from '../helpers/ffmpeg-utils' -import { copyFile, ensureDir, move, remove, stat } from 'fs-extra' import { logger } from '../helpers/logger' -import { VideoResolution } from '../../shared/models/videos' +import { CONFIG } from '../initializers/config' +import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants' import { VideoFileModel } from '../models/video/video-file' -import { updateMasterHLSPlaylist, updateSha256VODSegments } 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' -import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoWithAllFiles, MVideoWithFile } from '@server/types/models' -import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' +import { updateMasterHLSPlaylist, updateSha256VODSegments } from './hls' import { generateVideoStreamingPlaylistName, getVideoFilename, getVideoFilePath } from './video-paths' -import { spawn } from 'child_process' /** * Optimize the original video file and replace it. The resolution is not changed. @@ -147,17 +146,18 @@ async function mergeAudioVideofile (video: MVideoWithAllFiles, resolution: Video return onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) } -async function generateHlsPlaylist (video: MVideoWithFile, resolution: VideoResolution, copyCodecs: boolean, isPortraitMode: boolean) { +async function generateHlsPlaylist (options: { + video: MVideoWithFile + videoInputPath: string + resolution: VideoResolution + copyCodecs: boolean + isPortraitMode: boolean +}) { + const { video, videoInputPath, resolution, copyCodecs, isPortraitMode } = options + const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid) await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)) - const videoFileInput = copyCodecs - ? video.getWebTorrentFile(resolution) - : video.getMaxQualityFile() - - const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist() - const videoInputPath = getVideoFilePath(videoOrStreamingPlaylist, videoFileInput) - const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution)) const videoFilename = generateVideoStreamingPlaylistName(video.uuid, resolution) @@ -174,8 +174,6 @@ async function generateHlsPlaylist (video: MVideoWithFile, resolution: VideoReso } } - logger.debug('Will run transcode.', { transcodeOptions }) - await transcode(transcodeOptions) const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) @@ -184,7 +182,7 @@ async function generateHlsPlaylist (video: MVideoWithFile, resolution: VideoReso videoId: video.id, playlistUrl, segmentsSha256Url: WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid, video.isLive), - p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrl, video.VideoFiles), + p2pMediaLoaderInfohashes: [], p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, type: VideoStreamingPlaylistType.HLS @@ -211,6 +209,11 @@ async function generateHlsPlaylist (video: MVideoWithFile, resolution: VideoReso await VideoFileModel.customUpsert(newVideoFile, 'streaming-playlist', undefined) videoStreamingPlaylist.VideoFiles = await videoStreamingPlaylist.$get('VideoFiles') + videoStreamingPlaylist.p2pMediaLoaderInfohashes = VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes( + playlistUrl, videoStreamingPlaylist.VideoFiles + ) + await videoStreamingPlaylist.save() + video.setHLSPlaylist(videoStreamingPlaylist) await updateMasterHLSPlaylist(video)