Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
ffmpeg settings for converting to mp4 and ogg for HTML5 video
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg.
HTML5 video requires specific codecs for cross-browser compatibility. MP4 with H.264/AAC works in most browsers, while OGV with Theora/Vorbis supports Firefox and other open-source browsers.
Converting to MP4 Format
When converting to MP4, use the H.264 video codec and AAC audio codec for maximum browser compatibility, especially IE11 and earlier versions.
ffmpeg -i input.mov -vcodec h264 -acodec aac -strict -2 output.mp4
This command converts input.mov to output.mp4 with H.264 video and AAC audio codecs.
MP4 with Maximum Compatibility
For broader device support including older mobile devices and QuickTime, use this more compatible configuration:
ffmpeg -an -i input.mov -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 output2.mp4
This creates output2.mp4 with maximum compatibility, QuickTime support, and removes the audio stream (-an flag).
Parameters Explained
-
-an: Removes audio stream -
-vcodec libx264: Uses x264 encoder for H.264 -
-pix_fmt yuv420p: Sets pixel format for compatibility -
-profile:v baseline: Uses baseline profile for older devices -
-level 3: Sets H.264 level for compatibility
Converting to OGV Format
For Firefox and open-source browser compatibility, convert to OGV format using ffmpeg2theora. Install it first if not available:
# Install ffmpeg2theora (Ubuntu/Debian) sudo apt-get install ffmpeg2theora
Convert your MP4 to OGV:
ffmpeg2theora -o video_out_file.ogv output.mp4
This creates video_out_file.ogv from the previously converted MP4 file.
HTML5 Video Implementation
Use both formats in your HTML5 video element for cross-browser support:
<video controls width="640" height="480">
<source src="video_out_file.mp4" type="video/mp4">
<source src="video_out_file.ogv" type="video/ogg">
Your browser does not support HTML5 video.
</video>
Browser Compatibility
| Format | Browsers | Codecs |
|---|---|---|
| MP4 | Chrome, Safari, IE, Edge | H.264 + AAC |
| OGV | Firefox, Opera | Theora + Vorbis |
Conclusion
Use ffmpeg to create MP4 files with H.264/AAC for broad compatibility, and supplement with OGV using ffmpeg2theora for complete HTML5 video support across all browsers.
