Recursive AI

Handle an unsupported codec when remuxing video in C#

OneMedia is a free, open-source media library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Remuxing changes the container without re-encoding the video. Try the ZIP’s vp8.webm: OneMedia won’t write its VP8 video to MOV.

Terminal
dotnet add package RecursiveAI.OneMedia

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneMedia;
using RecursiveAI.OneMedia.Remuxing;
var options = new RemuxOptions
    { AllowDrop = false };
try
{
    Media.Remux("vp8.webm", "out.mov", options);
}
catch (MuxRefusedException ex) when
    (ex.Reason == MuxRefusalReason.UnsupportedCodec)
{
    Console.WriteLine($"MOV refused {ex.Codec}.");
}

The example is the full program below: unzip it and dotnet run. To run only the code above, paste it into Program.cs of a new dotnet new console project and dotnet run.

By default (AllowDrop = true), Remux drops an unsupported track without throwing if it can write another track; setting AllowDrop = false makes Remux throw instead.

Prints:

Text
MOV refused vp8.

The full program

C#
using RecursiveAI.OneMedia;
using RecursiveAI.OneMedia.Remuxing;
 
var strict = new RemuxOptions { AllowDrop = false };
try
{
    Media.Remux("vp8.webm", "out.mov", strict);
}
catch (MuxRefusedException ex) when (
    ex.Reason == MuxRefusalReason.UnsupportedCodec)
{
    Console.WriteLine($"MOV refused {ex.Codec}.");
    var report = Media.Remux("vp8.webm", "out.mkv", strict);
    Console.WriteLine($"MKV packets: {report.Tracks[0].Packets}");
}
Text
MOV refused vp8.
MKV packets: 5

The full program retries as Matroska (out.mkv), which can carry the original VP8 packets. Run it in a directory without a preexisting out.mkv; the path-based API refuses to replace files unless you opt in. Other refusal reasons and I/O errors aren’t swallowed by the catch filter.

Variations

If the caller owns the output files and explicitly permits replacement, use this for strict in the full program:

C#
var strict = new RemuxOptions
{
    AllowDrop = false, Overwrite = true
};

The short answer

Set RemuxOptions.AllowDrop = false and catch MuxRefusedException only when Reason is UnsupportedCodec. Return a useful error if the output container is fixed. If the caller accepts a different container, retry in one that supports the codec. In this example MOV refuses VP8, but Matroska writes all five video packets. The fallback changes the container, not the codec.

Can I just rename MKV to MP4?

No. Renaming a file doesn’t change its contents. Even a real remux with OneMedia can’t put VP8 in QuickTime MOV, but it can put VP8 in MP4. See OneMedia’s MP4-family sample entry table.

Does remuxing lose quality?

It doesn’t recompress the pictures. But keeping picture quality isn’t the same as keeping every track or all of a file’s metadata. With the default AllowDrop = true, an unsupported track can be omitted while other tracks are copied. Read the remux report if you choose that mode. For an export that requires all tracks, set AllowDrop = false so a track refusal fails instead of quietly producing a file that may be missing its video, audio or subtitles.

How do I change the codec on a video file?

If the recipient requires MOV and you can’t use VP8 in it, choose an accepted video codec such as H.264 and encode the video with a separate video encoder. OneMedia’s muxer is not that encoder. For errors other than UnsupportedCodec, don’t treat a container change as the default fix: missing codec configuration means the muxer needs initialization data, while non-monotonic DTS means packets reached it out of decode order. Inspect the typed reason before choosing whether to retry, fix the input, or return an error.

All onemedia recipes