How to make vote in Facebook
Once ffmpeg is installed, pick a GIF, and you'll be ready to roll. For the purposes of this guide, I picked this GIF, which is just shy of 14 MB. To start off, let's try our hand at converting a GIF to MPEG-4!
Converting GIF to MPEG-4
Whenever you embed videos on a page, you'll always want to have an MPEG-4 version as MPEG-4 enjoys the broadest support of all video formats across browsers. To get started, open a terminal window, go to the directory containing your test GIF, and try this command:
ffmpeg -i input.gif output.mp4
This is the most straightforward syntax for converting a GIF to MPEG-4. The -i flag specifies the input, and we specify an output file thereafter. This command takes our test GIF of 14,024 KB and reduces it to a reasonably high quality MPEG-4 video weighing in 867 KB. That's a reduction of 93.8%. Not bad, but maybe you're curious to see if we can go a little further. If so, keep reading!
It turns out ffmpeg is super configurable, and we can use this to our advantage to fine-tune the video output further by employing an encoding mode called Constant Rate Factor (or CRF). CRF is great when video quality is a high priority.
ffmpeg -i input.gif -b:v 0 -crf 25 output.mp4
This command is largely similar to the one before it, but with two key differences: The -b:v flag normally would limit the output bitrate, but when we want to use CRF mode, it must be set to 0. The -crf flag accepts a value between 0 and 51. Lower values yield higher quality (but larger) videos, whereas higher values do the opposite.
Using our test GIF, this command outputs an MPEG-4 video 687 KB in size. That's an improvement of roughly 20%! If you want even smaller file sizes, you could specify a higher CRF value. Just be aware that higher values will yield lower quality videos, so always check the encoder's output to ensure you're cool with the results!
In any event, both these commands yield a massive reduction in file size over GIF, which in turn will substantially improve initial page load time and reduce data usage. While the visual quality of the video issomewhat lower than source GIF, the reduction in file size is a reasonable trade-off to make:Figure 2. Visual comparison of an animated GIF frame against an MPEG-4 frame from a video encoded with a CRF of 25.
While the figure above is no substitute for a comprehensive visual comparison, the MPEG-4 is certainly sufficient as an animated GIF replacement. It also pays to remember that your users likely won't have a reference to the GIF source like you will. Always adhere to your project's standards for media quality, but be willing to make trade-offs for performance where appropriate.
Converting GIF to WebM
While MPEG-4 has been in around in some form since at least 1999 and continues to see development, WebM is a relative newcomer having been initially released in 2010. While browser support for WebM isn't as wide as MPEG-4, it's still very good. Because the <video> elementallows you to specify multiple <source> elements, you can state a preference for a WebM source that many browsers can use while falling back to an MPEG-4 source that all other browsers can understand.
Try converting your test GIF to WebM with ffmpeg with this command:
Once ffmpeg is installed, pick a GIF, and you'll be ready to roll. For the purposes of this guide, I picked this GIF, which is just shy of 14 MB. To start off, let's try our hand at converting a GIF to MPEG-4!
Converting GIF to MPEG-4
Whenever you embed videos on a page, you'll always want to have an MPEG-4 version as MPEG-4 enjoys the broadest support of all video formats across browsers. To get started, open a terminal window, go to the directory containing your test GIF, and try this command:
ffmpeg -i input.gif output.mp4
This is the most straightforward syntax for converting a GIF to MPEG-4. The -i flag specifies the input, and we specify an output file thereafter. This command takes our test GIF of 14,024 KB and reduces it to a reasonably high quality MPEG-4 video weighing in 867 KB. That's a reduction of 93.8%. Not bad, but maybe you're curious to see if we can go a little further. If so, keep reading!
It turns out ffmpeg is super configurable, and we can use this to our advantage to fine-tune the video output further by employing an encoding mode called Constant Rate Factor (or CRF). CRF is great when video quality is a high priority.
ffmpeg -i input.gif -b:v 0 -crf 25 output.mp4
This command is largely similar to the one before it, but with two key differences: The -b:v flag normally would limit the output bitrate, but when we want to use CRF mode, it must be set to 0. The -crf flag accepts a value between 0 and 51. Lower values yield higher quality (but larger) videos, whereas higher values do the opposite.
Using our test GIF, this command outputs an MPEG-4 video 687 KB in size. That's an improvement of roughly 20%! If you want even smaller file sizes, you could specify a higher CRF value. Just be aware that higher values will yield lower quality videos, so always check the encoder's output to ensure you're cool with the results!
In any event, both these commands yield a massive reduction in file size over GIF, which in turn will substantially improve initial page load time and reduce data usage. While the visual quality of the video issomewhat lower than source GIF, the reduction in file size is a reasonable trade-off to make:Figure 2. Visual comparison of an animated GIF frame against an MPEG-4 frame from a video encoded with a CRF of 25.
While the figure above is no substitute for a comprehensive visual comparison, the MPEG-4 is certainly sufficient as an animated GIF replacement. It also pays to remember that your users likely won't have a reference to the GIF source like you will. Always adhere to your project's standards for media quality, but be willing to make trade-offs for performance where appropriate.
Related Posts:
- Facebook app for iphone 3
- How to count down Days
- Logs
- Lpg in Fb
- Instagram limits 2016
- Get Facebook Messenger
- How to download fb videos in android Iphone
- How to sign out from Facebook messenger on Iphone
Converting GIF to WebM
While MPEG-4 has been in around in some form since at least 1999 and continues to see development, WebM is a relative newcomer having been initially released in 2010. While browser support for WebM isn't as wide as MPEG-4, it's still very good. Because the <video> elementallows you to specify multiple <source> elements, you can state a preference for a WebM source that many browsers can use while falling back to an MPEG-4 source that all other browsers can understand.
Try converting your test GIF to WebM with ffmpeg with this command:
0 comments:
Post a Comment
Facebook has greatly reduced the distribution of our stories in our readers' newsfeeds and is instead promoting mainstream media sources. When you share to your friends, however, you greatly help distribute our content. Please take a moment and consider sharing this article with your friends and family. Thank you.