---
title: "Handle an unsupported codec when remuxing video in C#"
url: https://recursiveai.org/onemedia/cookbook/handle-muxer-refusal-errors/
description: "Catch an unsupported codec when remuxing video in C#. Keep every track or fail, then retry in a container that supports the original codec."
version: "1.0.2"
---

# 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.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneMedia) · [GitHub](https://github.com/recursive-ai-oss/onemedia-csharp) · [Docs](https://recursiveai.org/onemedia/docs/) · [Download example (.zip)](https://recursiveai.org/onemedia/cookbook/handle-muxer-refusal-errors/handle-muxer-refusal-errors.zip)

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

```shell
dotnet add package RecursiveAI.OneMedia
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
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](https://recursiveai.org/onemedia/cookbook/handle-muxer-refusal-errors/handle-muxer-refusal-errors.zip) 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

```csharp
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:

```csharp
var strict = new RemuxOptions
{
    AllowDrop = false, Overwrite = true
};
```

## Related recipes

- [Write fragmented MP4](https://recursiveai.org/onemedia/cookbook/write-fragmented-mp4/)
- [Read audio and video decode timestamps](https://recursiveai.org/onemedia/cookbook/inspect-packet-timestamps/)

## 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](https://recursiveai.org/onemedia/docs/muxing/#sample-entries).

## 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](https://recursiveai.org/onemedia/docs/remux/) 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.
