Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ Sample test results are shown below. They were generated with [`run-video-bench.

The `h264.net` columns are the managed [H.264 port](src/Codecs/SIPSorcery.H264/), which is for educational use only and is never packaged, so the published tool leaves it out; the script builds the CLI from source with it to measure it. It picks its threads (a slice each) by frame size: 1 up to 640x480, 2 above that, 3 above 1280x960, and 4, OpenH264's most, from 1080p on a machine with more than 8 processors. That's the table libwebrtc has for OpenH264 but leaves off, running it on one thread. Its frame skipping is off so that it encodes every frame as the other encoders do, and its decoder gets the same FFmpeg (libx264 Constrained Baseline) clip as the FFmpeg H264 decoder.

The `vp9.net` columns are the managed [VP9 port](src/Codecs/SIPSorcery.VP9/) of libvpx, which isn't packaged yet either, so the script builds the CLI from source with it as well. It follows libwebrtc's set-up of libvpx VP9, CBR at cpu-used 7 with row multi-threading, on threads it picks by frame size: 2 at 480p, 4 at 720p, 8 at 1080p and 16 from 1440p (no more than the processors), where libwebrtc stops at 4 for native libvpx. Its decoder gets the same FFmpeg (libvpx-vp9) clip as the FFmpeg VP9 decoder. FFmpeg's VP9 encoder runs on every core at cpu-used 8 with row multi-threading, so it does less work per frame than `vp9.net` does.
The `vp9.net` columns are the managed [VP9 port](src/Codecs/SIPSorcery.VP9/) of libvpx, which is in the published tool. It follows libwebrtc's set-up of libvpx VP9, CBR at cpu-used 7 with row multi-threading, on threads it picks by frame size: 2 at 480p, 4 at 720p, 8 at 1080p and 16 from 1440p (no more than the processors), where libwebrtc stops at 4 for native libvpx. Its decoder gets the same FFmpeg (libvpx-vp9) clip as the FFmpeg VP9 decoder. FFmpeg's VP9 encoder runs on every core at cpu-used 8 with row multi-threading, so it does less work per frame than `vp9.net` does.

### Machine

Expand Down
34 changes: 6 additions & 28 deletions src/SIPSorcery.Cli/Commands/webrtc/WebRtcVideoBenchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
// Stage 3b (--encoder av1.net): the managed SIPSorcery.AV1 (av1rt) AV1 encoder.
// Stage 3c (--encoder h264.net): the managed SIPSorcery.H264 (OpenH264 port) encoder,
// in source builds with -p:IncludeH264Net=true only.
// Stage 3d (--encoder vp9.net): the managed SIPSorcery.VP9 (libvpx port) encoder,
// in source builds with -p:IncludeVp9Net=true only.
// Stage 3d (--encoder vp9.net): the managed SIPSorcery.VP9 (libvpx port) encoder.
// Stage 4 (--decoder ffmpeg|vp8.net|h264.net|vp9.net): a decoder on its own. A short clip is
// encoded first (untimed), then only the
// decoding of it, looped, is timed.
Expand Down Expand Up @@ -47,6 +46,7 @@
// (SIPSorcery.VP9 isn't packaged yet). h264.net's --threads 0
// leaves the threads to the codec, by frame size.
// 29 Nov 2026 Claude vp9.net's --threads help for its row based multi-threading.
// 04 Dec 2026 Claude vp9.net is always built in, now that SIPSorcery.VP9 is packaged.
//
// License:
// BSD 3-Clause "New" or "Revised" License, see included LICENSE.md file.
Expand Down Expand Up @@ -107,16 +107,10 @@ public sealed class WebRtcVideoBenchCommand : CommandBase
#endif

/// <summary>
/// The --encoder and --decoder name of the managed SIPSorcery.VP9 codec. It is compiled in only
/// when the tool is built from source with -p:IncludeVp9Net=true (see the project file).
/// The --encoder and --decoder name of the managed SIPSorcery.VP9 codec.
/// </summary>
private const string VP9_NET_STAGE = "vp9.net";

#if !VP9NET
private const string VP9_NET_NOT_BUILT = "vp9.net is only in source builds of the tool made with -p:IncludeVp9Net=true: " +
"SIPSorcery.VP9 isn't packaged yet.";
#endif

/// <summary>Seconds of frames (at --fps, at least 30 frames) in the clip the --decoder stage loops.</summary>
private const int DECODE_CLIP_SECONDS = 2;

Expand Down Expand Up @@ -204,7 +198,7 @@ public override Command Build()
Description = "The pipeline stage to test: none (packetise only), ffmpeg (SIPSorceryMedia.FFmpeg in-process encoder), " +
"ffmpeg-piped (external ffmpeg process), vp8.net (managed Vpx.Net codec), av1.net (managed SIPSorcery.AV1 " +
"encoder), h264.net (managed SIPSorcery.H264 encoder, in source builds made with -p:IncludeH264Net=true " +
"only) or vp9.net (managed SIPSorcery.VP9 encoder, in source builds made with -p:IncludeVp9Net=true only). " +
"only) or vp9.net (managed SIPSorcery.VP9 encoder). " +
"The none stage packetises a frame " +
"sized from --bitrate/--fps, so it is independent of resolution (width/height are reported for context only).",
DefaultValueFactory = _ => "none"
Expand Down Expand Up @@ -264,8 +258,8 @@ public override Command Build()
{
Description = "Benchmark a decoder instead of an encoder: ffmpeg (SIPSorceryMedia.FFmpeg, any codec), vp8.net " +
"(managed Vpx.Net, VP8 only), h264.net (managed SIPSorcery.H264, H264 only, in source builds made with " +
"-p:IncludeH264Net=true only) or vp9.net (managed SIPSorcery.VP9, VP9 only, in source builds made with " +
"-p:IncludeVp9Net=true only). A short --codec clip is encoded first, untimed, by --encoder (left as " +
"-p:IncludeH264Net=true only) or vp9.net (managed SIPSorcery.VP9, VP9 only). A short --codec clip is " +
"encoded first, untimed, by --encoder (left as " +
"none, ffmpeg, the native encoders a remote WebRTC peer most likely uses; or vp8.net, av1.net, h264.net or " +
"vp9.net), then " +
"only the decoding of it, looped, is timed. Decoded pictures are converted to BGR as a receiver's are."
Expand Down Expand Up @@ -439,17 +433,13 @@ private static int Run(string? preset, int width, int height, int fps, int durat
#endif

case VP9_NET_STAGE:
#if VP9NET
if (codecEnum != VideoCodecsEnum.VP9)
{
return WriteResult(asJson, Empty(encoder, codec, width, height, fps,
$"The vp9.net managed encoder only supports --codec vp9. Use --encoder ffmpeg for {codec.ToLowerInvariant()}."),
ExitCodes.InvalidArgument);
}
return RunVp9Encode(width, height, fps, durationSeconds, bitrate, codec, tuning, asJson, logger, ct);
#else
return WriteResult(asJson, Empty(encoder, codec, width, height, fps, VP9_NET_NOT_BUILT), ExitCodes.InvalidArgument);
#endif

case "ffmpeg":
return RunNativeFfmpegEncode(width, height, fps, durationSeconds, bitrate, codec, codecEnum, ffmpegPath, tuning, asJson, logger, ct);
Expand Down Expand Up @@ -638,7 +628,6 @@ private static int RunH264Encode(int width, int height, int fps, int durationSec
};
#endif

#if VP9NET
/// <summary>
/// Stage 3d: the managed SIPSorcery.VP9 encoder (a port of libvpx's realtime VP9 encoder), set up as
/// libwebrtc sets up libvpx (CBR, speed 7, cyclic refresh, row based multi-threading), on --threads
Expand Down Expand Up @@ -667,7 +656,6 @@ private static int RunVp9Encode(int width, int height, int fps, int durationSeco
// fast the loop runs. --threads sets the encoder's and the decoder's threads (0: the codec's choice).
private static SIPSorcery.VP9.VP9Codec CreateVp9NetCodec(int fps, int bitrate, int threads) =>
new(targetBitrateKbps: Math.Max(1, bitrate / 1000), threads: Math.Clamp(threads, 0, 64)) { FrameRate = fps };
#endif

/// <summary>
/// Stage 4 (--decoder): a decoder on its own. A clip of <see cref="DECODE_CLIP_SECONDS"/> of
Expand All @@ -688,12 +676,6 @@ private static int RunDecode(string decoderName, string encoderName, int width,
{
return WriteResult(asJson, Empty(stage, codec, width, height, fps, H264_NET_NOT_BUILT), ExitCodes.InvalidArgument);
}
#endif
#if !VP9NET
if (decoderName == VP9_NET_STAGE || encoderName.Trim().Equals(VP9_NET_STAGE, StringComparison.OrdinalIgnoreCase))
{
return WriteResult(asJson, Empty(stage, codec, width, height, fps, VP9_NET_NOT_BUILT), ExitCodes.InvalidArgument);
}
#endif
if (decoderName != "ffmpeg" && decoderName != "vp8.net" && decoderName != H264_NET_STAGE && decoderName != VP9_NET_STAGE)
{
Expand Down Expand Up @@ -788,9 +770,7 @@ private static int RunDecode(string decoderName, string encoderName, int width,
#if H264NET
H264_NET_STAGE => new SIPSorcery.H264.H264Codec(),
#endif
#if VP9NET
VP9_NET_STAGE => CreateVp9NetCodec(fps, bitrate, tuning.Threads),
#endif
_ => new FFmpegVideoEncoder(),
};

Expand Down Expand Up @@ -905,12 +885,10 @@ private static List<byte[]> EncodeClip(string clipEncoder, int encWidth, int enc
encode = raw => encoder.EncodeVideo(encWidth, encHeight, raw, VideoPixelFormatsEnum.I420, codecEnum);
break;
#endif
#if VP9NET
case VP9_NET_STAGE:
encoder = CreateVp9NetCodec(fps, bitrate, tuning.Threads);
encode = raw => encoder.EncodeVideo(encWidth, encHeight, raw, VideoPixelFormatsEnum.I420, codecEnum);
break;
#endif
default:
{
Dictionary<string, string>? extraOptions = null;
Expand Down
11 changes: 6 additions & 5 deletions src/SIPSorcery.Cli/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ its [README](../../Codecs/SIPSorcery.H264/README.md)) and is never packaged, so
out. The script builds the CLI from source with `-p:IncludeH264Net=true` to measure it, and
`-SkipH264Net` leaves it out.

`vp9.net`, the managed libvpx VP9 port, isn't packaged yet either. The script builds the CLI with
`-p:IncludeVp9Net=true` to measure it, and `-SkipVp9Net` leaves it out.
`vp9.net`, the managed libvpx VP9 port, is in the published tool. `-SkipVp9Net` leaves its columns out.

The WebRTC pipeline table (`loopback`, ffmpeg encoder and decoder, H264 by default):

Expand Down Expand Up @@ -97,7 +96,7 @@ Useful parameters (all optional):
| `-FfmpegPath` | (PATH) | FFmpeg shared-library directory. |
| `-OutputDir` | `./results` | Where `results.json` and `RESULTS.md` are written. |
| `-SkipH264Net` | off | Leaves out the `h264.net` columns and builds the CLI without SIPSorcery.H264, as it is published. |
| `-SkipVp9Net` | off | Leaves out the `vp9.net` columns and builds the CLI without SIPSorcery.VP9. |
| `-SkipVp9Net` | off | Leaves out the `vp9.net` columns. |
| `-Codecs` | (all) | Only these codecs' encode and decode columns (`vp8`, `vp9`, `h264`, `h265`, `av1`), to re-measure some of them. |

The CLI is published to a temp directory once at the start, then invoked per run, so build/JIT noise
Expand All @@ -109,14 +108,16 @@ To measure one cell by hand, run the same command the script does, for example:
dotnet run -c Release --project src/SIPSorcery.Cli -- webrtc video-bench --preset 1080p --decoder ffmpeg --codec av1 --json
```

The `h264.net` and `vp9.net` cells need their source build flags:
The `h264.net` cells need the source build flag:

```powershell
dotnet run -c Release --property:IncludeH264Net=true --project src/SIPSorcery.Cli -- webrtc video-bench --preset 1080p --encoder h264.net --json
```

The `vp9.net` cells need no flag:

```powershell
dotnet run -c Release --property:IncludeVp9Net=true --project src/SIPSorcery.Cli -- webrtc video-bench --preset 1080p --encoder vp9.net --codec vp9 --json
dotnet run -c Release --project src/SIPSorcery.Cli -- webrtc video-bench --preset 1080p --encoder vp9.net --codec vp9 --json
```

## Output
Expand Down
5 changes: 2 additions & 3 deletions src/SIPSorcery.Cli/benchmarks/run-video-bench.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
h264.net, the managed OpenH264 port, is for educational use only and is never packaged, so the
published tool leaves it out. This script publishes the CLI from source with
-p:IncludeH264Net=true to measure it; -SkipH264Net leaves it out. vp9.net, the managed libvpx VP9
port, isn't packaged yet either: -p:IncludeVp9Net=true puts it in, and -SkipVp9Net leaves it out.
port, is in the published tool; -SkipVp9Net leaves its columns out.

-Codecs limits the encode and decode tables to some codecs (vp8, vp9, h264, h265, av1), to
re-measure those columns only.
Expand Down Expand Up @@ -88,7 +88,7 @@ param(
[string] $OutputDir = (Join-Path $PSScriptRoot 'results'),
# Leaves out the h264.net columns, and builds the CLI as it is published, without SIPSorcery.H264.
[switch] $SkipH264Net,
# Leaves out the vp9.net columns, and builds the CLI without SIPSorcery.VP9.
# Leaves out the vp9.net columns.
[switch] $SkipVp9Net,
# Only these codecs' encoders and decoders (vp8, vp9, h264, h265, av1); all of them when empty.
[string[]] $Codecs = @()
Expand Down Expand Up @@ -147,7 +147,6 @@ $binDir = Join-Path ([System.IO.Path]::GetTempPath()) 'sipsorcery-vbench-bin'
Write-Host "Publishing CLI (Release) ..." -ForegroundColor Cyan
$publishArgs = @($proj, '-c', 'Release', '-o', $binDir, '--nologo')
if (-not $SkipH264Net) { $publishArgs += '-p:IncludeH264Net=true' }
if (-not $SkipVp9Net) { $publishArgs += '-p:IncludeVp9Net=true' }
dotnet publish @publishArgs | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Publishing the CLI failed." }
$exe = Join-Path $binDir 'SIPSorcery.Cli.exe'
Expand Down
Loading
Loading