aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-22 15:42:02 +0100
committerChocobozzz <me@florianbigard.com>2020-12-22 16:04:42 +0100
commit236841a1d73a1b67541537f0017856848ad43b79 (patch)
tree843d6fdb355f834bd03d1c9b0f40eea0390cd424 /server
parent1916c9663ac632227e60ebc93cec616b2dd6800d (diff)
downloadPeerTube-236841a1d73a1b67541537f0017856848ad43b79.tar.gz
PeerTube-236841a1d73a1b67541537f0017856848ad43b79.tar.zst
PeerTube-236841a1d73a1b67541537f0017856848ad43b79.zip
Force HLS transcoding
Fix weird behaviour with some web browsers. Don't really know if it's a ffmpeg bug, a safari bug or a peertube bug, but forcing transcoding seems to fix this playback bug
Diffstat (limited to 'server')
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts26
-rw-r--r--server/lib/video-transcoding.ts2
2 files changed, 20 insertions, 8 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index b6b8d9071..04143eec3 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -18,6 +18,7 @@ import { federateVideoIfNeeded } from '../../activitypub/videos'
18import { Notifier } from '../../notifier' 18import { Notifier } from '../../notifier'
19import { generateHlsPlaylist, mergeAudioVideofile, optimizeOriginalVideofile, transcodeNewResolution } from '../../video-transcoding' 19import { generateHlsPlaylist, mergeAudioVideofile, optimizeOriginalVideofile, transcodeNewResolution } from '../../video-transcoding'
20import { JobQueue } from '../job-queue' 20import { JobQueue } from '../job-queue'
21import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils'
21 22
22async function processVideoTranscoding (job: Bull.Job) { 23async function processVideoTranscoding (job: Bull.Job) {
23 const payload = job.data as VideoTranscodingPayload 24 const payload = job.data as VideoTranscodingPayload
@@ -56,9 +57,9 @@ async function processVideoTranscoding (job: Bull.Job) {
56 57
57 await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload) 58 await retryTransactionWrapper(publishNewResolutionIfNeeded, video, payload)
58 } else { 59 } else {
59 await optimizeOriginalVideofile(video) 60 const transcodeType = await optimizeOriginalVideofile(video)
60 61
61 await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload) 62 await retryTransactionWrapper(onVideoFileOptimizerSuccess, video, payload, transcodeType)
62 } 63 }
63 64
64 return video 65 return video
@@ -83,10 +84,14 @@ async function onHlsPlaylistGenerationSuccess (video: MVideoFullLight) {
83async function publishNewResolutionIfNeeded (video: MVideoUUID, payload?: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload) { 84async function publishNewResolutionIfNeeded (video: MVideoUUID, payload?: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload) {
84 await publishAndFederateIfNeeded(video) 85 await publishAndFederateIfNeeded(video)
85 86
86 await createHlsJobIfEnabled(payload) 87 createHlsJobIfEnabled(Object.assign({}, payload, { copyCodecs: true })
87} 88}
88 89
89async function onVideoFileOptimizerSuccess (videoArg: MVideoWithFile, payload: OptimizeTranscodingPayload) { 90async function onVideoFileOptimizerSuccess (
91 videoArg: MVideoWithFile,
92 payload: OptimizeTranscodingPayload,
93 transcodeType: TranscodeOptionsType
94) {
90 if (videoArg === undefined) return undefined 95 if (videoArg === undefined) return undefined
91 96
92 // Outside the transaction (IO on disk) 97 // Outside the transaction (IO on disk)
@@ -108,8 +113,13 @@ async function onVideoFileOptimizerSuccess (videoArg: MVideoWithFile, payload: O
108 let videoPublished = false 113 let videoPublished = false
109 114
110 // Generate HLS version of the max quality file 115 // Generate HLS version of the max quality file
111 const hlsPayload = Object.assign({}, payload, { resolution: videoDatabase.getMaxQualityFile().resolution }) 116 const originalFileHLSPayload = Object.assign({}, payload, {
112 await createHlsJobIfEnabled(hlsPayload) 117 isPortraitMode,
118 resolution: videoDatabase.getMaxQualityFile().resolution,
119 // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
120 copyCodecs: transcodeType !== 'quick-transcode'
121 })
122 createHlsJobIfEnabled(originalFileHLSPayload)
113 123
114 if (resolutionsEnabled.length !== 0) { 124 if (resolutionsEnabled.length !== 0) {
115 for (const resolution of resolutionsEnabled) { 125 for (const resolution of resolutionsEnabled) {
@@ -161,7 +171,7 @@ export {
161 171
162// --------------------------------------------------------------------------- 172// ---------------------------------------------------------------------------
163 173
164function createHlsJobIfEnabled (payload?: { videoUUID: string, resolution: number, isPortraitMode?: boolean }) { 174function createHlsJobIfEnabled (payload: { videoUUID: string, resolution: number, isPortraitMode?: boolean, copyCodecs: boolean }) {
165 // Generate HLS playlist? 175 // Generate HLS playlist?
166 if (payload && CONFIG.TRANSCODING.HLS.ENABLED) { 176 if (payload && CONFIG.TRANSCODING.HLS.ENABLED) {
167 const hlsTranscodingPayload = { 177 const hlsTranscodingPayload = {
@@ -169,7 +179,7 @@ function createHlsJobIfEnabled (payload?: { videoUUID: string, resolution: numbe
169 videoUUID: payload.videoUUID, 179 videoUUID: payload.videoUUID,
170 resolution: payload.resolution, 180 resolution: payload.resolution,
171 isPortraitMode: payload.isPortraitMode, 181 isPortraitMode: payload.isPortraitMode,
172 copyCodecs: true 182 copyCodecs: payload.copyCodecs
173 } 183 }
174 184
175 return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload }) 185 return JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload })
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index e7108bd5a..078e85acf 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -59,6 +59,8 @@ async function optimizeOriginalVideofile (video: MVideoWithFile, inputVideoFileA
59 const videoOutputPath = getVideoFilePath(video, inputVideoFile) 59 const videoOutputPath = getVideoFilePath(video, inputVideoFile)
60 60
61 await onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath) 61 await onVideoFileTranscoding(video, inputVideoFile, videoTranscodedPath, videoOutputPath)
62
63 return transcodeType
62 } catch (err) { 64 } catch (err) {
63 // Auto destruction... 65 // Auto destruction...
64 video.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', { err })) 66 video.destroy().catch(err => logger.error('Cannot destruct video after transcoding failure.', { err }))