FFmpeg

What is FFmpeg?

FF β‡’ Fast Forward, mpeg β‡’ Moving Picture Experts Group

The MPEG group is the alliance of working groups who are behind setting many of the most important video standards being used today including the MP4 format.

πŸ’‘ MPEG stands for "Moving Picture Experts Group," and it refers to a set of standards developed by a working group of experts. The MPEG standards are focused on audio and video **compression** and **coding**. They define various methods for compressing audio and video data to enable efficient storage and transmission while maintaining acceptable quality.

MPEG standards

  1. MPEG-1: This standard was introduced in the early 1990s and is responsible for formats like MPEG-1 Audio Layer III (MP3) for audio compression and Video CD (VCD) for video storage.
  2. MPEG-2: Introduced in the late 1990s, MPEG-2 is used for digital television broadcasting, DVD videos, and some digital video broadcasting standards.
  3. MPEG-4: This standard, introduced in the late 1990s as well, is more versatile and supports various multimedia applications, including video streaming, interactive multimedia, and mobile devices. It includes codecs like H.264 (also known as AVC) and AAC (Advanced Audio Codec).
  4. MPEG-7: This standard focuses on the description of audiovisual content, enabling better searching, indexing, and retrieval of multimedia content.
  5. MPEG-21: This standard aims to provide a framework for multimedia applications and services, enabling the integration of various multimedia technologies.
  6. MPEG-DASH: Dynamic Adaptive Streaming over HTTP (DASH) is an adaptive streaming protocol based on MPEG standards, allowing for efficient video streaming over the internet.
  7. MPEG-H: MPEG-H Audio is an audio codec that supports immersive and 3D audio experiences, making it suitable for technologies like Virtual Reality (VR) and Augmented Reality (AR).

Characteristics

  • Open-source project
  • Collection of libraries and tools
  • For handling multimedia files and streams (audio/video)
  • Can use it for free β€œFree Licence” (GPL/LGPL)

Why use FFmpeg?

  • Swiss army knife of transcoding/streaming
  • Versatile (multiple functions)
  • Fast
  • Simple to run
  • Very flexible
  • Supports a very wide range of codecs, formats, devices, and protocols
  • It is still active and under development
  • It has a large community

1592580187419.jpeg

FFmpeg is commonly used in

  1. Format Conversion: FFmpeg can convert audio and video files between different formats. This is particularly useful when you need to make media content compatible with different devices, software, or platforms.
  2. Video Compression: FFmpeg includes various codecs and compression algorithms that allow you to reduce the size of video files without compromising too much on quality. This is important for efficient storage and streaming.
  3. Audio Manipulation: You can use FFmpeg to manipulate audio files by changing their formats, bit rates, sample rates, and channels. It can also apply effects, normalize audio levels, and perform other audio-related tasks.
  4. Video Editing: While FFmpeg is not a full-fledged video editing software, it can perform basic video editing tasks like cutting, trimming, merging, and concatenating video clips.
  5. Streaming: FFmpeg supports live streaming and adaptive streaming protocols, making it suitable for broadcasting live events or creating online streaming platforms.
  6. Transcoding: Transcoding involves converting media content from one codec to another. FFmpeg is often used for this purpose, especially when dealing with video platforms, streaming services, or different hardware devices that require specific codecs.
  7. Batch Processing: You can automate batch processing tasks with FFmpeg, allowing you to apply the same operation to multiple files.
  8. Command-Line Interface: FFmpeg provides a command-line interface, which gives you fine-grained control over various settings and options. This is particularly useful for advanced users and developers who want to integrate multimedia processing into scripts and applications.
  9. Customization: FFmpeg's open-source nature allows developers to modify and extend its functionality to suit specific needs. This makes it adaptable for a wide range of projects.
  10. Cross-Platform: FFmpeg is available for various operating systems, including Windows, macOS, Linux, and more. This cross-platform compatibility makes it accessible to users on different systems.

Who uses FFmpeg?

  • Video Streaming Platforms like YouTube, iTunes…
  • Media Players and Editors like VLC
  • Media asset management systems
  • Transcoders
  • Video Conversion Tools
  • Broadcasters
  • Live Streaming Services
  • Video and Audio Processing Libraries
  • Digital Signage
  • Gaming Industry
  • etc

FFmpeg Libraries

  • libavcodec β‡’ contains all the encoders and decoders that FFmpeg support
  • libavformat β‡’ has all the muxers and demuxers for dealing with various container formats like MP4, MKV, AVI, and more.
  • libavfilter β‡’ consists of a huge number of filters that you can use to modify the audio or video such as scaling, cropping, resizing, and more
  • libavdevices β‡’ support several different input and output devices
  • libavutil β‡’ contains utility functions that are used by other FFmpeg components. It includes functions for memory management, data structures, mathematics, and more
  • libswscale β‡’ is responsible for image scaling and conversion. It's often used to adapt the dimensions and color spaces of video frames
  • libswresample β‡’ handles audio resampling and conversion. It's used for adjusting audio sample rates, formats, and channels.
  • libpostproc β‡’ provides post-processing functionalities for video frames. It can be used for tasks like deinterlacing, noise reduction, and image enhancement
  • libavcformat β‡’ focuses on format conversion and supports a wide range of multimedia formats, making it useful for transcoding and format-related tasks

FFmpeg Tools

  • ffmpegβ‡’ core tool of FFmpeg and provides a comprehensive set of options for transcoding, converting, and manipulating audio and video files. It can be used to change formats, resize videos, adjust codecs, and more
  • ffplay β‡’ minimal tool for playing audio and video
  • ffprobe β‡’ analyzing multimedia files and extracting information about their formats, codecs, streams, bit rates, and more
  • ffserver β‡’ allows you to set up a multimedia streaming server. It can stream audio and video content over networks using various protocols
  • ffmpeg-avconv β‡’ is a compatibility tool that provides a similar interface to the now-deprecated avconv command. It's useful for transitioning from avconv to FFmpeg
  • ffmpeg-resampler β‡’ is a tool for audio resampling and conversion. It can be used to adjust audio sample rates and formats
  • ffmpegthumbnailer β‡’ generates thumbnails from video files. It can be used to create preview images for video content.
  • qt-faststart β‡’ rearranges the structure of MP4 or MOV files, making them suitable for streaming over the internet.
  • ffmpeg-filters β‡’ provides documentation for FFmpeg's various filters, which can be used to modify and process multimedia content.
  • ffmpeg-scaler β‡’ provides documentation for FFmpeg's image scaler, which can be used to resize and convert images.

Install FFmpeg

πŸ’‘ The FFmpeg project doesn’t offer official builds of FFmpeg for any operating system, so you can build FFmpeg yourself from the source code

Pre-built packages

1- Mac Installation

The easiest way to get FFmpeg installed is by Homebrew package manager

open your terminal and type…

brew  //to install Homebrew package manager
brew install ffmpeg  //to install ffmpeg
ffmpeg  //to check version is installed

2- Ubuntu Installation

The easiest way to get FFmpeg installed is by APT package manager open your terminal and type…

sudo apt update   //to get the latest version of apt
sudo apt install ffmpeg  //to install ffmpeg
ffmpeg  //to check version is installed

3- Windows Installation

  1. go to https://ffmpeg.org/download.html

  2. Get your executable file for Windows

  3. Choose the best build for you from

  • master builds (full or essential)
  • release builds (full or essential) Release Essential is a good choice
  1. Extract the downloaded file

  2. Add bin folder in extracted folder to PATH environment variables

  3. Type in your terminal β‡’ ffmpeg to check ffmpeg version

Screenshot 2023-08-22 093920.png

Screenshot 2023-08-22 095525.png

Screenshot 2023-08-22 095653.png


#FFprobe

It is a very powerful tool that can be used to extract and show various information about the media for example the resolution of the video, codec information, number of channels in an audio stream, etc.

How to use FFprobe

ffprobe [options] [video (name/url)]

1- Simple use

ffprobe input.mp4 // [input.mp4] may be local video or video url

Screenshot 2023-08-22 185701.png

2- Remove FFprobr banner

ffprobe -hide_banner js.mp4

Screenshot 2023-08-22 190225.png

3- logs only errors

ffprobe -v error js.mp4

4- show input format

ffprobe -v error js.mp4 -show_format

Screenshot 2023-08-22 192255.png

5- show input streams

ffprobe -v error js.mp4 -show_streams

It will show all information about input video streams (codec name - width - height - codec type - etc.)

Screenshot 2023-08-22 193809.png

5- show video packets

ffprobe -v error js.mp4 -show_packets

Screenshot 2023-08-22 194619.png

6- show video frames

ffprobe -v error js.mp4 -show_frames

Screenshot 2023-08-22 194900.png

7- Select video/audio stream

ffprobe -v error js.mp4 -show_streams -select_streams v

Screenshot 2023-08-22 204418.png

8- Format output

ffprobe -v error js.mp4 -show_streams -select_streams v -print_format json

Screenshot 2023-08-22 205046.png

9- Display a specific property

ffprobe -v error js.mp4 -show_streams -select_streams v -show_entries stream=codec_name

Screenshot 2023-08-22 205606.png

ffprobe -v error js.mp4  -show_entries format=format_long_name -print_format default

Screenshot 2023-08-22 205922.png

** if you want to remove the wrapper **

ffprobe -v error js.mp4 -show_entries format=format_long_name -print_format default=noprint_wrappers=1

Screenshot 2023-08-22 210219.png

** if you want to display only value without the key**

ffprobe -v error js.mp4 -show_entries format=format_long_name -print_format default=noprint_wrappers=1:nokey=1

Screenshot 2023-08-22 210832.png

πŸ’‘ There are many other options available; you can explore them through the official website.

#FFplay

It allows you to play various audio and video files directly from the command line without the need for a separate media player application.

How to use FFplay

ffplay [options] [input file or url]

1- Simple use

ffplay source.mp4

2- Play video without unnecessary logs

ffplay -v error source.mp4

3- Play video with specific width and height

ffplay -v error source.mp4 -x 1080 -y 900

4- Display video with no border

ffplay -v error source.mp4 -x 1080 -y 900 -noborder

5- Remove the black area around the video

ffplay -v error source.mp4 -x 1080

6- Change the window position on the screen

ffplay -v error source.mp4 -top 0 -left 0

7- display full-screen video

ffplay -v error source.mp4 -fs

8- Disable audio playback

ffplay -v error source.mp4 -an

9-Disable video playback

ffplay -v error source.mp4 -vn

10- Change displayed mode

ffplay -v error source.mp4 -showmode (waves | video | rdft)

11- Repeat the played video

ffplay -v error source.mp4  -loop 0

12- Play a specific section of a video

ffplay -ss 30 -t 10 source.mp4

13- Disable subtitles

ffplay -v error -sn source.mp4 

Shortcuts you can use while a video is playing.

- space => resume/pause
- m => mute/unmute
- f => fullscreen
- double lift click =>  fullscreen
- / or 9 => volume down
- * or 0 => volume up
- w => change mode (audio - video - waves)
- s => frame step
- β†’ => forward 10s
- ← => back 10s
- ↑ => forward 1m
- ↓ => back 1m
- Esc => quit
πŸ’‘ There are many other options available; you can explore them through the official website.