Server‑Side Video Rendering with After Effects, Aerender, and FFmpeg
This article describes how a PHP‑based backend service integrates Adobe After Effects' command‑line renderer and FFmpeg to generate, split, concatenate, and compress user‑uploaded video templates for a mini‑program, covering architecture, workflow, code snippets, and performance optimizations.
The article introduces a mini‑program called "XiaoBai Magic Photo" that lets elderly users create music photo albums with video effects, and explains the three core product requirements: diverse After Effects‑style effects, rapid template rollout, and compatibility with a mini‑program (no client‑side rendering).
Two initial solutions were considered: front‑end CSS/JS effects (rejected because they cannot produce downloadable videos) and server‑side rendering with open‑source tools like MLT (rejected due to the need to convert AE templates to MLT XML). The chosen approach leverages Adobe After Effects' command‑line tool aerender.exe to automatically render videos from uploaded assets.
The processing pipeline consists of four steps:
User selects a template in the mini‑program, uploads required media, and calls a backend API.
The PHP backend stores the request, creates a rendering task, and pushes it to a message queue.
A Windows‑based Go rendering service consumes the task, copies the AE project, replaces placeholder assets, and invokes aerender.exe to produce a video.
The PHP backend receives the rendered video URL from the queue, stores it, and returns the link to the client.
After initial tests, three issues were identified: slow rendering (≈30 s for a 10‑second template), large output size, and the need for a thumbnail frame.
To speed up rendering, the video is split into smaller frame ranges using the -s and -e parameters of aerender.exe :
aerender.exe -project c:\projects\project_1.aep -comp "Composition_1" -s 1 -e 36 -RStemplate "Multi-Machine Settings" -OMtemplate "Multi-Machine Sequence" -output c:\output\project_1\frames_1.movEach segment is then concatenated with FFmpeg:
ffmpeg -f concat -i "c:\output\project_1\file.txt" -c copy "c:\output\project_1\outmerge.mov"Finally, the merged video is re‑encoded to reduce size, lowering frame rate to 18 fps and audio bitrate to 32 k, using H.264 and AAC:
ffmpeg -i c:\output\project_1\outmerge.mov -c:v libx264 -pix_fmt yuv420p c:\output\project_1\out.mp4The article concludes with a roadmap that includes Windows cluster management, performance improvements, template generation automation, and exploration of more mature rendering solutions.
360 Tech Engineering
Official tech channel of 360, building the most professional technology aggregation platform for the brand.
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.