aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-11 17:20:28 +0100
committerChocobozzz <me@florianbigard.com>2019-02-12 11:14:36 +0100
commit7f8f8bdb4a1fb695a114874c4679605ac8911e2d (patch)
tree44a853508884ea37ae4ac21057f24f009edd8d94
parent66d332340e2df628569c81448ab9e11287056541 (diff)
downloadPeerTube-7f8f8bdb4a1fb695a114874c4679605ac8911e2d.tar.gz
PeerTube-7f8f8bdb4a1fb695a114874c4679605ac8911e2d.tar.zst
PeerTube-7f8f8bdb4a1fb695a114874c4679605ac8911e2d.zip
HLS is only supported by ffmpeg 4
Because of https://github.com/FFmpeg/FFmpeg/commit/c8f625f52998faa9bf0fe22701f1684e51edfc07
-rw-r--r--.gitignore1
-rw-r--r--config/default.yaml6
-rw-r--r--config/production.yaml.example6
-rw-r--r--server/helpers/ffmpeg-utils.ts29
4 files changed, 33 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index a31da70a9..681004527 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@
17/config/local* 17/config/local*
18/ffmpeg/ 18/ffmpeg/
19/ffmpeg-4/ 19/ffmpeg-4/
20/ffmpeg-3/
20/thumbnails/ 21/thumbnails/
21/torrents/ 22/torrents/
22/videos/ 23/videos/
diff --git a/config/default.yaml b/config/default.yaml
index 5a83b271e..7af615a82 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -140,12 +140,12 @@ transcoding:
140 720p: false 140 720p: false
141 1080p: false 141 1080p: false
142 # /!\ EXPERIMENTAL /!\ 142 # /!\ EXPERIMENTAL /!\
143 # /!\ Requires ffmpeg >= 3.4 143 # /!\ Requires ffmpeg >= 4
144 # Generate HLS playlist/segments. Better playback than with WebTorrent: 144 # Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
145 # * Resolution change is smoother 145 # * Resolution change is smoother
146 # * Faster playback in particular with long videos 146 # * Faster playback in particular with long videos
147 # * More stable playback (less bugs/infinite loading) 147 # * More stable playback (less bugs/infinite loading)
148 # /!\ Multiply videos storage by two /!\ 148 # /!\ Multiply videos storage by 2 /!\
149 hls: 149 hls:
150 enabled: false 150 enabled: false
151 151
diff --git a/config/production.yaml.example b/config/production.yaml.example
index c54e1a516..413e3c478 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -153,12 +153,12 @@ transcoding:
153 720p: false 153 720p: false
154 1080p: false 154 1080p: false
155 # /!\ EXPERIMENTAL /!\ 155 # /!\ EXPERIMENTAL /!\
156 # /!\ Requires ffmpeg >= 3.4 156 # /!\ Requires ffmpeg >= 4
157 # Generate HLS playlist/segments. Better playback than with WebTorrent: 157 # Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent:
158 # * Resolution change is smoother 158 # * Resolution change is smoother
159 # * Faster playback in particular with long videos 159 # * Faster playback in particular with long videos
160 # * More stable playback (less bugs/infinite loading) 160 # * More stable playback (less bugs/infinite loading)
161 # /!\ Multiply videos storage by two /!\ 161 # /!\ Multiply videos storage by 2 /!\
162 hls: 162 hls:
163 enabled: false 163 enabled: false
164 164
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 133b1b03b..b6b64de3f 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -5,7 +5,7 @@ import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/cons
5import { processImage } from './image-utils' 5import { processImage } from './image-utils'
6import { logger } from './logger' 6import { logger } from './logger'
7import { checkFFmpegEncoders } from '../initializers/checker-before-init' 7import { checkFFmpegEncoders } from '../initializers/checker-before-init'
8import { remove } from 'fs-extra' 8import { remove, readFile, writeFile } from 'fs-extra'
9 9
10function computeResolutionsToTranscode (videoFileHeight: number) { 10function computeResolutionsToTranscode (videoFileHeight: number) {
11 const resolutionsEnabled: number[] = [] 11 const resolutionsEnabled: number[] = []
@@ -164,7 +164,7 @@ function transcode (options: TranscodeOptions) {
164 } 164 }
165 165
166 if (options.hlsPlaylist) { 166 if (options.hlsPlaylist) {
167 const videoPath = `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}` 167 const videoPath = getHLSVideoPath(options)
168 168
169 command = command.outputOption('-hls_time 4') 169 command = command.outputOption('-hls_time 4')
170 .outputOption('-hls_list_size 0') 170 .outputOption('-hls_list_size 0')
@@ -180,7 +180,11 @@ function transcode (options: TranscodeOptions) {
180 logger.error('Error in transcoding job.', { stdout, stderr }) 180 logger.error('Error in transcoding job.', { stdout, stderr })
181 return rej(err) 181 return rej(err)
182 }) 182 })
183 .on('end', res) 183 .on('end', () => {
184 return onTranscodingSuccess(options)
185 .then(() => res())
186 .catch(err => rej(err))
187 })
184 .run() 188 .run()
185 } catch (err) { 189 } catch (err) {
186 return rej(err) 190 return rej(err)
@@ -204,6 +208,25 @@ export {
204 208
205// --------------------------------------------------------------------------- 209// ---------------------------------------------------------------------------
206 210
211function getHLSVideoPath (options: TranscodeOptions) {
212 return `${dirname(options.outputPath)}/${options.hlsPlaylist.videoFilename}`
213}
214
215async function onTranscodingSuccess (options: TranscodeOptions) {
216 if (!options.hlsPlaylist) return
217
218 // Fix wrong mapping with some ffmpeg versions
219 const fileContent = await readFile(options.outputPath)
220
221 const videoFileName = options.hlsPlaylist.videoFilename
222 const videoFilePath = getHLSVideoPath(options)
223
224 const newContent = fileContent.toString()
225 .replace(`#EXT-X-MAP:URI="${videoFilePath}",`, `#EXT-X-MAP:URI="${videoFileName}",`)
226
227 await writeFile(options.outputPath, newContent)
228}
229
207function getVideoFileStream (path: string) { 230function getVideoFileStream (path: string) {
208 return new Promise<any>((res, rej) => { 231 return new Promise<any>((res, rej) => {
209 ffmpeg.ffprobe(path, (err, metadata) => { 232 ffmpeg.ffprobe(path, (err, metadata) => {