aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2019-05-04 03:18:32 +0200
committerFelix Ableitner <me@nutomic.com>2019-05-04 13:06:43 +0200
commit7ed2c1a46fd11caca16d5aec80d9f90d7a2d3429 (patch)
treef08bb274301a10cbddfa8bc852d14bd8b8d5b074
parent5ba49f268deb76b168559fe5fe2506b0bd5af9a8 (diff)
downloadPeerTube-7ed2c1a46fd11caca16d5aec80d9f90d7a2d3429.tar.gz
PeerTube-7ed2c1a46fd11caca16d5aec80d9f90d7a2d3429.tar.zst
PeerTube-7ed2c1a46fd11caca16d5aec80d9f90d7a2d3429.zip
fixed formatting, added test case
-rw-r--r--server/helpers/ffmpeg-utils.ts19
-rw-r--r--server/lib/video-transcoding.ts2
-rw-r--r--server/tests/api/videos/video-transcoder.ts23
3 files changed, 32 insertions, 12 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 13bb2e894..af92d1ba9 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -173,7 +173,7 @@ function transcode (options: TranscodeOptions) {
173 }) 173 })
174} 174}
175 175
176async function canDoQuickTranscode (path: string) { 176async function canDoQuickTranscode (path: string): Promise<boolean> {
177 // NOTE: This could be optimized by running ffprobe only once (but it runs fast anyway) 177 // NOTE: This could be optimized by running ffprobe only once (but it runs fast anyway)
178 const videoStream = await getVideoStreamFromFile(path) 178 const videoStream = await getVideoStreamFromFile(path)
179 const parsedAudio = await audio.get(path) 179 const parsedAudio = await audio.get(path)
@@ -182,22 +182,27 @@ async function canDoQuickTranscode (path: string) {
182 const resolution = await getVideoFileResolution(path) 182 const resolution = await getVideoFileResolution(path)
183 183
184 // check video params 184 // check video params
185 if (videoStream[ 'codec_name' ] !== 'h264') 185 if (videoStream[ 'codec_name' ] !== 'h264') {
186 return false 186 return false
187 if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) 187 }
188 if (fps < VIDEO_TRANSCODING_FPS.MIN || fps > VIDEO_TRANSCODING_FPS.MAX) {
188 return false 189 return false
189 if (bitRate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) 190 }
191 if (bitRate > getMaxBitrate(resolution.videoFileResolution, fps, VIDEO_TRANSCODING_FPS)) {
190 return false 192 return false
193 }
191 194
192 // check audio params (if audio stream exists) 195 // check audio params (if audio stream exists)
193 if (parsedAudio.audioStream) { 196 if (parsedAudio.audioStream) {
194 if (parsedAudio.audioStream[ 'codec_name' ] !== 'aac') 197 if (parsedAudio.audioStream[ 'codec_name' ] !== 'aac') {
195 return false 198 return false
199 }
196 const maxAudioBitrate = audio.bitrate[ 'aac' ](parsedAudio.audioStream[ 'bit_rate' ]) 200 const maxAudioBitrate = audio.bitrate[ 'aac' ](parsedAudio.audioStream[ 'bit_rate' ])
197 if (maxAudioBitrate != -1 && parsedAudio.audioStream[ 'bit_rate' ] > maxAudioBitrate) 201 if (maxAudioBitrate !== -1 && parsedAudio.audioStream[ 'bit_rate' ] > maxAudioBitrate) {
198 return false 202 return false
203 }
199 } 204 }
200 205
201 return true 206 return true
202} 207}
203 208
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index 05afb44d1..81aa7a4c4 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -1,4 +1,4 @@
1import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER, VIDEO_TRANSCODING_FPS } from '../initializers/constants' 1import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers/constants'
2import { join } from 'path' 2import { join } from 'path'
3import { getVideoFileFPS, transcode, canDoQuickTranscode } from '../helpers/ffmpeg-utils' 3import { getVideoFileFPS, transcode, canDoQuickTranscode } from '../helpers/ffmpeg-utils'
4import { ensureDir, move, remove, stat } from 'fs-extra' 4import { ensureDir, move, remove, stat } from 'fs-extra'
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index 3cd43e99b..4923759da 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -4,7 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos' 6import { getMaxBitrate, VideoDetails, VideoResolution, VideoState } from '../../../../shared/models/videos'
7import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 7import { audio, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution, canDoQuickTranscode } from '../../../helpers/ffmpeg-utils'
8import { 8import {
9 buildAbsoluteFixturePath, cleanupTests, 9 buildAbsoluteFixturePath, cleanupTests,
10 doubleFollow, 10 doubleFollow,
@@ -13,15 +13,14 @@ import {
13 getMyVideos, 13 getMyVideos,
14 getVideo, 14 getVideo,
15 getVideosList, 15 getVideosList,
16 killallServers, 16 waitJobs,
17 root, 17 root,
18 ServerInfo, 18 ServerInfo,
19 setAccessTokensToServers, 19 setAccessTokensToServers,
20 uploadVideo, 20 uploadVideo,
21 webtorrentAdd 21 webtorrentAdd
22} from '../../../../shared/extra-utils' 22} from '../../../../shared/extra-utils'
23import { extname, join } from 'path' 23import { join } from 'path'
24import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' 24import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants'
26 25
27const expect = chai.expect 26const expect = chai.expect
@@ -324,6 +323,15 @@ describe('Test video transcoding', function () {
324 it('Should accept and transcode additional extensions', async function () { 323 it('Should accept and transcode additional extensions', async function () {
325 this.timeout(300000) 324 this.timeout(300000)
326 325
326 let tempFixturePath: string
327
328 {
329 tempFixturePath = await generateHighBitrateVideo()
330
331 const bitrate = await getVideoFileBitrate(tempFixturePath)
332 expect(bitrate).to.be.above(getMaxBitrate(VideoResolution.H_1080P, 60, VIDEO_TRANSCODING_FPS))
333 }
334
327 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) { 335 for (const fixture of [ 'video_short.mkv', 'video_short.avi' ]) {
328 const videoAttributes = { 336 const videoAttributes = {
329 name: fixture, 337 name: fixture,
@@ -349,6 +357,13 @@ describe('Test video transcoding', function () {
349 } 357 }
350 }) 358 })
351 359
360 it('Should correctly detect if quick transcode is possible', async function () {
361 this.timeout(10000)
362
363 expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.mp4'))).to.be.true
364 expect(await canDoQuickTranscode(buildAbsoluteFixturePath('video_short.webm'))).to.be.false
365 })
366
352 after(async function () { 367 after(async function () {
353 await cleanupTests(servers) 368 await cleanupTests(servers)
354 }) 369 })