FFMPEG basic operation command guide (2)

FFmpeg is a set of open source computer programs that can be used to record, convert digital audio and video, and convert them into streams. FFmpeg has very powerful functions including video capture function, video format conversion, video capture, adding watermark to video, etc.

Continuing with the basic commands of the first article, here are some seemingly complicated ones

1: Video cutting

Command example:

ffmpeg -ss 00:00:00 -i input.mp4 -vcodec copy -acodec copy -t 00:00:31 output.mp4

 illustrate:

The function of this command is to cut the input.mp4 video according to the specified time and generate a new output.mp4 video. in,

-ss 00:00:00 Start converting from the specified time (if you do not add:, it is expressed as seconds, such as -ss 0, which means cutting from the 0th second)

-t 00:00:31 Set the duration of the output video (if you do not add :, it will be expressed as seconds, such as -t 31, which means the duration is 31 seconds)

Two: video mute

Command example:

ffmpeg -i input.mp4 -af "volume=enable='between(t,5,10)':volume=0" output.mp4

illustrate:

The function of this command is to mute the input.mp4 video according to the specified time and generate a new output.mp4 video.

volume=enable='between(t,5,10)':volume=0 Mute from the 5th second to the 10th second, this command can write multiple, that is, multiple mutes, separated by commas.

Three: Video watermark

Command example:

ffmpeg -i input.mp4 -vf "movie=input.png,colorchannelmixer=aa=0.4,scale=300:300 [watermark]; [in][watermark] overlay" output.mp4

illustrate:

The function of this command is to watermark the input.mp4 video according to the specified command, and generate a new output.mp4 video.

movie=input.png watermark image,

colorchannelmixer=aa=0.4 watermark transparency (if you do not need to change the transparency, remove this paragraph)

scale=300:300 The size of the watermark (if you use the original watermark size, remove this section)

overlay The position of the watermark, the default is the upper left corner

        overlay=Ww upper right corner

        overlay=0:Hh lower left corner

        overlay=Ww:Hh lower right corner

ps: If the watermark does not need to be displayed on the edge, just change the values ​​​​of W and H slightly

Four: video speed change

Command example:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4

illustrate:

The function of this command is to generate a new output.mp4 video at the specified speed of the input.mp4 video.

setpts=0.5*PTS video acceleration (the default is 1, now it is 0.5. It becomes 2 times faster)

atempo=2.0 audio acceleration (the default is 1, now it is 0.5. It becomes 2x speed)

ps: Video acceleration and audio acceleration, the double speed needs to be consistent, otherwise the sound and video will be out of sync

Five: Video coding

Command example:

ffmpeg -i input.mp4 -filter_complex "[0:v]crop=w=100:h=100:x=1200:y=0,boxblur=luma_radius=25:luma_power=2[boxblur];0:voverlay=1200:0[vout]" -map "[vout]" -map 0:a -c:v libx264 -crf 28 -preset veryfast -c:a copy -movflags +faststart output.mp4 -y

illustrate:

The function of this command is to code the input.mp4 video according to the specified position to generate a new output.mp4 video.

 crop=w=100:h=100:x=1200:y=0 wh refers to the width and height of the mosaic, and xy refers to the coordinates that appear in the video

overlay=1200:0 Covered coordinates (this is consistent with the xy above)

Six: Video slice into m3u8 video file

Command example:

ffmpeg -i input.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb -c copy -map 0 -f segment -segment_list output.m3u8 -segment_time 20 %03d.ts

illustrate:

The function of this command is to slice the input.mp4 video according to the specified size, and generate the sliced ​​code m3u8 video.

-segment_time 20 The size of a single slice, you can set it yourself

Guess you like

Origin blog.csdn.net/m0_58954887/article/details/126364820