FFmpeg 3GP Audio and Video Codec Constraints
This article provides a comprehensive overview of the audio and video codec constraints encountered when using FFmpeg to encode or mux media into the 3GP container format. Because 3GP was designed primarily for older mobile devices with limited processing power and bandwidth, the container enforces strict limitations on codecs, resolutions, sample rates, and channel configurations. Understanding these boundaries is essential for successful command execution without generating errors in FFmpeg.
Video Codec Constraints
The 3GP container supports a very limited selection of video codecs. When using FFmpeg, you must target these specific codecs and adhere to their respective resolution and framerate constraints:
- H.263 (
-c:v h263or-c:v h263p): This is the traditional standard for 3GP. It is highly constrained regarding resolutions. You must use standard sizes such as Sub-QCIF (128x96), QCIF (176x144), or CIF (352x288). Framerates are typically limited to 15 or 30 frames per second. - MPEG-4 Part 2 (
-c:v mpeg4): This codec offers better quality than H.263 and is widely supported by 3GP containers. It is less restrictive with resolutions but still works best at lower, mobile-friendly dimensions. - H.264 / AVC (
-c:v libx264): Supported in newer 3GPP release specifications. However, to maintain compatibility within the 3GP container, you must restrict the H.264 stream to the Baseline Profile (-profile:v baseline) and low levels (e.g., Level 1.2 to 3.0).
Audio Codec Constraints
Audio in a 3GP container is strictly regulated. Passing unsupported sample rates or channel layouts to FFmpeg will cause the encoding process to fail.
- AMR-NB (Narrowband -
-c:a libopencore_amrnb):- Sample Rate: Must be exactly 8000
Hz (
-ar 8000). - Channels: Must be mono
(
-ac 1). - Bitrates: Restricted to specific CBR bitrates (4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k, or 12.2k).
- Sample Rate: Must be exactly 8000
Hz (
- AMR-WB (Wideband -
-c:a libopencore_amrwb):- Sample Rate: Must be exactly 16000
Hz (
-ar 16000). - Channels: Must be mono
(
-ac 1). - Bitrates: Restricted to specific CBR bitrates (6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 18.25k, 19.85k, 23.05k, or 23.85k).
- Sample Rate: Must be exactly 16000
Hz (
- AAC-LC (Low Complexity AAC -
-c:a aac): Used for higher-quality audio in later 3GP revisions. It supports stereo (-ac 2) and standard sample rates (usually 22050 Hz, 24000 Hz, 32000 Hz, or 44100 Hz).
Example FFmpeg Commands
To ensure successful compilation to 3GP, you must explicitly apply these constraints in your FFmpeg commands.
Encoding to H.263 and AMR-NB:
ffmpeg -i input.mp4 -c:v h263 -s 176x144 -r 15 -c:a libopencore_amrnb -ar 8000 -ac 1 -ab 12.2k output.3gpEncoding to MPEG-4 and AAC (Higher Quality):
ffmpeg -i input.mp4 -c:v mpeg4 -s 320x240 -r 25 -c:a aac -ar 32000 -ac 2 -b:a 64k output.3gp