Automating Batch Video Editing Using FFmpeg on Tencent Cloud Serverless
The article explains how to use FFmpeg within Tencent Cloud Serverless functions to build fully automated, scalable, and customizable batch video‑editing pipelines—covering use cases like personalized student highlights, avatar‑based marketing clips, and streamer promos—while detailing deployment via GitHub Actions or manual upload.
The article starts by addressing three common doubts: whether traditional Adobe tools are sufficient for video editing, why Serverless should be used, and how to write code to perform video editing.
It then describes several business scenarios that require batch, automated, and customizable video processing, such as:
Generating personalized highlight videos for thousands of students after an online class.
Creating unique avatar videos for marketing campaigns with tens of thousands of users.
Producing weekly promotional videos for dozens of streamers in a live‑broadcast operation.
These scenarios share three key characteristics: batch , automation , and customizability . Traditional video‑editing software or template‑based tools cannot handle them efficiently.
Why Serverless? Video‑editing workloads are typically:
Highly concentrated in time (e.g., many videos need to be rendered right after a class ends).
Compute‑intensive (transcoding, scaling, adding effects).
Serverless offers pay‑per‑use billing, elastic scaling, and high‑performance compute, making it a perfect fit. Tencent Cloud Serverless functions also provide a programmable environment that supports any language, such as Python.
FFmpeg is introduced as the open‑source engine that powers all the video‑processing capabilities (transcoding, cutting, adding text or images, concatenation, streaming, etc.).
Typical FFmpeg commands are shown below. Each command is presented unchanged inside tags:
ffmpeg -i input.mov output.mp4 ffmpeg -i input.mp4 -r 24 -an output.mp4 ffmpeg -i input.mp4 -codec: copy -bsf:v h264_mp4toannexb -start_number 0 -hls_time 10 -hls_list_size 0 -f hls output.m3u8 ffmpeg -i input.mp4 -vf scale=480:360,pad=480:360:240:240:black -c:v libx264 -x264-params nal-hrd=cbr:force-cfr=1 -b:v 400000 -bufsize 400000 -minrate 400000 -maxrate 400000 output.mp4 ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='Your Text':fontcolor=white:fontsize=24:box=1:[email protected]:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy output.mp4 ffmpeg -i input.mp4 -i avatar.JPG -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4 ffmpeg -f concat -safe 0 -i list.txt -c copy -movflags +faststart output.mp4 ffmpeg -y -i input.mp4 -stream_loop -1 -i audio.mp3 -map 0:v -map 1:a -c:v copy -shortest output.mp4In Python, these commands can be executed with subprocess.run :
child = subprocess.run('./ffmpeg -i input.mov output.mp4', stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True) if child.returncode == 0: print('success:', child) else: print('error:', child) raise KeyError('Processing video failed, error:', child)Two deployment methods are described:
GitHub Actions : fork the repository, add Tencent Cloud secret keys, and let the workflow automatically deploy on each push.
Manual upload : package the code as a ZIP file, create a new Cloud Function in the Tencent console, select Python, upload the ZIP, configure memory, enable async execution, set a longer timeout, and bind an API‑Gateway trigger.
A concrete case study is presented: a school needs to generate a 30‑second personalized video for each of 200 students after a one‑hour class. The requirements include batch processing, high concurrency, adding each student’s name and avatar, and a short, fixed processing window. Using Tencent Cloud Serverless functions solves the concurrency, cost, and compute challenges.
The article concludes that by orchestrating the various FFmpeg‑based video‑editing primitives (text overlay, image overlay, scaling, concatenation, audio mixing, etc.) and exposing them as Serverless APIs, developers can achieve fully automated, scalable, and customizable video production pipelines.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
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.