Repository navigation
MediaToolkit.NET 1.0.0
The first stable release. It follows a full audit of the 0.3.1 code for bugs,
resource leaks and vulnerabilities (AUDIT.md in the repository holds every
finding, with its evidence). Each fix was written test first: a test that
failed for the stated reason, then the change, then the test passing. The
findings were reproduced on Windows 11 and on Debian 13 under WSL before they
were fixed, not only read from the code.
From 1.0.0 the public API follows semantic versioning. This release does change
behaviour in four places, listed first, because each one can break a caller that
worked before.
Changes that can break existing code
FFmpeg inputs are local files by default
FFmpegProber, FFmpegMediaReader and FFmpegTranscoder now open local files
and pipes only. A path that came from somebody else could otherwise make the
process connect to a host of that somebody's choosing, or read other files
through a playlist.
- Network URLs (
http://,https://,rtsp://,tcp://,udp://, and
every protocol butfile,pipe,cryptoanddata) are refused with
avformat_open_input(...): Invalid argument, without connecting. - Playlists (HLS, DASH,
concat) are refused: they name other files to read. FFmpegPlayerand capture devices are not restricted.
To open URLs on purpose, allow them once at start-up
(FFmpegDemuxer.AllowNetworkByDefault = true) or for one reader through
MediaReaderOptions.DemuxerOptions["protocol_whitelist"]. A playlist can be
opened with FFmpegDemuxer.Open(url, allowPlaylists: true). Examples are in the
README. GStreamer and mpv accept URLs as before.
Transcoders write to a partial file
All three transcoders now write .<name>.partial-<id><ext> beside the output and
rename it over the output only when the job has finished (PartialOutput).
- An output path that is a link to an input no longer overwrites the input.
With 0.3.1 an FFmpeg or mpv job through a symbolic link replaced the input with
its own output and reported success, and a GStreamer job emptied it. - A job that fails or is refused no longer deletes a file that was already at
the output path. - The output directory must now allow creating a file; a cancelled or failed job
removes its partial file.
Native library search is narrower
- The development convenience of walking up from the application folder to a
src/FFMpeg/<platform>folder now applies only below a folder that holds
MediaToolkit.NET.slnx. On an installed application the walk reached folders
other users may write to, which allowed a planted DLL to be loaded. - Relative and empty entries of
PATHare no longer used, and on Windows the
loader no longer falls back to the default search order, which includes the
current directory.
Small changes of contract
MpvPlayersetsytdl=noandload-scripts=noby default; put them back
throughMpvPlayer.Optionsif you rely on them.MpvFilterChain.Lavfireturnslavfi=graph=%N%...instead oflavfi=[...],
which a]inside the chain would end early.- Pushing planar audio with more channels than a frame view can hold (8) to a
filter graph throwsArgumentException. Ole32.InitializereturnstrueforS_FALSEas well, since that call must be
balanced too.
Fixed
Crashes and memory safety
- GStreamer read past a short buffer. The planes of a video frame came from
the caps alone; a buffer shorter than they describe aborted the process.
FrameBounds.FitsInnow checks every frame against its buffer, in the
GStreamer, DirectShow, Media Foundation, V4L2 and AVFoundation producers.
Along the way: a bottom-up Media Foundation picture is addressed from its last
row, V4L2 skips buffers the driver flagged as incomplete, and AVFoundation
skips a buffer whose lock failed. MpvPlayer: an access violation whenStop,PauseorVolumeran while
another thread disposed the player. Native calls now run under a read lock and
the handle is destroyed under the write lock.FFmpegPlayer.Seekwhile paused used the decoder from two threads at once; the worker
applies seeks now.Disposefrom inside a frame handler waited out a two-second join and then
freed the media under the running worker; the worker closes it when it
leaves.- A read blocked on the network held
Disposefor the whole timeout; the
input is opened throughavio_open2with an interrupt callback, and
FFmpegDemuxer.InterruptandClearInterruptare public. Playafter the end of the stream no longer drops its cancellation source
without disposing it.
- A subscriber that throws from
Failedended the process on every backend's
worker thread and native callback. They are raised through
SafeEvents.RaiseFailed.
Wrong output
- FFmpeg audio frames carried the format the decoder reported at open, not
the frame's own: a stream whose audio starts later read as0 Hz, 0 ch, and one
that changes rate or channels mid-way described its frames wrongly. The format
now comes from each frame, andFFmpegMediaReaderrebuilds its conversion graph
when it changes. TryReadAton MPEG-TS returned the first key frame after the requested
time; it now seeks back until the frame on screen at that time is the one read.- Transcoding audio from MP2 failed, because the check compared the decoded
frame with the container's sample format. A timestamp that jumps back is
repaired instead of reaching the muxer, and a video that changes size part way
through is rebuilt for the new size. - Encoder options nobody recognised vanished. FFmpeg and mpv now report each as
a warning inTranscodeResult.Warnings. WasapiRenderer.Writewaited for ever when the endpoint had not been
started and the data was longer than the free buffer.
Resource leaks
FFmpegDemuxer.Open,FFmpegRecorder(constructor and stream setup) and the
DirectShowGraphconstructor release what they hold when they fail.DirectShowGraphkept every wrapper it ever handed out until the graph was
disposed; wrappers now remove themselves, andDescribereleases what it
enumerates.- V4L2 unmaps buffers mapped before a failure and opens the device with
O_CLOEXEC. - The DirectShow property reader clears a variant that is not a string.
- COM initialisation is balanced on the WASAPI and Media Foundation capture
threads. - mpv's argument vector is allocated with
NativeMemory, and zeroed: a failure
part way through the oldstackallocloop freed garbage.
New public API
PartialOutput(Abstractions): the partial file a job writes before the rename.FrameBounds.FitsIn(Abstractions): checks a frame's planes against its buffer.SafeEvents.RaiseFailed(Abstractions): raises an event without letting a
subscriber's exception through.FFmpegDemuxer.AllowNetworkByDefault,Open(..., allowPlaylists, allowNetwork),
Interrupt()andClearInterrupt().
Not covered, and why
The audit lists these in AUDIT.md; they could not be reproduced or tested
without hardware, or without a Mac:
- WASAPI, Media Foundation, V4L2, ALSA and PulseAudio teardown: the worker thread
is joined with a two-second timeout and the native objects are then freed, so a
handler that takes longer, or a device that stops answering, can still free them
under the worker.FFmpegPlayerandMpvPlayerno longer have this. - A capture whose loop failed still reports
IsRunninguntilStopis called
(WASAPI, V4L2, ALSA, PulseAudio, Media Foundation). - AVFoundation and AudioQueue on macOS: a callback in flight during
Dispose, and
restarting a capture afterStop. The macOS code changed in this release (frame
checks,Failedhandling) and has never been run, as before. - A connect that is already in progress inside
FFmpegDemuxer.Opencannot be
interrupted; passrw_timeoutthroughDemuxerOptions. - The Media Foundation recorder does not check a frame's format against its
stream's. FFmpegPlayer.Stopinterrupts network reads, but the prober, the reader and the
transcoder have no interrupt of their own.
Verified by running
- Debian 13 under WSL, FFmpeg 7.1.5, GStreamer 1.26.2, libmpv 2.5: 213 unit tests
and 124 integration tests pass. - Windows 11: 213 unit tests and 107 integration tests pass, 15 skip (GStreamer is
Linux-only). The DirectShow graph (ds-filters,ds-grabon a bottom-up H.264
file), device enumeration, WASAPI capture, Media Foundation audio recording and
camera capture were also run by hand after the changes to them. - Races are tested in a child process (
tests/MediaToolkitNet.CrashProbe), since
the failures they look for end the process. The player seek race was run 15
times in a row, the mpv one three. - Some integration tests need the
ffmpegprogram to make their media: it is found
inMEDIATOOLKITNET_FFMPEG_DIRor onPATH.
Not run: FFmpeg 8 and 9 transcoding, mpv playback, the macOS backend, and the V4L2,
ALSA and PulseAudio paths on Linux, as in 0.3.1.