When you download a video from the internet, you may see file types such as MP4, MP3, MPEG and WebM. You may also hear terms such as codec, container, video stream, audio stream and FFmpeg. These terms can seem confusing at first. This article explains these concepts from the beginning and shows how they fit together inside a modern YouTube downloader.
What Is a Video File?
A video is essentially a sequence of images displayed rapidly one after another. For example, a video running at 30 frames per second displays approximately 30 individual frames every second. A ten-second video at 30 frames per second therefore contains about 300 frames.
A video also normally contains audio. The audio may include speech, music, sound effects and other sounds. Additional information such as duration, encoding information and other metadata may also be stored with the media.
Video file ├── Video stream ├── Audio stream └── Metadata
Why Does Video Need Compression?
Uncompressed video requires a huge amount of storage. A Full HD frame contains 1920 × 1080 pixels, and a video may contain 30 or 60 frames every second. Storing every frame without compression would therefore produce extremely large files.
Video compression reduces the amount of data required to store and transmit video. Instead of storing every pixel of every frame independently, compression techniques can describe similarities and changes between frames.
What Is a Codec?
The word codec comes from coder and decoder. A codec is technology used to encode media into a compressed form and decode it again for playback.
Common video codecs include H.264, H.265 or HEVC, VP9 and AV1. Common audio codecs include AAC, Opus and MP3.
Raw video ↓ Video codec ↓ Compressed video
A codec is not the same thing as a container. This distinction is important when understanding MP4 and other media formats.
What Is a Container?
A container is a file format that organizes one or more media streams together. You can think of a container as a box that holds the video stream, audio stream and related metadata.
MP4 container ├── Video stream ├── Audio stream └── Metadata
Common multimedia containers include MP4, WebM, MKV, AVI and MOV. The container tells a media player how the different streams are organized, but the container itself does not define the exact compression codec used for every stream.
What Is MP4?
MP4 is a widely used multimedia container format. Its usual file extension is .mp4. An MP4 file can contain video, audio and metadata.
A common combination is H.264 video with AAC audio inside an MP4 container. This combination is widely supported by web browsers, smartphones, computers, televisions and media players.
MP4 ├── H.264 video └── AAC audio
What Is MPEG?
MPEG stands for Moving Picture Experts Group. It refers to a family of standards related to digital audio and video. MPEG standards have been used for video compression, audio compression and multimedia systems.
MP4 is associated with the MPEG-4 family, but MP4 and MPEG are not the same thing. MPEG is a family of standards, while MP4 is a multimedia container format.
What Is MP3?
MP3 is primarily an audio format. An MP3 file normally contains audio rather than video. It is commonly used for music, speech and other audio content.
MP3 ↓ Audio
This makes MP3 fundamentally different from MP4. MP4 is a multimedia container that can contain both video and audio, while MP3 is primarily used for audio.
Video Streams and Audio Streams
Modern online video services do not always provide video and audio as one single file. Video and audio can be delivered as separate streams.
Video stream └── 1080p video Audio stream └── Audio
When separate streams are used, a downloader may need to download both streams and combine them into a final media file.
Why Can Video and Audio Be Separate?
Modern video platforms can use adaptive streaming. Different video qualities and audio streams can be provided independently so that the streaming system can select appropriate media for a device and network connection.
Video ├── 360p ├── 480p ├── 720p └── 1080p Audio ├── Lower bitrate ├── Medium bitrate └── Higher bitrate
What Is FFmpeg?
FFmpeg is a powerful open-source multimedia framework used for processing audio and video. It can perform operations such as encoding, decoding, conversion, filtering and combining media streams.
For example, if a downloader has a video stream and an audio stream, FFmpeg can combine them into a single media container when the streams are compatible with the desired output.
Video stream + Audio stream ↓ FFmpeg ↓ Combined MP4
What Is Muxing?
Muxing means combining multiple media streams into a single container. For example, an H.264 video stream and an AAC audio stream can be placed together inside an MP4 container.
H.264 video + AAC audio ↓ Muxing ↓ video.mp4
The opposite operation is called demuxing, where streams are separated from a container.
How Does a YouTube Downloader Work?
A modern YouTube downloader does more than simply copy a video file. It needs to inspect the available media formats, select the requested quality, download the required streams and, when necessary, combine them into the requested output format.
User ↓ Next.js Frontend ↓ FastAPI Backend ↓ Background Worker ↓ yt-dlp ↓ YouTube
Step 1: The User Provides a YouTube URL
The process begins when a user enters a YouTube URL into the downloader. The Next.js frontend sends the URL to the backend API for processing.
Step 2: The Backend Analyzes the Video
The backend uses yt-dlp to inspect the supplied URL and discover information about the video and available formats. This can include the title, duration, thumbnail, available resolutions, formats and media codecs.
Step 3: The User Selects a Quality
The frontend can present available quality options such as 360p, 480p and 720p. The user selects the desired output before starting the download.
Step 4: A Background Job Is Created
Downloading and processing a large video can take time. Instead of keeping an HTTP request busy during the entire operation, the application creates a background job.
FastAPI ↓ Create download job ↓ Redis ↓ Celery Worker
This allows the web request and the long-running download task to have separate responsibilities.
Step 5: yt-dlp Downloads the Media
The Celery worker uses yt-dlp to retrieve the selected media. Depending on the available formats, the required video and audio streams may be downloaded separately.
Step 6: FFmpeg Combines the Streams
When separate streams are required, yt-dlp can use FFmpeg to combine them into the requested output container. For an MP4 download, the final file can contain the selected video and audio streams together.
720p video + Audio ↓ FFmpeg ↓ Final MP4
Step 7: The Download Job Is Updated
The background worker updates the download job as the operation progresses. A simplified job lifecycle is:
PENDING ↓ PROCESSING ↓ COMPLETED
If an error occurs, the job can instead move to a FAILED state.
Step 8: The User Receives the Final File
Once processing is complete, the final media file is made available to the user. The browser can then download the completed file.
Where Does PostgreSQL Fit?
PostgreSQL is used to store information about download jobs rather than storing the video itself. A job record can contain information such as the job ID, task ID, URL, selected format, status, file path, error information and timestamps.
PostgreSQL └── Download job information Redis └── Task/message communication Celery └── Background task execution yt-dlp └── Media retrieval FFmpeg └── Media processing File storage └── Downloaded media file
MP3, MP4, MPEG and FFmpeg: The Difference
- MP3 is primarily an audio format.
- MP4 is a multimedia container format.
- MPEG is a family of multimedia standards.
- FFmpeg is software used to process audio and video.
What Actually Happens When You Download an MP4?
When a user selects Download as MP4, the source does not necessarily provide one ready-made MP4 file containing everything required. The downloader may need to discover the available streams, select the appropriate video and audio, download them and combine them into an MP4 container.
Discover ↓ Select ↓ Download ↓ Combine / Mux ↓ Store ↓ Deliver
The Complete Architecture
The complete downloader architecture can be summarized as a set of separate components, with each component responsible for a specific part of the process.
User ↓ Next.js Frontend ↓ FastAPI Backend ↓ Redis ↓ Celery Worker ↓ yt-dlp ↓ YouTube ├── Video stream └── Audio stream ↓ FFmpeg ↓ Final MP4 ↓ Storage ↓ User
Final Takeaway
A video file is more than a collection of images. Modern video commonly consists of compressed audio and video streams organized inside a container. Understanding the difference between codecs, containers, streams and multimedia tools makes it much easier to understand how online video platforms and downloaders work.
Our YouTube downloader follows this same basic process. The Next.js frontend provides the user interface, FastAPI manages API requests, Redis and Celery handle background jobs, yt-dlp retrieves the available media streams, and FFmpeg can combine compatible streams into the final downloadable file.
Instead of thinking that a downloader simply copies a YouTube video, it is more accurate to think of it as a system that discovers available media streams, selects the requested quality, downloads the required streams, combines them when necessary, creates the final media file and delivers it to the user.