Skip to content

Commit

Permalink
vmaf fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Dec 18, 2023
1 parent c7b11e7 commit 368ee52
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 255 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tmp
prometheus-stack/data
webrtcperf*
chromium
*.traineddata
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ webrtcperf.exe
webrtcperf_*.gz
build
_docs
*.traineddata
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ RUN \
mkdir -p /etc/apt/keyrings; \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" \
> /etc/apt/sources.list.d/nodesource.list; \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -; \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list; \
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,15 @@ DEBUG_LEVEL=DEBUG:* yarn start \
--server-data=/data
```
2. The sent/received videos will be saved in the `/data` directory.
3. Run the VMAF calculator comparing the sent (`<n>_send_<trackId>.ivf`) with the received video (`<n>_recv_<trackId>.ivf`):
3. Run the VMAF calculator comparing the sent/received videos:
```sh
docker run --rm \
-e DEBUG_LEVEL=INFO \
-v $PWD/data:/data \
ghcr.io/vpalmisano/webrtcperf:devel \
--vmaf-reference-path /data/1_send_89c58e0f-0307-4ab0-8eff-3ba86fb8ccf0.ivf \
--vmaf-degraded-paths /data/1_recv_9e03aba3-5fa3-4fe3-9ee2-4166a2256c1d.ivf
--vmaf-path /data \
```
The tool will generate a `.vmaf.json` and a `.plotly` files in the `data` directory.
The tool will generate a `.vmaf.json` and a `.plotly` files in the `data/vmaf` directory.
Adding the `--vmaf-preview` option, a `.mp4` file containing the side-by-side
video comparison will be generated.

Expand Down
53 changes: 27 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"license": "AGPL-3.0-or-later",
"dependencies": {
"axios": "^1.5.1",
"axios": "^1.6.2",
"browserify": "^17.0.0",
"camel-case": "^4.1.2",
"chalk": "^4.1.2",
Expand Down Expand Up @@ -75,36 +75,37 @@
"puppeteer-intercept-and-modify-requests": "^1.3.0",
"sprintf-js": "^1.1.3",
"tar-fs": "^2.1.1",
"terser": "^5.22.0",
"terser": "^5.26.0",
"tesseract.js": "^5.0.3",
"uuid": "^9.0.1",
"word-wrap": "^1.2.5",
"ws": "^8.14.2",
"yaml": "^2.3.3"
"ws": "^8.15.1",
"yaml": "^2.3.4"
},
"devDependencies": {
"@types/browserify": "^12.0.39",
"@types/compression": "^1.7.4",
"@types/convict": "^6.1.5",
"@types/convict-format-with-validator": "^6.0.4",
"@types/fast-stats": "^0.0.34",
"@types/node-fetch": "^2.6.7",
"@types/node-os-utils": "^1.3.3",
"@types/pem": "^1.14.3",
"@types/pidusage": "^2.0.4",
"@types/ps-tree": "^1.1.4",
"@types/sprintf-js": "^1.1.3",
"@types/tar-fs": "^2.0.3",
"@types/uuid": "^9.0.6",
"@types/browserify": "^12.0.40",
"@types/compression": "^1.7.5",
"@types/convict": "^6.1.6",
"@types/convict-format-with-validator": "^6.0.5",
"@types/fast-stats": "^0.0.35",
"@types/node": "^20.10.5",
"@types/node-fetch": "^2.6.9",
"@types/node-os-utils": "^1.3.4",
"@types/pem": "^1.14.4",
"@types/pidusage": "^2.0.5",
"@types/ps-tree": "^1.1.6",
"@types/sprintf-js": "^1.1.4",
"@types/tar-fs": "^2.0.4",
"@types/uuid": "^9.0.7",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-standard": "^16.0.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jest": "^27.4.3",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^6.1.1",
Expand All @@ -114,10 +115,10 @@
"nodemon": "^2.0.22",
"prettier": "^2.8.8",
"terser-webpack-plugin": "^5.3.9",
"ts-loader": "^9.5.0",
"ts-node": "^10.9.1",
"typedoc": "^0.25.2",
"typescript": "^4.9.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typedoc": "^0.25.4",
"typescript": "^5.2.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^3.0.0",
Expand Down
15 changes: 12 additions & 3 deletions scripts/get-user-media.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global log, loadScript, sleep, Tesseract, streamWriter */
/* global log, loadScript, sleep, Tesseract, streamWriter, isDisplayTrack */

const applyOverride = (constraints, override) => {
if (override) {
Expand Down Expand Up @@ -127,12 +127,14 @@ function collectMediaTracks(mediaStream) {
* Save the MediaStream video track to disk.
* @param {MediaStreamTrack} videoTrack
*/
window.saveMediaStreamTrack = async (videoTrack, tag, quality = 0.75) => {
window.saveMediaStreamTrack = async (videoTrack, sendrecv, quality = 0.75) => {
const settings = videoTrack.getSettings()
const width = settings.width || window.VIDEO_WIDTH
const height = settings.height || window.VIDEO_HEIGHT
const frameRate = settings.frameRate || window.VIDEO_FRAMERATE
const fname = `${window.WEBRTC_STRESS_TEST_INDEX}_${tag}_${videoTrack.id}.ivf`
const fname = `${window.getParticipantName()}-${sendrecv}_${
videoTrack.id
}.ivf`
log(`saveMediaStreamTrack ${fname} ${width}x${height} ${frameRate}fps`)
const writer = await streamWriter(fname, width, height, frameRate, 'MJPG')

Expand Down Expand Up @@ -215,6 +217,8 @@ const applyTimestampWatermark = mediaStream => {
const fontSize = Math.ceil(canvas.height / 18)
ctx.font = `${fontSize}px Sans`
const textHeight = fontSize + 6
const participantName =
window.getParticipantName() + (isDisplayTrack(videoTrack) ? ' -s' : '')

const transformer = new window.TransformStream({
async transform(videoFrame, controller) {
Expand All @@ -231,6 +235,11 @@ const applyTimestampWatermark = mediaStream => {
ctx.fillStyle = 'white'
ctx.fillText(text, 0, fontSize)

ctx.fillStyle = 'black'
ctx.fillRect(0, height - textHeight, width, height)
ctx.fillStyle = 'white'
ctx.fillText(participantName, 0, height - 6)

const newBitmap = await createImageBitmap(canvas)
const newFrame = new VideoFrame(newBitmap, { timestamp })
newBitmap.close()
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function main(): Promise<void> {
}

// VMAF score.
if (config.vmafReferencePath && config.vmafDegradedPaths) {
if (config.vmafPath) {
await calculateVmafScore(config)
process.exit(0)
}
Expand Down
23 changes: 11 additions & 12 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,21 +666,13 @@ alert will be successful only when at least 95% of the checks pass.`,
env: 'SERVER_DATA',
arg: 'server-data',
},
vmafReferencePath: {
doc: `The reference video path to use for VMAF calculation.`,
vmafPath: {
doc: `When set, it runs the VMAF calculator for the videos saved under the provided directory path.`,
format: String,
nullable: true,
default: '',
env: 'VMAF_REFERENCE_PATH',
arg: 'vmaf-reference-path',
},
vmafDegradedPaths: {
doc: `The degraded video paths (comma-separated) to use for VMAF calculation.`,
format: String,
nullable: true,
default: '',
env: 'VMAF_DEGRADED_PATHS',
arg: 'vmaf-degraded-paths',
env: 'VMAF_PATH',
arg: 'vmaf-path',
},
vmafPreview: {
doc: `If true, for each VMAF comparison it creates a side-by-side video with \
Expand All @@ -690,6 +682,13 @@ the reference and degraded versions.`,
env: 'VMAF_PREVIEW',
arg: 'vmaf-preview',
},
vmafKeepIntermediateFiles: {
doc: `If true, the VMAF intermediate files will not be deleted.`,
format: 'Boolean',
default: false,
env: 'VMAF_KEEP_INTERMEDIATE_FILES',
arg: 'vmaf-keep-intermediate-files',
},
})

type ConfigDocs = Record<
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async function updateSystemStats(): Promise<void> {
SystemStatsCache.set('default', stat)
}

let systemStatsInterval: NodeJS.Timer | null = null
let systemStatsInterval: NodeJS.Timeout | null = null

export function getSystemStats(): SystemStats | undefined {
if (!systemStatsInterval) {
Expand Down
Loading

0 comments on commit 368ee52

Please sign in to comment.