GitHub

leandromoreira /ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡ฐ๐Ÿ‡ท ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ป๐Ÿ‡ณ ๐Ÿ‡ง๐Ÿ‡ท ๐Ÿ‡ท๐Ÿ‡บ

โ˜… 11,063โ‘‚ 1,010๐Ÿ‘ 267โ‘ƒ 58โ— 88โ–ค 1
+0
Daily
+0
Weekly
+9
Monthly
11,063
stars
1,010
forks
267
watchers
58
prs
88
issues
1
releases

README

๐Ÿ‡จ๐Ÿ‡ณ
๐Ÿ‡ฐ๐Ÿ‡ท
๐Ÿ‡ช๐Ÿ‡ธ
๐Ÿ‡ป๐Ÿ‡ณ
๐Ÿ‡ง๐Ÿ‡ท
๐Ÿ‡ท๐Ÿ‡บ



I was looking for a tutorial/book that would teach me how to start to use FFmpeg as a library (a.k.a. libav) and then I found the "How to write a video player in less than 1k lines" tutorial.
Unfortunately it was deprecated, so I decided to write this one.

Most of the code in here will be in C but don't worry: you can easily understand and apply it to your preferred language.
FFmpeg libav has lots of bindings for many languages like python, go and even if your language doesn't have it, you can still support it through the ffi (here's an example with Lua).

We'll start with a quick lesson about what is video, audio, codec and container and then we'll go to a crash course on how to use FFmpeg command line and finally we'll write code, feel free to skip directly to the section Learn FFmpeg libav the Hard Way.

Some people used to say that the Internet video streaming is the future of the traditional TV, in any case, the FFmpeg is something that is worth studying.

__Table of Contents__

 Intro
   video - what you see!
   audio - what you listen!
   codec - shrinking data
   container - a comfy place for audio and video
 FFmpeg - command line
   FFmpeg command line tool 101
 Common video operations
   Transcoding
   Transmuxing
   Transrating
   Transsizing
   Bonus Round: Adaptive Streaming
   Going beyond
 Learn FFmpeg libav the Hard Way
   Chapter 0 - The infamous hello world
     FFmpeg libav architecture
   Chapter 1 - timing
   Chapter 2 - remuxing
   Chapter 3 - transcoding

 Intro

 video - what you see!

If you have a sequence series of images and change them at a given frequency (let's say 24 images per second), you will create an illusion of movement.
In summary this is the very basic idea behind a video: a series of pictures / frames running at a given rate.



Zeitgenรถssische Illustration (1886)

 audio - what you listen!

Although a muted video can express a variety of feelings, adding sound to it brings more pleasure to the experience.

Sound is the vibration that propagates as a wave of pressure, through the air or any other transmission medium, such as a gas, liquid or solid.

 In a digital audio system, a microphone converts sound to an analog electrical signal, then an analog-to-digital converter (ADC) โ€” typically using pulse-code modulation (PCM) - converts the analog signal into a digital signal.

!audio analog to digital
Source

 codec - shrinking data

 CODEC is an electronic circuit or software that compresses or decompresses digital audio/video. It converts raw (uncompressed) digital audio/video to a compressed format or vice versa.
 https://en.wikipedia.org/wiki/Video_codec

But if we chose to pack millions of images in a single file and called it a movie, we might end up with a huge file. Let's do the math:

Suppose we are creating a video with a resolution of 1080 x 1920 (height x width) and that we'll spend 3 bytes per pixel (the minimal point at a screen) to encode the color (or 24 bit color, what g

Snapshot: 2026-11-04T14:00:00Z ยท Data license Apache-2.0 ยท JSON