# How to Convert Audio to Video Using the Convert Project

> Learn how to convert audio to video using the Convert project. This guide explains how to wrap audio streams into MP4 or WebM video containers with the FFmpeg handler.

- Repository: [p2r3/convert](https://github.com/p2r3/convert)
- Tags: how-to-guide
- Published: 2026-02-19

---

**Yes, the Convert project supports audio-to-video conversions by leveraging the FFmpeg handler to wrap audio streams into video containers like MP4 or WebM.**

The p2r3/convert repository is a browser-based file conversion tool that utilizes WebAssembly FFmpeg to process media files directly in the client. Among its core capabilities, the project enables converting audio files into video containers, allowing workflows such as embedding WAV tracks into MP4 files for broader compatibility.

## Architecture Behind Audio-to-Video Conversions

### FFmpeg Handler Format Detection

In [`src/handlers/FFmpeg.ts`](https://github.com/p2r3/convert/blob/main/src/handlers/FFmpeg.ts), the **FFmpegHandler** class enumerates every format supported by the WebAssembly build of FFmpeg. During initialization, the handler inspects FFmpeg's codec list (lines 152-163) and classifies each entry by MIME type into categories including `audio`, `video`, or `image`. When the codec description indicates an audio codec, the handler explicitly sets the `category` property to **audio**; otherwise, it assigns **video** or alternative classifications based on the format capabilities.

### The TraversionGraph Edge

The conversion pathway is defined in [`src/TraversionGraph.ts`](https://github.com/p2r3/convert/blob/main/src/TraversionGraph.ts), which maintains a graph of allowed conversion edges between format categories. The graph includes a specific edge from `audio → video` with a cost of `1` and **no** handler restriction. Because FFmpegHandler registers both audio and video formats in its `supportedFormats` list, it satisfies the requirements for this edge and can execute cross-category conversions.

## Executing Audio-to-Video Conversions

When converting audio files to video containers, the `doConvert` method in `FFmpegHandler` constructs an FFmpeg command that accepts audio input and writes to a video container format. The generated command utilizes the concat demuxer for reliable input handling:

```typescript
["-hide_banner", "-f", "concat", "-safe", "0", "-i", "list.txt", "-f", outputFormat.internal, ...]

```

This command works for audio-only streams, producing a container file that FFmpeg classifies as a video format while preserving the original audio track without requiring video encoding.

## Code Example: WAV to MP4 Conversion

To perform an audio-to-video conversion programmatically using the Convert project's API:

```typescript
import handlers from "./handlers/index.ts";
import { TraversionGraph } from "./TraversionGraph.ts";

const graph = new TraversionGraph();
await graph.init(new Map(), handlers);

const inputFiles = [{ bytes: wavBytes, name: "sample.wav" }];
const inputFormat = { mime: "audio/wav", extension: "wav", format: "wav" };
const outputFormat = { mime: "video/mp4", extension: "mp4", format: "mp4" };

const ffmpegHandler = handlers.find(h => h.name === "FFmpeg");
const result = await ffmpegHandler.doConvert(
  inputFiles,
  inputFormat,
  outputFormat,
  []  // optional additional FFmpeg arguments
);

// result contains a FileData object with the MP4 container holding the audio

```

## Key Source Files

Understanding the implementation requires examining these critical components:

- **[`src/handlers/FFmpeg.ts`](https://github.com/p2r3/convert/blob/main/src/handlers/FFmpeg.ts)**: Implements format discovery and the `doConvert` method that executes FFmpeg commands for audio-to-video transformations.
- **[`src/TraversionGraph.ts`](https://github.com/p2r3/convert/blob/main/src/TraversionGraph.ts)**: Defines the conversion graph including the `audio → video` edge that enables cross-category conversions.
- **[`src/handlers/index.ts`](https://github.com/p2r3/convert/blob/main/src/handlers/index.ts)**: Registers the FFmpeg handler and makes it available to the conversion engine.
- **[`src/main.ts`](https://github.com/p2r3/convert/blob/main/src/main.ts)**: Orchestrates the UI and routes user selections to the appropriate handler based on the graph resolution.

## Summary

- The Convert project supports **audio-to-video conversions** through the FFmpeg WebAssembly handler.
- **[`src/handlers/FFmpeg.ts`](https://github.com/p2r3/convert/blob/main/src/handlers/FFmpeg.ts)** classifies formats during initialization and executes conversions using standard FFmpeg concat commands.
- The **`TraversionGraph`** explicitly allows `audio → video` transitions with a universal handler policy and a cost of `1`.
- Supported conversions include wrapping audio tracks into containers like **MP4**, **WebM**, and other FFmpeg-supported video formats.
- The conversion process uses the `doConvert` method with concat-based input handling for reliable audio stream packaging.

## Frequently Asked Questions

### Can Convert handle any audio format to any video format?

The Convert project supports any audio-to-video conversion where the WebAssembly build of FFmpeg supports both the input audio codec and the output video container. Common combinations like WAV to MP4 or AAC to WebM work seamlessly, but specific support depends on the codecs compiled into the WASM binary as enumerated in [`src/handlers/FFmpeg.ts`](https://github.com/p2r3/convert/blob/main/src/handlers/FFmpeg.ts).

### Does the video output contain video streams or just audio?

When converting audio to video formats, the output file is a video container (e.g., MP4) that contains only the audio stream without a visual track, unless the conversion is explicitly configured to add a static image. The default implementation in `FFmpegHandler.doConvert` packages the audio into the video container format without additional video encoding.

### Is there a performance cost for audio-to-video conversions?

According to the TraversionGraph configuration in [`src/TraversionGraph.ts`](https://github.com/p2r3/convert/blob/main/src/TraversionGraph.ts), the `audio → video` edge has a cost of `1`, representing a lightweight operation. Since this conversion primarily involves remuxing the audio stream into a different container rather than re-encoding video content, it typically executes faster than video-to-video transcoding operations.

### How does the UI determine that audio-to-video conversion is possible?

The UI logic in [`src/main.ts`](https://github.com/p2r3/convert/blob/main/src/main.ts) queries the TraversionGraph to find valid conversion paths. When a user selects an audio source file, the system checks the graph for reachable target categories. The presence of the `audio → video` edge signals that video formats are valid destinations, enabling these options in the interface dropdown menus.