},
html5: {
hlsjsConfig: {
+ capLevelToPlayerSize: true,
autoStartLoad: false,
liveSyncDurationCount: 7,
loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
return resolutionsEnabled
}
-async function getVideoFileSize (path: string) {
+async function getVideoStreamSize (path: string) {
const videoStream = await getVideoStreamFromFile(path)
return videoStream === null
: { width: videoStream.width, height: videoStream.height }
}
+async function getVideoStreamCodec (path: string) {
+ const videoStream = await getVideoStreamFromFile(path)
+
+ if (!videoStream) return ''
+
+ const videoCodec = videoStream.codec_tag_string
+
+ const baseProfileMatrix = {
+ 'High': '6400',
+ 'Main': '4D40',
+ 'Baseline': '42E0'
+ }
+
+ let baseProfile = baseProfileMatrix[videoStream.profile]
+ if (!baseProfile) {
+ logger.warn('Cannot get video profile codec of %s.', path, { videoStream })
+ baseProfile = baseProfileMatrix['High'] // Fallback
+ }
+
+ const level = videoStream.level.toString(16)
+
+ return `${videoCodec}.${baseProfile}${level}`
+}
+
+async function getAudioStreamCodec (path: string) {
+ const { audioStream } = await audio.get(path)
+
+ if (!audioStream) return ''
+
+ const audioCodec = audioStream.codec_name
+ if (audioCodec.codec_name === 'aac') return 'mp4a.40.2'
+
+ logger.warn('Cannot get audio codec of %s.', path, { audioStream })
+
+ return 'mp4a.40.2' // Fallback
+}
+
async function getVideoFileResolution (path: string) {
- const size = await getVideoFileSize(path)
+ const size = await getVideoStreamSize(path)
return {
videoFileResolution: Math.min(size.height, size.width),
// ---------------------------------------------------------------------------
export {
- getVideoFileSize,
+ getVideoStreamCodec,
+ getAudioStreamCodec,
+ getVideoStreamSize,
getVideoFileResolution,
getDurationFromVideoFile,
generateImageFromVideoFile,
let localCommand = command
.format('mp4')
.videoCodec('libx264')
- .outputOption('-level 3.1') // 3.1 is the minimal ressource allocation for our highest supported resolution
- .outputOption('-b_strategy 1') // NOTE: b-strategy 1 - heuristic algorythm, 16 is optimal B-frames for it
+ .outputOption('-level 3.1') // 3.1 is the minimal resource allocation for our highest supported resolution
+ .outputOption('-b_strategy 1') // NOTE: b-strategy 1 - heuristic algorithm, 16 is optimal B-frames for it
.outputOption('-bf 16') // NOTE: Why 16: https://github.com/Chocobozzz/PeerTube/pull/774. b-strategy 2 -> B-frames<16
.outputOption('-pix_fmt yuv420p') // allows import of source material with incompatible pixel formats (e.g. MJPEG video)
.outputOption('-map_metadata -1') // strip all metadata
import { basename, dirname, join } from 'path'
import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION } from '../initializers/constants'
import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra'
-import { getVideoFileSize } from '../helpers/ffmpeg-utils'
+import { getVideoStreamSize, getAudioStreamCodec, getVideoStreamCodec } from '../helpers/ffmpeg-utils'
import { sha256 } from '../helpers/core-utils'
import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
import { logger } from '../helpers/logger'
const videoFilePath = getVideoFilePath(streamingPlaylist, file)
- const size = await getVideoFileSize(videoFilePath)
+ const size = await getVideoStreamSize(videoFilePath)
const bandwidth = 'BANDWIDTH=' + video.getBandwidthBits(file)
const resolution = `RESOLUTION=${size.width}x${size.height}`
let line = `#EXT-X-STREAM-INF:${bandwidth},${resolution}`
if (file.fps) line += ',FRAME-RATE=' + file.fps
+ const audioCodec = await getAudioStreamCodec(filePlaylistPath)
+ const videoCodec = await getVideoStreamCodec(filePlaylistPath)
+ line += `,CODECS="${videoCodec},${audioCodec}"`
+
masterPlaylists.push(line)
masterPlaylists.push(VideoStreamingPlaylistModel.getHlsPlaylistFilename(file.resolution))
}
import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
import { join } from 'path'
import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants'
-import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution, audio, getVideoFileSize } from '@server/helpers/ffmpeg-utils'
+import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution, audio, getVideoStreamSize } from '@server/helpers/ffmpeg-utils'
const expect = chai.expect
expect(audioStream[ 'codec_name' ]).to.be.equal('aac')
expect(audioStream[ 'bit_rate' ]).to.be.at.most(384 * 8000)
- const size = await getVideoFileSize(path)
+ const size = await getVideoStreamSize(path)
expect(size.height).to.equal(0)
expect(size.width).to.equal(0)
}
const masterPlaylist = res.text
for (const resolution of resolutions) {
- expect(masterPlaylist).to.match(new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',FRAME-RATE=\\d+'))
+ const reg = new RegExp('#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',FRAME-RATE=\\d+,CODECS="avc1.64001f,mp4a.40.2"')
+
+ expect(masterPlaylist).to.match(reg)
+ expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
expect(masterPlaylist).to.contain(`${resolution}.m3u8`)
}
}