Custom Video Compression on iOS: Understanding H.264 Profiles, Levels and Implementation
This article introduces the fundamentals of video compression, analyzes the shortcomings of traditional iOS compression methods, explains H.264 profile and level concepts, examines device support, and provides a step‑by‑step custom iOS solution for controlling bitrate, resolution and frame rate.
With the rapid growth of short‑video apps like Douyin and Kuaishou, video compression has become a critical step for mobile transmission. The article first presents basic video concepts and demonstrates that the default AVFoundation compression often produces larger files despite lower resolution.
It then analyzes traditional compression shortcomings, showing a test where a 1080×608, 90 MB source becomes a 960×540, 147 MB output, and examines the video parameters before and after compression using MediaInfo.
The discussion moves to key video metrics—bitrate, frame rate, resolution—and introduces H.264 encoding standards, describing the various profiles (Baseline, Main, High) and their capabilities.
Profiles and levels are explained in detail, including the official definition of a level and a table of Level 3.1 constraints such as maximum luma samples and macroblocks.
Device support for different profiles and levels on iPhone and iPad models is listed, highlighting which devices can decode Main or High profiles at specific levels.
Finally, a custom video compression workflow for iOS is proposed: use AVAssetReader to extract each sample buffer, set desired bitrate, profile, and frame rate, and write the processed frames with AVAssetWriter . The article outlines the implementation steps—initializing reader and writer, configuring tracks, specifying compression parameters, reading and writing frames, and completing the compression.
Sample code snippets (shown as images in the original) illustrate the initialization, parameter setting, and frame‑by‑frame processing. The resulting compressed video demonstrates reduced bitrate, and the author notes that the same pipeline can be extended to add watermarks or filters in future articles.
Ctrip Technology
Official Ctrip Technology account, sharing and discussing growth.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.