Munzir Alradi
ع
Munzir Alradi
Home About Services Work Blog Tutorials Contact Light Tunnel العربية
Tools

Compressing Documentation Video with FFmpeg

Turning a 200 MB phone clip into something a web page can actually serve, from the command line.

2021 4 min read 15 photos
Outline of a film strip with a play arrow on a teal grid
The FFmpeg logo

ffmpeg

FFmpeg is a free and open-source software project consisting of a large suite of libraries and programs for handling video, audio, and other multimedia files and streams. it is cross-platform solution to record, convert and stream audio and video designed for command-line -based processing of video and audio files.

Download FFmpeg

what makes ffmpeg the best choice is

  • free and open source
  • working in cross platform
  • work in command line

you can download ffmpeg from [here]{https://ffmpeg.org/download.html)

The ffmpeg.org download page with the Windows, Linux and macOS builds

There is a lot of choice , I will use the one with gpl licence The one with capital are the build that are taken straight off the github source and build from there, the one with n and followed by 4.3 or something like that are the official releases that have been built and packaged up,

The gpl build circled among the release assets on github

After you click it and download the zip folder

unzip the folder

after downloading ffmpeg unzip the folder and save it in a reachable location such as c:/user/

The downloaded zip open in WinRAR: bin, doc, include and lib

now lets add it to our system path to make it recognize where its located to make it reachable from command line

unzip and add to path

to add ffmpeg to windows path follow these steps

  • open control panel then navigate to system
System circled in the control panel
  • then click advance system setting
Advanced system settings circled in the sidebar of the system page
  • then from the top bar click advance and open environment variable
The advanced tab and the environment variables button circled in system properties
  • from the system variable open path, and add new then the location of ffmpeg folder that you saved on
Editing path from the system variables, with new, the new entry and OK marked

ffmpeg in command line

to awake ffmpeg from the comand line just type ffmpeg

Typing ffmpeg prints the version and the usage line

ffmpeg -i

Using ffmpeg requires that you open a command prompt window, then type ffmpeg specific commands. Here is a typical ffmpeg command: And for video we can use ffmpeg to call ffmpeg in the command line to use it with videos The first command functuin here is

Ffmpeg –i

ffmpeg - This command tells cmd that we want to run ffmpeg commands. cmd will first look for ffmpeg.exe in one of the folders from step 6 in the Installation section. If it is found, it will attempt to run the command.

-i video.mp4 - This is an input file. We are going to be doing work on this file.

Example

ffmpeg -i video.mp4 -vn -ar 44100 -ac 1 -b:a 32k -f mp3 audio.mp3

This command has four parts:

ffmpeg -

This command tells cmd that we want to run ffmpeg commands. cmd will first look for ffmpeg.exe in one of the folders from step 6 in the Installation section. If it is found, it will attempt to run the command.

-i video.mp4 -

This is an input file. We are going to be doing work on this file.

-vn -ar 44100 -ac 1 -b:a 32k -f mp3 - These are the “arguments”.

These characters are like mini commands that specify exactly what we want to do. In this case, it is saying create an mp3 file from the input source.

  • -vn - Leave out the video stream
  • -ar 44100 - Specifies audio resolution in hertz.
  • -ac 1 - Audio channels, only 1. This is effectively “make mono”.
  • -b:a 32k - Audio bitrate, set to 32 kbps.
  • -f mp3 - Force to MP3 conversion. Without this command, ffmpeg attempts to interpret what you want based on the extension you use in the output file name.

audio.mp3- This is the output file.

ffmpeg -i Media1.mp4 reporting what is inside the file

Metadata:

Meta data give information about the creation of the file

The metadata block highlighted: brand, version and creation time

duration, stream ,

And also you can know the duration of it and bitrate Video h264 is the video codec The size is 1900*1004 The frame rate is 10 fps The size 4327 kb/s,

Duration, bitrate and h264 stream details from the same ffmpeg -i output

resize video

ffmpeg -i “media.mp4” -vf scale=1280x720 vedio-resized01.mp4

-vf means adding video filter then when need to specify what is the filter and here we used the scale filter to resize the video And then we name the output file “vedio-resized01.mp4”

Running the scale filter to take Media1.mp4 to 1280x720

The video resized from 4.95Mb to 167 KB

File properties side by side: 4.95 MB against 167 KB

Now I try to skip 5second from the video file and the compress using -ss

The next command, with -ss and -t, typed after the previous encode finishes

The Right Dimensions

YouTube allows you to upload videos of various sizes, ranging from 240p to 2160p (4K). Let’s try to understand the dimensions for each of these sizes.

  • 240p: 426x240 pixels
  • 360p: 640x360 pixels
  • 480p: 854x480 pixels
  • 720p: 1280x720 pixels
  • 1080p: 1920x1080 pixels
  • 1440p: 2560x1440 pixels
  • 2160p: 3840x2160 pixels

References

How To: Download+Install FFMPEG on Windows 10 by TroubleChute

Fab Web Basics / Day 05 / Image and Video Optimization

Type to search