当前位置:网站首页>Ffmpeg command line use

Ffmpeg command line use

2022-07-06 16:41:00 Dog egg L

View video information

ffmpeg -i  Video name 

 Insert picture description here
Enter the first few characters of the video name here and press tab Key can automatically complete

Return results :
 Insert picture description here

The contents in the red box are useless

Encoder :encoder : Lavf57.25.100
The duration of the :Duration: 00:14:20.58, start: 0.000000, bitrate: 381 kb/s
Duration The duration of the ,start Starting time ,bitrate Bit rate

Video streaming : Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yu
v420p, 1360x768, 182 kb/s, 29.94 fps, 30 tbr, 15360 tbn, 30720 tbc (default)
h264 Coding format ,avc1 Package format ,yuv420p Format of each frame ,1360x768 The resolution of the ,182 kb/s Video bitrate ,29.94 fps frames

Audio stream : Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, flt
p, 191 kb/s (default)
aac Coding format ,mp4a Package format ,44100 Hz Sampling rate ,stereo stereo ,fltp floating-point ,191 kb/s (default) Audio bitrate

Remove audio

ffmpeg -i  file name  -an -vcodec copy  file name .mp4

-an Remove audio ,-vcodec copy Copy the video stream of the source data to the file name .mp4 In the document

Remove video

ffmpeg -i  file name  -vn -acodec copy  file name .mp4

-vn Remove audio ,-acodec copy Copy the audio stream of the source data to the file name .mp4 In the document

Save audio as AAC file

 ffmpeg -i  file name .mp4 -vn -acodec copy  file name .aac

Change the video resolution

ffmpeg -i  file name .mp4 -vf scale=640:360  file name .mp4

scale= The following is the modified resolution

ffmpeg -i  file name .mp4 -vf scale=iw*2:ih*2  file name .mp4

Double the resolution , It's fine too *0.5 Become half

Hide useless information

ffmpeg -i  file name .mp4 -hide_banner

 Insert picture description here

Add watermark

ffmpeg -i  file name .mp4 -i  watermark .png -filter_complex overlay out.mp4

Default top left corner ,overlay=W-w Is the top right corner ,overlay=0:H-h It's the lower left corner ,overlay=W-w:H-h It's the lower right corner
uppercase H Is the height of the video , uppercase W Is the width of the video , Lowercase h Is the height of the watermark , Lowercase w Is the width of the watermark .

Remove watermark

ffmpeg -i  file name .mp4 -vf delogo=x:y:w:h:show out.mp4

x,y determine logo The position coordinates of
w,h Set up logo The width and height of
show Indicates whether a rectangle is displayed , The default is 0 No display ,1 Is to show

Add text watermark

ffmpeg -i  file name .mp4 -vf drawtext=text=' Content ':fontcolor=' Color ':fontsize= Font size  out.mp4

Capture the video

ffmpeg -i  file name .mp4 -ss  second  -to  Time  out.mp4

From how many seconds , How long will the video be captured

Video to gif

ffmpeg -i  file name .mp4 -ss 10 -t 5 -s 640*320 -r 15 out.mp4

-ss Starting time
-t The duration of the
-i Followed by the source file
-s Motion picture resolution
-r Frame rate

ffmpeg -i  file name .mp4 -vframes 30 out.gif

-vframes 30 The first thirty frames of the video
Convert the first thirty frames of the video into gif

Video compression -crf

ffmpeg -i  file name .mp4 -c:v libx264 -crf 23 out.mp4

×264 The default value is 23( Suggest 18 - 28)
×265 The default is 28( Suggest 24 - 34)
The available values for both are 0 To 51
The smaller the value, the better the coding quality , The higher the bit rate
among 0 It can be said to be undamaged ,51 The worst quality
crf The difference is 6 It will double or halve the file size

Video compression -preset

ffmpeg -i  file name .mp4 -vocdec libx264 -preset xxx -crt 25 out.mp4

preset It mainly affects the speed of coding , It does not greatly affect the size of the output file
x264 The encoding algorithm has the following parameter values
ultrafast The coding speed is the fastest and the compression rate is low , The generated file is very large
superfa
veryfast
faster
fast
medium x264 Default criteria
slow
slower
veryslow
placebo The encoding speed is the slowest , High compression ratio , Generated file small

xxx Just fill in the following parameters

Add a black edge to a video or image

ffmpeg -i  file name .mp4 -vf pad=1080:720:0:56:black out.mp4

pad The following parameter values are : wide , high ,x coordinate ,y coordinate , The default is that the black edge can not be written
56:(720 - 680)/2=56
1080 x 608 The resolution becomes 1080 x 720 The resolution of the

Format

ffmpeg -i out.mp4 -vcodec copy -acodec copy out.flv

The command table above is audio 、 The videos are all direct copy, Just to mp4 The packaging format of is changed to flv.
copy Is to put the original unconditional

  • -i: Input file
  • -vcodec copy : Video coding processing method
  • -acodec copy: Audio coding processing method

Audio and video merge

ffmpeg -i out.h264 -i out.aac -vcodec copy -acodec copy out.mp4

extract YUV data

ffmpeg -i input.mp4 -an -c:v rawvideo -pixel_format yuv420p out.yuv

ffplay -s (wxh The resolution of the ,stream see ) out.yuv
  • -an: a representative audio,n representative no Not including audio
  • -c:v rawvideo Specifies to convert the video to raw data
  • -pixel_format yuv420p Specifies that the conversion format is yuv420p(4:2:0)

YUV turn H264

ffmpeg -f rawvideo -pix_fmt yuv420p -s 320x240 -r 30 -i out.yuv -c:v libx264 -f rawvideo out.h264

extract PCM data

ffmpeg -i out.mp4 -vn -ar 44100 -ac 2 -f s16le out.pcm

When playing, the parameters should be the same as the above , Because I don't know what sampling rate and channel you use

ffplay -ar 44100 -ac 2 -f s16le -i out.pcm
  • -vn: v representative video,n It means no video
  • -ar: a representative audio,r representative read, Sampling rate 44100 44.1k
  • -ac: a representative audio,c2 For two channels and stereo , Surround sound
  • -f: Audio extracted access format , s16 s Stands for signed , every 16 Who said

PCM turn WAV

ffmpeg -f s16be -ar 8000 -ac 2 -acodec pcm_s16be -i input.raw output.wav

View which devices are available

First, check the following command mac What are the devices on the .

ffmpeg -f avfoundation -list_devices true -i ""

Recording screen

yuv When playing, you need to specify the width and height

ffmpeg -f avfoundation -i 1 -r 30 out.yuv
  • -f Specify the use of avfoundation Collect data .
  • -i Specify where to collect data , It is a file index number . In my MAC On ,1 On behalf of the desktop ( You can query the device index number through the above command )(1 It's actually an index , The screen is 1, The camera is 0).
  • -r Specify the frame rate . Press ffmpeg The official document says -r And -framerate The same effect , But the actual test found a difference .-framerate Used to limit input , and -r Used to limit output .

Be careful , Desktop input has no requirements for frame rate , So don't limit the frame rate of the desktop . In fact, it's useless to limit .

Play

When recording, you will be prompted

Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 3360x2100,
q=2-31, 3386880 kb/s, 30 fps, 30 tbn, 30 tbc

-s 3360x2100
-pix_fmt uyvy422

ffplay -s xxxxx( The width and height you recorded ) -pix_fmt ( It is also the format when you record ) ./out.yuv

Recording screen + voice

ffmpeg  -f avfoundation -i 1:0  -r 29.97 -c:v libx264 -crf 0 -c:a libfdk_aac -profile:a aac_he_v2 -b:a 32k  out.flv
ffmpeg -y -f avfoundation -i 1:0 -framerate 60 -c:v libx264 -r 60 -pix_fmt yuv420p -preset 0 -crf 19 -c:a aac -b:a 192k "$HOME/Screen Record $(date "+%Y-%m-%d %H-%M-%S").mp4"
  • -i 1:0 In front of the colon “1” Represents the screen index number . Behind the colon "0" On behalf of the voice cable phase number .
  • -c:v With the parameters -vcodec equally , Represents a video encoder .c yes codec Abbreviation ,v yes video Abbreviation .
  • -crf yes x264 Parameters of . 0 Table lossless compression .
  • -c:a With the parameters -acodec equally , Indicates the audio encoder .
  • -profile yes fdk_aac Parameters of . aac_he_v2 Tabular use AAC_HE v2 compressed data .
  • -b:a Specify the audio rate . b yes bitrate Abbreviation , a yes audio Contraction and

Video recording

ffmpeg -framerate 30 -f avfoundation -i 0 out.mp4 
  • -framerate Limit the capture frame rate of video . This must be set according to the prompt requirements , If it is not set, an error will be reported .
  • -f Specify the use of avfoundation Collect data .
  • -i Specifies the index number of the video device

video + Audio

ffmpeg -framerate 30 -f avfoundation -i 0:0 out.mp4 

sound recording

ffmpeg -f avfoundation -i :0 out.wav

0 Is the index representing the device , You can go up to check

Record and play

ffplay ./out.wav

Record audio data

ffmpeg  -f avfoundation -i :0 -ar 44100 -f s16le out.pcm

Double the size of the video

ffmpeg -i out.mp4 -vf scale=iw/2:-1 scale.mp4
  • -vf scale Specify the use of simple filters scale,iw/2:-1 Medium iw Specifies the width of the video by integer . -1 Indicates that the height changes with the width .

Video clip

ffmpeg -i VR.mov  -vf crop=in_w-200:in_h-200 -c:v libx264 -c:a copy -video_size 1280x720 vr_new.mp4

crop Format :crop=out_w:out_h : x : y

  • out_w: The width of the output . have access to in_w Tabular input video width .
  • out_h: Output height . have access to in_h Table type input video height .
  • x : X coordinate
  • y : Y coordinate

If x and y Set to 0, Description from the top left corner to start cutting . If you don't write it, cut it from the center .

Speed up

ffmpeg -i out.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" speed2.0.mp4
  • -filter_complex Complex filter ,[0:v] Represents the first ( The index number of the document is 0) File video as input .setpts=0.5*PTS For each frame of video pts Time stamps are multiplied by 0.5, That's half the difference .[v] Indicates the alias of the output . The same goes for audio .
  • map Can be used to handle complex output , If you can output the specified multiplex stream to an output file , You can also specify output to multiple files ."[v]" Alias for complex filter output as a stream of output files . above map The usage is to output the video and audio output by the complex filter to the specified file .

Symmetrical video

ffmpeg  -i out.mp4 -filter_complex "[0:v]pad=w=2*iw[a];[0:v]hflip[b];[a][b]overlay=x=w" duicheng.mp4
  • hflip Flip horizontal

If you want to change it to vertical flip, you can use vflip.

Picture in picture

ffmpeg -i out.mp4 -i out1.mp4 -filter_complex "[1:v]scale=w=176:h=144:force_original_aspect_ratio=decrease[ckout];[0:v][ckout]overlay=x=W-w-10:y=0[out]" -map "[out]" -movflags faststart new.mp4

Record picture in picture

ffmpeg  -f avfoundation -i "1" -framerate 30 -f avfoundation -i "0:0" 
-r 30 -c:v libx264 -preset ultrafast 
-c:a libfdk_aac -profile:a aac_he_v2 -ar 44100 -ac 2 
-filter_complex "[1:v]scale=w=176:h=144:force_original_aspect_ratio=decrease[a];[0:v][a]overlay=x=W-w-10:y=0[out]" 
-map "[out]" -movflags faststart -map 1:a b.mp4

Multi channel video mosaic

ffmpeg  -f avfoundation -i "1" -framerate 30 -f avfoundation   -i "0:0" -r 30 -c:v libx264 -preset ultrafast -c:a libfdk_aac -profile:a aac_he_v2 -ar 44100 -ac 2 -filter_complex "[0:v]scale=320:240[a];[a]pad=640:240[b];[b][1:v]overlay=320:0[out]" -map "[out]" -movflags faststart  -map 1:a  c.mp4

Add watermark

ffmpeg -i out.mp4  -vf "movie=logo.png,scale=64:48[watermask];[in][watermask] overlay=30:10 [out]" water.mp4
  • -vf Medium movie Appoint logo Location .scale Appoint logo size .overlay Appoint logo Place .

Delete watermark

Through the first ffplay Find to delete LOGO The location of

ffplay -i test.flv -vf delogo=x=806:y=20:w=70:h=80:show=1

Use delogo Filter delete LOGO

ffmpeg -i test.flv -vf delogo=x=806:y=20:w=70:h=80 output.flv

tailoring

ffmpeg -i out.mp4 -ss 00:00:00 -t 10 out1.mp4
  • -ss Specify the start time of cutting , Accurate to seconds , when : branch : second
  • -t The length of time after being cut , The unit is in seconds

Merge

First create a inputs.txt file , The contents of the document are as follows :

file ‘1.flv’
file ‘2.flv’
file ‘3.flv’

Then execute the following command :

ffmpeg -f concat -i inputs.txt -c copy output.flv

hls section

ffmpeg -i out.mp4 -c:v libx264 -c:a libfdk_aac -strict -2 -f hls  out.m3u8
  • -strict -2 Indicates that the audio makes AAC.
  • -f hls Turn into m3u8 Format .

Video to JPEG

ffmpeg -i test.flv -r 1 -f image2 image-%3d.jpeg
  • -r : Frame rate of picture transfer out , Every second 1 A picture
  • -f : What format to convert the input file
  • %3d Is dynamic ,3 It's made up of two numbers

Video to gif

ffmpeg -i out.mp4 -ss 00:00:00 -t 10 out.gif

Picture to video

This will output all frames at once

ffmpeg  -f image2 -i image-%3d.jpeg images.mp4
  • -i : Indicates input , There are pictures behind

Play YUV data

ffplay -pix_fmt nv12 -s 192x144 1.yuv 

Play YUV Medium Y Plane

ffplay -pix_fmt nv21 -s 640x480 -vf extractplanes='y' 1.yuv
原网站

版权声明
本文为[Dog egg L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060920335772.html