How MaFengWo Built a Powerful iOS Video Editing Framework for Short Videos
This article explains how MaFengWo’s iOS app implements a flexible video editing framework that supports custom editing and template‑based creation, detailing the requirement analysis, architecture design, AVFoundation‑based implementation, performance optimizations, and future directions for short‑video content.
MaFengWo has expanded its short‑video capabilities to complement its traditional travel‑article formats, aiming to provide users with both visually appealing and highly functional video content. The iOS app now offers two editing modes: a "custom edit" mode for freeform creation and a "template creation" mode that lets users generate videos with the same effects as predefined templates.
Requirement Analysis
The custom edit mode must support features such as video stitching, image‑to‑video conversion, trimming, speed adjustment, background music mixing, reverse playback, transition effects, and visual edits like rotation, partitioning, filters, stickers, and text. The template mode adds the ability to apply a saved editing description to new media, enabling one‑click creation of "same‑style" videos.
Video stitching: concatenate multiple clips in order.
Image playback: turn a series of photos into a video.
Video trimming: remove a segment from a clip.
Speed change: adjust playback speed.
Background music: add and mix music with original audio.
Reverse playback: play video backwards.
Transition: add effects between stitched clips.
Visual editing: rotate, partition, set background color, apply filters, stickers, text, etc.
Framework Design
The framework consists of three main modules:
Edit module : implements the actual media processing.
Description module : defines a JSON‑based model that describes media assets and the sequence of editing operations; it can be enriched with template metadata (title, thumbnail, description).
Conversion module : translates between the description model and the edit module, enabling both custom editing and template‑driven generation. The overall architecture is illustrated below:
Module Implementation
Using Apple’s AVFoundation, the edit module implements the required capabilities:
1. Media Composition (AVMutableComposition)
Tracks (AVCompositionTrack) hold video, audio, or image segments, each defined by a time range.
// Create a new composition track
- (nullable AVMutableCompositionTrack *)addMutableTrackWithMediaType:(AVMediaType)mediaType preferredTrackID:(CMPersistentTrackID)preferredTrackID;2. Audio Mixing (AVMutableAudioMix)
AudioMixInputParameters allow per‑track volume ramps over specific time ranges.
CMPersistentTrackID trackID;
- (void)setVolumeRampFromStartVolume:(float)startVolume toEndVolume:(float)endVolume timeRange:(CMTimeRange)timeRange;3. Video Rendering (AVMutableVideoComposition)
VideoComposition defines render size, frame rate, and layer instructions for applying filters, transforms, and CoreAnimation overlays.
4. Export (AVAssetExportSession)
The final composition is exported to a file by assigning the above objects to an AVAssetExportSession.
The edit module also defines tracks, segments, and instructions that map the description model to concrete AVFoundation operations, supporting both custom edits and template‑driven generation.
Optimization and Future Plans
During development, several pitfalls were encountered:
Track count limitation : Export fails when too many video tracks exceed the device’s decoder limit. The solution was to collapse multiple tracks into a dual‑track structure before export.
Reverse playback performance : Instead of re‑encoding the entire clip in reverse, the implementation maps timestamps to reverse order, avoiding costly processing.
Memory usage : Preview uses low‑resolution images to reduce RAM consumption, while export uses the original high‑resolution assets.
Future work includes integrating machine‑learning and AR techniques to create more personalized travel‑video experiences.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Mafengwo Technology
External communication platform of the Mafengwo Technology team, regularly sharing articles on advanced tech practices, tech exchange events, and recruitment.
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.
