FFmpeg Cheat Sheet
By Ron Royston
Table of Contents
- Compress mp4
- Trimming A Multimedia File
- Join Audio and Video Files
- Add a Watermark to a Video
- Reassembly of Transport Stream Video
HTML5 introduced native <audio> and <video> multimedia elements making audio and video enabled websites as easy as copy and paste. However since both the content and the codecs are subject to licensing issues there remains cross platform and cross browser challenges. Therefore it is recommended to serve more than one format of audio or video to reach the largest audience. FFmpeg is the tool for this job - formatting or transcoding a .wmv to .mp4, for example. This article does not focus on audio or video web development but on creating audio and video files using FFmpeg, the leading multimedia framework.
The commands below include hand selected arguments / options for quality while minimizing file size. Users are encouraged to explore the full capabilities of the FFmpeg tool.
Begin by downloading and installing FFmpeg on your system. Below are the installation steps for a Windows system. Apple and linux system users should follow the steps specific to their platform which can be found online.
- Download the FFmpeg software from https://www.ffmpeg.org/
- Install the software on your system
- Create folder C:\Program Files\ffmpeg\
- Extract the contents of the FFmpeg zip package to this folder
- Right click This PC or Computer then click Properties > Advanced System Settings > Advanced > Environment Variables
- Edit the Path variable
- Append the location of ffmpeg.exe to the list, C:\Program Files\ffmpeg\bin\
- Verify installation by opening a command line and entering ffmpeg -version
Now that you have FFmpeg installed let's look at how to do some basics - transcoding from one format to another, cutting a multimedia file, and adding a watermark to a video.
Reduce the filesize of an mp4 while maintaining good quality.
FFmpeg allows us to transcode video as well as convert video to audio only. We are using FFmpeg from the command line.
Transcode .mp4 to .webm
Convert video .mp4 to audio .mp3
Convert .gif to .mp4
Trimming A Multimedia File
In case you need to cut portions of a multimedia file FFmpeg has you covered.
Cut everything after 1 minute
Join Separate Audio and Video Files
Join separate audio and video files without re-encoding.
Add a Watermark to a Video
Want to add your logo or watermark to your video? FFmpeg can do that. For best results use a .png image format as it supports transparency. You want this watermark to be small, usually somewhere between 16 and 36px. The overlay parameters specify the x:y offset in pixels.
Add A Watermark
Reassembly of Transport Stream Video
Sometimes you find that a page source does not specify a single video file. You really want that video. A little brute force paired with FFmpeg and you got it. Open browser developer tools Control + Shift + i and click the Network tab. If you see several .ts files search for a m3u8 file. Specifically, you want the index_0 file which is the highest resolution set. This file displays each segments address. It is telling you the web address to get each transport stream segment. Download each .ts file then use FFmpeg to join then all and transcode them to .mp4.