Common video editing tools such as Premiere and AE can implement complex editing effects and are widely used in promotional and advertising video production. However, in the following scenarios, traditional editing tools and template-based video processing software programs cannot meet the requirements for batch, automated, and custom video editing:
In these video editing scenarios, resource usage is concentrated within certain hours, and the volume of computed data is high. In this case, dedicated high-end servers may have a low utilization, while low-end servers' computing power cannot meet the requirements. By contrast, SCF perfectly satisfies such requirements with its pay-as-you-go billing mode and high-performance computing power. It not only achieves a 100% utilization but also provides high computing power on demand. In addition, it delivers a higher flexibility by supporting multiple programming environments for developers with different development habits.
All video editing features mentioned in this document are implemented by FFmpeg.
FFmpeg is an open-source video processing tool. It supports video editing, transcoding, splicing, audio processing, text adding, and live stream push/pull. You can use different FFmpeg commands to program and implement different video editing features. You can also combine and orchestrate them to execute various batch automated tasks.
Below are common video editing scenarios:
Some FFmpeg commands are as described below. You can install FFmpeg locally first and then perform tests.
// Convert an .mov video to an .mp4 video ffmpeg -i input.mov output.mp4
// Change the frame rate of the original video to 24 FPS ffmpeg -i input.mp4 -r 24 -an output.mp4
// Convert an .mp4 video to a video stream suitable for live streaming ffmpeg -i input.mp4 -codec: copy -bsf:v h264_mp4toannexb -start_number 0 -hls_time 10 -hls_list_size 0 -f hls output.m3u8
// Change the video resolution to 480x360 and change the bitrate to 400 Kbps 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
// Add text such as subtitles and title to the video // `fontfile` is the path of the font to be used, and `text` is the text to be added // `fontcolor` is the font color, `fontsize` is the font size, and `box` is the text box // `box=1` indicates to enable the text box, while `0` indicates to disable it. `boxcolor` is the box color. `firstname.lastname@example.org` indicates black with 50% transparency. `boxborderw` is the width between the box and the text // `x` and `y` indicate the text position. They can be numbers or expressions. For more information, visit the FFmpeg website ffmpeg -i input.mp4 -vf "drawtext=fontfile=/path/to/font.ttf:text='your text':fontcolor=white:fontsize=24:box=1:email@example.com:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -codec:a copy output.mp4
// Add an image such as logo, profile photo, and sticker to the video. `filter_complex` indicates a complex filter, `overlay` indicates the X and Y coordinates of the image, and `enable` indicates the image display period (from second 0 to second 20) 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
// Splices videos. `list.txt` lists the paths of all video files to be spliced in sequence; for example: // Note: If the videos have different resolutions, splicing will fail. ffmpeg -f concat -safe 0 -i list.txt -c copy -movflags +faststart output.mp4 // `list.txt` is in the following format: file 'xx.mp4' file 'yy.mp4'
// Add audio to the video. `stream_loop` indicates whether to loop the audio (-1: infinite loop; 0: no loop). `shortest` indicates to complete encoding when the shortest .mp3 input stream ends. ffmpeg -y -i input.mp4 -stream_loop -1 -i audio.mp3 -map 0:v -map 1:a -c:v copy -shortest output.mp4
FFmpeg also supports editing audio separately. For detailed directions, visit the FFmpeg website.
This document uses Python as an example. You can refer to the following sample code to run FFmpeg commands:
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("Failed to process the video. Error:", child)
This example requires SCF to have the operation permissions of VOD. Execution Role has been enabled by default, and an execution role has been automatically created and associated with the required VOD permission policy
QcloudVODFullAccess. If you need to make adjustments, select Use the existing role or disable Execution Role.
To use an existing API service to create an API Gateway trigger or modify the trigger configuration, select Custom.
The customer is an online education company. It needs to create 30-second videos as students' study results from online class recordings every time students finish classes. This case has the following key information:
Based on the above characteristics, SCF has the following strengths for video editing:
The reference architecture for this case is as shown below:
You can orchestrate, combine, and reuse the above audio/video editing capabilities to meet the requirements for various scenarios. You can also convert the parameters used to control various effects in video editing to the parameters passed in during service call in order to implement various custom effects.