Installing
Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.
If you already have ffmpeg installed, but not with the other libraries, use the
reinstall
command.FFmpeg options. The
-c:v
option is an alias for -vcodec
and -c:a
is an alias for -acodec
. -crf
is Constant Rate Factor.Constant Rate Factor
This method allows the encoder to attempt to achieve a certain output quality for the whole file when output file size is of less importance. This provides maximum compression efficiency with a single pass. Each frame gets the bitrate it needs to keep the requested quality level. The downside is that you can't tell it to get a specific filesize or not go over a specific size or bitrate.
Convert to MP4
When converting to an MP4, you want to use the h264 video codec and the aac audio codec because IE11 and earlier only support this combination. The FFmpeg and H.264 Encoding Guide can walk you through some of the H.264 specific options.
For maximum compatibility, use the
profile
option. This may, however, increase the bit rate quite a bit. You can disable the audio stream with the -an
option. -pix_fmt yuv420p
is for Apple Quicktime support.In this example,
input.mov
is converted to output.mp4
with maximum compatibility, with Quicktime support, and without an audio stream.Convert to WebM
VP8
libvpx
is the VP8 video encoder for ​WebM. FFmpeg and WebM Encoding Guide will walk you through webm specifics.In this example,
input.mov
is converted to output.webm
with a constant rate factor of 10
(lower is higher quality) at a bitrate of 1M
. Changing the bitrate to something lower (e.g. 700K
) will result in lower file sizes and lower quality. If your video does not have audio, you may leave off the -acodec libvorbis
part.VP9
VP9 can encode videos at half the file size 😄 ðŸ‘x8F You can check out Google's VP9 encoding guide for their recommend settings or the FFmpeg VP9 guide.
Here's an example from the FFmpeg guide:
And here's Google's 'Best Quality (Slowest) Recommended Settings'. You need to run the first line(s). It will create a log file (and warn you the out.webm is empty). On the second pass, the video will be output.
Support
As of January 2015, all major browsers support MP4.
Data current as of May 2019. Sources:
- jwplayer's research
- caniuse for AV1
- caniuse for MPEG-4/H.264
- caniuse for HEVC/H.265
- caniuse for WebM
Browser | AV1 | H264 | H265 | VP8 | VP9 | AAC | MP3 | VORBIS | OPUS |
---|---|---|---|---|---|---|---|---|---|
Chrome for Desktop | 70 | 30 | - | 30 | 30 | 30 | 30 | 30 | 33 |
Chrome for Android | - | 30 | - | 30 | 30 | 30 | 30 | 30 | - |
IE | - | 9 | 101 | - | - | 9 | 9 | - | - |
IE Mobile | - | 10 | - | - | - | 10 | 10 | - | - |
Edge | 75 | 12 | 121 | - | 142 | 12 | 12 | - | 14 |
Firefox for Desktop | 67 | 22 | - | 20 | 28 | 22 | 22 | 20 | 20 |
Firefox for Android | - | 20 | - | 20 | 28 | 20 | 20 | 20 | 20 |
Safari for Mac | - | 3 | 113 | - | - | 3 | 3 | - | - |
Safari for iOS | - | 3 | 113 | - | - | 3 | 3 | - | - |
Opera for Desktop | 57 | 25 | - | 11 | 16 | - | - | 11 | 12 |
Android Stock Browser | - | 2.3 | - | 4.0 | 5 | 2.3 | 2.3 | 4.0 | - |
Notes
- Supported only for devices with hardware support.
- Edge 14+ has partial support for VP9
- Supported only on macOS High Sierra and onwards.
Recommended markup
Since all browsers support MP4, we can use WebM's VP9 codec for modern browsers and fall back to MP4s for the rest.
Creating thumbnail images from the video
Here's their guide. Output a single frame from the video.
Output one image every second as a jpg.
Reversing a video
FFmpeg now has a reverse filter. Usage: (source from this video.stackexchange answer)
For video only:
For audio and video:
This filter buffers the entire clip. For larger files, segment the file, reverse each segment and then concat the reversed segments.
How to Add a Watermark to Video
FFMPEG filters provide a powerful way to programmatically enhance or alter videos, and it’s fairly simple to add a watermark to a video using the overlay filter. The easiest way to install ffmpeg is to download a pre-built binary for your specific platform. Then you don’t have to worry about including and installing all the right dependencies and codecs you will be using.
Once you have ffmpeg installed, adding a watermark is as easy as passing your existing source through an overlay filter like so:
Basically, we’re passing in the original video, and an overlay image as inputs, then passing it through the filter, and saving the output as test1.mp4.
We specify a specific position of the overlay in pixels – 10:10 puts the video 10 pixels from the top and 10 pixels from the right. (x:y coordinates)
In some cases you might not know the exact dimensions of the videos you’ll be watermarking. Fortunately, there are variables you can use to better position your watermark depending on the size of the video. These variables include:
- main_h – the video’s height
- main_w – the video’s width
- overlay_h – the overlay’s height
- overlay_w – the overlay’s width
![Ffmpeg Ffmpeg](/uploads/1/2/3/7/123701326/754058907.png)
Using these variable we can position the watermark right in the center of the video like so:
If we wanted to add branding or a watermark to the clip but not cover the existing video, we can use the pad filter to add some padding to our clip, and then position our watermark over the padding like so:
Once you start getting the hang of this, you can even animate your overlays!
I want to create a gif image from a jpeg image list, everything works fine, but how can I slow the animation?
Here is my code: Star wars battlefront 2 1920x1080.
wojttaa
wojttaawojttaa
2 Answers
To slow down an image sequence, lower its framerate
GyanFfmpeg Source Code Git
Gyan37.5k22 gold badges3434 silver badges7575 bronze badges
You want the
-r
flag to set the frame rate (in frames per second). From the official documentation:-r[:stream_specifier] fps (input/output,per-stream)
Set frame rate (Hz value, fraction or abbreviation).
As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps. This is not the same as the -framerate option used for some input formats like image2 or v4l2 (it used to be the same in older versions of FFmpeg). If in doubt use -framerate instead of the input option -r.
As an output option, duplicate or drop input frames to achieve constant output frame rate fps.
For example, setting to 30 fps:
Note: The
MTCosterMTCoster-r
argument must appear after the input file if you want it to apply to the output4,10722 gold badges2222 silver badges4343 bronze badges