TensorStack.Media
0.15.1
Prefix Reserved
dotnet add package TensorStack.Media --version 0.15.1
NuGet\Install-Package TensorStack.Media -Version 0.15.1
<PackageReference Include="TensorStack.Media" Version="0.15.1" />
<PackageVersion Include="TensorStack.Media" Version="0.15.1" />
<PackageReference Include="TensorStack.Media" />
paket add TensorStack.Media --version 0.15.1
#r "nuget: TensorStack.Media, 0.15.1"
#:package TensorStack.Media@0.15.1
#addin nuget:?package=TensorStack.Media&version=0.15.1
#tool nuget:?package=TensorStack.Media&version=0.15.1
TensorStack.Media
Loading, saving and streaming of images, audio and video, using SkiaSharp, OpenCvSharp and FFmpeg.
Nuget Package
Setup
Video and audio use FFmpeg, set its location and the temporary directory once at startup (defaults to ffmpeg.exe, ffprobe.exe and Temp in the working directory)
MediaManager.Initialize("ffmpeg.exe", "ffprobe.exe", "Temp");
An FFmpeg failure throws with its error output, a cancelled operation stops the FFmpeg process.
Images
ImageInput
ImageInput extends ImageTensor with loading and saving images to disk
var image = new ImageInput("Input.png");
var resized = new ImageInput("Input.png", 1024, 1024, ResizeMode.Crop);
await image.SaveAsync("Output.png");
// Any ImageTensor can be saved directly
await imageTensor.SaveAsync("Output.png");
Video
VideoInput
VideoInput extends VideoSequence, a buffered video with all frames and audio in memory
var video = new VideoInput("Input.mp4");
Console.WriteLine($"{video.FrameCount} frames @ {video.FrameRate}fps");
await video.SaveAsync("Output.mp4");
VideoInputStream
VideoInputStream is a video backed by a file stream, loading frames on demand so long videos can be processed one frame at a time
var stream = await VideoInputStream.CreateAsync("Input.mp4");
await foreach (var frame in stream.GetAsync())
{
// Process frame
}
// Or chain a pipeline and save the result, with the source audio track
await pipeline.RunAsync(new UpscaleStreamOptions { Stream = stream.GetAsync() }).SaveAsync("Output.mp4", audioSourceFile: stream.SourceFile);
// Process every frame with buffered read, process and write, the audio track is written in the same pass
var result = await stream.ProcessAsync("Output.mp4", async frame => await ProcessFrameAsync(frame));
// Read frames into a VideoSequence, with the audio trimmed to the frames read
var sequence = await stream.GetSequenceAsync(512, 512, frameRateOverride: 24, ResizeMode.Crop, maxFrames: 81, includeAudio: true);
// Replace the audio track with another file or a mixed AudioTimeline
result = await result.AddAudioAsync("Music.mp3");
HasAudio/Audio- The audio track info, null when the video has no audio
VideoSequence
GetSequence- A range of frames by index or time, the audio is trimmed to match
VideoManager
LoadVideoInfoAsync- Video info and thumbnailLoadVideoSequenceAsync- Load aVideoSequence, with optional size and frame rate overridesWriteVideoStreamAsync- Write a frame stream to a file, with optional frame processor and audio source
Video encoding
Video is written by FFmpeg as H.264 (MP4) with the first encoder that works at the output size, the result is cached per size:
NVIDIA h264_nvenc, AMD h264_amf, Intel h264_qsv, then the CPU encoders libopenh264 and mpeg4 (MPEG-4 Part 2, for sizes the H.264 encoders can't take).
Odd sizes are rounded down to even. An audio track is encoded as AAC and padded or trimmed to the video length, in the same pass as the frames.
OpenCvSharp is used for reading video frames only.
Audio
AudioInput
AudioInput extends AudioTensor with loading and saving audio to disk. Audio is interleaved [Samples, Channels], see AudioTensor layout
// Any audio or video file, converted to the sample rate and channels (default 16 kHz mono)
var audio = await AudioInput.CreateAsync("Input.mp3", sampleRate: 44100, channels: 2);
await audio.SaveAsync("Output.wav");
// Any AudioTensor can be saved, resampled or downmixed
await audioTensor.Resample(24000).ToMono().SaveAsync("Output.wav");
AudioInputStream
AudioInputStream is audio backed by a file, loading data on demand
SampleRate/Channels/Duration/AudioCodec- The audio stream infoGetAsync- Load asAudioInput, at a sample rate and channel count or the source format when not setMoveAsync/CopyAsync- Move or copy the source fileCreateAsync- Open a file
AudioManager
LoadInfoAsync- Audio stream info, null when the file has no audioLoadTensorAsync- Load the audio track of an audio or video file as anAudioTensor, decoded as 32-bit floatSaveAudio- Save anAudioTensorAddAudioAsync- Add the audio track of a file, or a mixedAudioTimeline, to a video. The video is not encoded again, the audio is encoded as AAC and padded or trimmed to the video length, a source with no audio is skippedCreateAudioTimelineAsync- Mix anAudioTimelineof segments to a file
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows10.0.17763 is compatible. |
-
net10.0-windows10.0.17763
- OpenCvSharp5 (>= 5.0.0.20261109)
- OpenCvSharp5.runtime.win (>= 5.0.0.20261109)
- SkiaSharp (>= 4.155.0)
- System.Linq.Async (>= 7.0.1)
- TensorStack.Common (>= 0.15.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on TensorStack.Media:
| Package | Downloads |
|---|---|
|
TensorStack.WPF
Package Description |
|
|
TensorStack.StableDiffusionCpp
.NET Wrapper API for StableDiffusion.cpp |
|
|
TensorStack.LlamaCpp
.NET Wrapper API for llama.cpp |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.15.1 | 0 | 11/21/2026 |
| 0.15.0 | 107 | 11/18/2026 |
| 0.14.14 | 99 | 11/17/2026 |
| 0.14.13 | 110 | 11/16/2026 |
| 0.14.12 | 96 | 11/15/2026 |
| 0.14.11 | 93 | 11/15/2026 |
| 0.14.10 | 105 | 11/14/2026 |
| 0.14.9 | 107 | 11/13/2026 |
| 0.14.8 | 96 | 11/10/2026 |
| 0.14.7 | 96 | 11/8/2026 |
| 0.14.6 | 107 | 11/5/2026 |
| 0.14.5 | 113 | 11/1/2026 |
| 0.14.4 | 191 | 10/29/2026 |
| 0.14.3 | 115 | 10/28/2026 |
| 0.14.2 | 141 | 10/20/2026 |
| 0.14.1 | 135 | 10/16/2026 |
| 0.13.13 | 127 | 10/11/2026 |
| 0.13.12 | 114 | 10/10/2026 |
| 0.13.10 | 140 | 10/6/2026 |
| 0.13.9 | 114 | 10/5/2026 |