What is the difference between codec and container / format?
You need to understand the difference between a codec (e.g. H.264, VP9) and a container format (e.g. MP4, WebM). The container simply stores encoded video and audio information. As a rule, you can change the container between streams ( ffmpeg -i input -c copy output ), but for historical reasons you will find that some containers do not accept some codecs or some players may not process the codec inside the container (for example, only the latest software can read VP9 video in MP4). Check out this overview of container formats to find out which codecs are supported.
What are the restrictions imposed by various mobile OS?
To target iOS and Android platforms, you need to check whether this video file is compatible with supported codecs / formats:
Of course, it can change over time, but, as a rule, a common denominator:
- H.264 Video
- MP4 container
- Main profile
- Maximum resolution 1920 Γ 1080 - although the resolution may be higher if the device supports it, it is rarely necessary to exceed Full HD for mobile devices, since people cannot understand the difference between this and 4K / UHD, if only it is a large tablet.
- The frame rate must not exceed a certain maximum (e.g. 60 Hz)
- The sub-colorization should be 4: 2: 0.
- Audio AAC-LC
Certain restrictions depend on the device, obviously, and on the installed version of the operating system. Not all of these features are mentioned in the iOS / Android documentation. You should definitely do some testing and, if not sure, transcode the video.
So which codec / format should be encoded with?
Apple has invested heavily in the MPEG ecosystem and traditionally better supports H.264 and H.265 (HEVC); they do not support VP8 and VP9 in WebM. Thus, if you have a VP8 / VP9 video and you want it to be visible cross-platform, transcode it to H.264.
How do I make the actual encoding?
Make sure you use a high enough bit rate so that you donβt add additional artifacts to your already lost video. You should not just do a one-time target bit rate, as you are doing now. Instead, perform two-pass encoding to improve the quality and efficiency of encoding (although it takes more time). You can also use constant quality mode if you do not need a specific file size (for example, CRF for libx264 ). Read more about FFmpeg H.264 for encoding .
What about the future?
Please note that almost all major players in the technology industry, except Apple, have joined the Alliance for Open Media . They are developing a VP9 successor called " AV1, " which will receive support from all major browser providers (Chrome, Firefox, Edge) and Android.
H.265 / HEVC also seems like a good choice, but encoding with x265 , for example, is currently still very slow compared to x264 , the most popular open source H.264 encoder.