# How you-get Handles Container Formats (WebM, MP4, and More): A Technical Deep Dive

> Explore how you-get handles WebM, MP4, and other container formats. Discover its use of MIME types, file extensions, and FFmpeg for efficient audio codec integration and streaming.

- Repository: [Mort Yao/you-get](https://github.com/soimort/you-get)
- Tags: deep-dive
- Published: 2026-03-06

---

**you-get detects container formats via MIME-type headers and file extensions, then routes downloads through FFmpeg processors that apply container-specific audio codecs and bit-stream filters to ensure proper merging and streaming.**

you-get is a popular command-line utility for downloading media from websites like YouTube and Bilibili. When handling diverse container formats such as WebM, MP4, and FLV, the tool employs a four-stage pipeline that combines HTTP header inspection, extractor routing, and FFmpeg-based post-processing as implemented in the soimort/you-get repository.

## Step 1: Detecting the Container via MIME-Type Mapping

The detection process begins immediately after URL resolution. In [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py) (lines 6-12), the `url_info` function issues a HEAD request and examines the `Content-Type` header. A dedicated mapping table converts MIME types into file extensions—`video/webm` maps to `webm` and `video/mp4` maps to `mp4`.

If the `Content-Type` header is absent, you-get falls back to parsing the `Content-Disposition` filename to determine the container format. This dual-strategy ensures reliable format identification regardless of server configuration.

## Step 2: Routing Downloads Through Extractor Pipelines

Once detected, the container format dictates which extraction path you-get follows.

### The Universal Extractor

For direct media URLs, the universal extractor in [`src/you_get/extractors/universal.py`](https://github.com/soimort/you-get/blob/main/src/you_get/extractors/universal.py) (lines 66-68) treats any URL ending with a supported extension as a direct download. The `media_exts` list explicitly includes `.webm` and `.mp4` among other formats, allowing immediate pass-through to the downloader without site-specific parsing.

### Site-Specific Extractors

For platforms like YouTube, site-specific extractors expose the container in the stream dictionary. In [`src/you_get/extractors/youtube.py`](https://github.com/soimort/you-get/blob/main/src/you_get/extractors/youtube.py) (lines 410-416), the extractor populates a `container` field with values like `'webm'` or `'mp4'`, which downstream processors use to determine handling logic.

## Step 3: Merging Multi-Part Videos with FFmpeg

When videos are split into multiple segments, you-get merges them using FFmpeg with container-aware encoding rules. The `ffmpeg_concat_av` function in [`src/you_get/processor/ffmpeg.py`](https://github.com/soimort/you-get/blob/main/src/you_get/processor/ffmpeg.py) (lines 71-77) selects audio codecs based on the target container: it forces **AAC** (`-c:a aac`) for MP4 and **Opus** (`-c:a opus`) for WebM.

Dedicated concatenation helpers further refine the process. The `ffmpeg_concat_mp4_to_mp4` routine applies bit-stream filters specific to MP4 containers, such as `-bsf:a aac_adtstoasc` (lines 200-209), ensuring compliance with the MP4 specification when joining fragmented files. As a fallback, [`src/you_get/processor/join_mp4.py`](https://github.com/soimort/you-get/blob/main/src/you_get/processor/join_mp4.py) (lines 902-919) provides additional MP4-specific joining capabilities when the concat demuxer is unavailable.

## Step 4: Streaming HLS and DASH with Container Preservation

For live streams using HLS or DASH protocols, you-get invokes `ffmpeg_download_stream` in [`src/you_get/processor/ffmpeg.py`](https://github.com/soimort/you-get/blob/main/src/you_get/processor/ffmpeg.py) (lines 40-63). This wrapper forces `-c copy` to preserve the original video stream while applying container-specific bit-stream filters. For MP4 containers, it injects `-bsf:a aac_adtstoasc`, whereas WebM streams require no additional filters.

## Practical Code Examples

The following commands demonstrate how to leverage you-get's container handling capabilities:

```bash

# Auto-detect and download WebM or MP4 files directly

you-get https://example.com/video.webm
you-get https://example.com/movie.mp4

# Download and merge split videos with automatic codec selection

you-get -m https://site.com/playlist.m3u8

# Force a specific container format when multiple options exist

you-get --format=webm https://www.youtube.com/watch?v=abc123
you-get --format=mp4 https://www.youtube.com/watch?v=abc123

# Stream live HLS content while preserving container integrity

you-get -i https://live.example.com/stream.m3u8

```

## Summary

- **you-get** identifies container formats through MIME-type mapping in [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py) and file extension analysis in the universal extractor.
- The tool routes URLs through either the universal extractor (for direct links) or site-specific extractors (like YouTube) that expose container metadata.
- FFmpeg integration applies container-specific rules: AAC for MP4, Opus for WebM, with bit-stream filters like `aac_adtstoasc` for compliant merging.
- Live streams preserve original containers via `-c copy` with conditional bit-stream filtering in the FFmpeg download wrapper.

## Frequently Asked Questions

### How does you-get determine whether a file is WebM or MP4?

you-get determines the container by inspecting the `Content-Type` HTTP header in [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py) (lines 6-12), mapping MIME types like `video/webm` to extensions. If headers are missing, it parses the `Content-Disposition` filename as a fallback.

### What audio codecs does you-get use when merging videos?

According to [`src/you_get/processor/ffmpeg.py`](https://github.com/soimort/you-get/blob/main/src/you_get/processor/ffmpeg.py) (lines 71-77), you-get forces **AAC** (`-c:a aac`) for MP4 containers and **Opus** (`-c:a opus`) for WebM containers during the merge process, ensuring codec compatibility with each format's specification.

### Can you-get handle split or fragmented video files?

Yes. When downloading multi-part videos, you-get uses `ffmpeg_concat_av` and specialized helpers like `ffmpeg_concat_mp4_to_mp4` in [`src/you_get/processor/ffmpeg.py`](https://github.com/soimort/you-get/blob/main/src/you_get/processor/ffmpeg.py) (lines 200-209). These functions apply necessary bit-stream filters such as `-bsf:a aac_adtstoasc` to produce valid output files, with [`src/you_get/processor/join_mp4.py`](https://github.com/soimort/you-get/blob/main/src/you_get/processor/join_mp4.py) (lines 902-919) serving as a fallback.

### Does you-get re-encode videos when downloading HLS streams?

No. For HLS and DASH streams, you-get invokes `ffmpeg_download_stream` with `-c copy` to preserve the original encoding (lines 40-63). It only applies container-specific bit-stream filters when necessary (for example, AAC ADTS-to-ASC conversion for MP4), avoiding quality loss from re-encoding.