Nodejs Chapter 16 (ffmpeg)

FFmpeg is an open source cross-platform multimedia processing tool that can be used to process audio, video and multimedia streams. It provides a set of powerful command line tools and libraries for video transcoding, video editing, audio extraction, audio and video merging, streaming media transmission and other operations.

FFmpeg’s main functions and features:
  1. Format conversion: FFmpeg can convert a media file from one format to another, supporting almost all common audio and video formats, including MP4, AVI, MKV, MOV, FLV, MP3, AAC, etc.
  2. Video processing: FFmpeg can perform video encoding, decoding, cropping, rotating, scaling, adjusting frame rate, adding watermarks, etc. You can use it to adjust the resolution of the video, cut and splice video clips, and apply various effects to the video.
  3. Audio processing: FFmpeg can perform audio encoding, decoding, editing, mixing, volume adjustment and other operations. You can use it to extract audio tracks, cut and splice audio clips, and perform noise reduction, equalizer, and other processing on audio.
  4. Streaming media transmission: FFmpeg supports real-time transmission of audio and video streams to the network, and can be used in application scenarios such as real-time streaming media services, live broadcasts, and video conferencing.
  5. Efficient video processing: FFmpeg is an efficient tool optimized for processing large video files and high-resolution videos, providing fast processing speeds while maintaining good quality.
  6. Cross-platform support: FFmpeg can run on multiple operating systems, including Windows, MacOS, Linux, etc., and supports multiple hardware acceleration technologies, such as NVIDIA CUDA and Intel Quick Sync Video.
Install

http://ffmpeg.p2hp.com/download.html

image.png

Just select the corresponding operating system to download. After the download is completed, configure the environment variables and it will be ok.

ffmpage -versionJust enter without reporting an error

image.png

Subprocess cooperates with ffmpeg

  1. Simple demo video to gif -ito express the meaning of input
const {
    
    execSync} = require('child_process')
execSync(`ffmpeg -i test.mp4 test.gif`,{
    
    stdio:'inherit'})

image.png

  1. add watermark

-vf is video filter

drawtext adds text fontsize size xy vertical horizontal direction fontcolor color text watermark copywriting全部小写

const {
    
    execSync} = require('child_process')

execSync(`ffmpeg -i test.mp4 -vf drawtext=text="XMZS":fontsize=30:fontcolor=white:x=10:y=10 test2.mp4`,{
    
    stdio:'inherit'})

image.png

  1. Video crop + size control

-ss starting time

-to end event

Writing ss in front of -i may cause accuracy problems, because the video jumps to the relevant position before it is parsed, but the parsing speed is fast

If ss is written after -i, the accuracy will be fine, but the parsing speed will be slower.

const {
    
    execSync} = require('child_process')

execSync(`ffmpeg -ss 10 -to 20 -i test.mp4  test3.mp4`,{
    
    stdio:'inherit'})
  1. Extract audio from video
const {
    
    execSync} = require('child_process')
execSync(`ffmpeg -i test.mp4 test.mp3`,{
    
    stdio:'inherit'})

image.png

  1. Remove watermark

wh width height
xy vertical and horizontal coordinates
filter parameters used by delogo to remove watermarks

const {
    
    execSync} = require('child_process')

execSync(`ffmpeg -i  test2.mp4 -vf delogo=w=120:h=30:x=10:y=10 test3.mp4`,{
    
    stdio:'inherit'})

image.png

Guess you like

Origin blog.csdn.net/qq1195566313/article/details/132927842