FFMPEG maybe you have not heard, but storm video, QQ video, VLC, format factory…
preface
FFMPEG maybe you have not heard, but storm video, QQ video, VLC, format factory…
A lot of you probably felt the same way I did when I first got into it, what does this have to do with the front end?
What can YOU do with FFMPEG?
Function is introduced
Video capture function
ffmpeg -f avfoundation -framerate 30 -i "0" -vcodec h264 -f flv rtmp://localhost:1935/live/movie
Copy the code
- -f Specifies the input or output file format. The format of the input file is usually automatically detected and guessed from the file extension of the output file, so this option is not required in most cases.
- -framerate controls the FPS framerate with -r
Video screenshot function
ffmpeg -i 0723.flv -ss 60 -f image2 test60.jpeg
Copy the code
- -I: indicates the input stream, followed by the physical path of the video, such as MP4 or AVI
- -ss: indicates the position of the image to be captured in the video, followed by a number, in seconds
- -f: indicates the output image followed by image2
Video format conversion
ffmpeg -i 0723.flv -vf "movie=logo.png[watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10[out] " output.mp4
Copy the code
Add watermark to video/picture
- Image watermarking
ffmpeg -i 0723.flv -vf "movie=wenzi.png[watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10[out] " output.mp4
Copy the code
- – I: input
- 0723. FLV video source
- Vf filter correlation, video cropping, watermarking is completed here
- Overlay watermark parameter
- Main_w-overlay_w_10 Watermark is located on the X-axis, x= main_W-overlay_W-10
- Main_h-overlay_h-10 Position of the watermark on the Y-axis
ffmpeg -i 0723.flv -i iQIYI_logo.png -filter_complex overlay output.mp4
Copy the code
- -i input
- -filter_complex Filter Solves the problem of multiple watermarks in complex filters
- Overlay default parameter
- The output output
- Text watermarking
ffmpeg -i 0723.flv -vf "Drawtext =fontfile=simhei. TTF: text= 'Tip Studio' :x=10:y=10:fontsize=24:fontcolor=white:shadowy=2"Iceberg. FLVCopy the code
or
ffmpeg -i 0723.flv -b:v 2M -vf "Drawtext =fontfile=simhei. TTF: text= 'Tip Studio' :x=10:y=10:fontsize=24:fontcolor=white:shadowy=2"Iceberg. FLVCopy the code
What’s the difference?
- -b: Sets the bit rate to adjust the picture quality
Combine image sequences into video
ffmpeg -f image2 -i image%d.jpg binshan.mp4
Copy the code
Decompose the video into a sequence of images
ffmpeg -i bingshan.mp4 image%d.jpg
Copy the code
Pull the sound from the video. Coexist as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
Copy the code
- Source video: source_video.avi
- Audio bit rate: 192KB /s
- Output format: MP3
- Generated sound: sound.mp3
Synthesize video and audio
ffmpeg -i son.wav -i video_origine.avi video_finale.mp4
Copy the code
Extract mp3 from FLV
ffmpeg -i source.flv -ab 128k dest.mp3
Copy the code
A) Generic options
-L license
– h help
-fromats displays available formats, codecs, protocols…
-f FMT Forces the format FMT
-i filename Indicates the input file
-y overwrites the output file
-t duration Sets the record time. The record time in hh:mm:ss[. XXX] format is also supported
-ss position Specifies the time to search for. The format of hh:mm:ss[. XXX] is also supported
-title string Sets the title
-author string Sets the author
-copyright string Sets the copyright
-comment string Sets comments
-target type Sets all the format options (bit rate, codec, and buffer size) of the target file type (VCD, SVCD, DVD) to be automatically set. ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
– HQ enables high quality Settings
-itsoffset offset Sets the time offset in seconds. This option affects all subsequent input files. The offset is added to the timestamp of the input file, and defining a positive offset means that the corresponding stream is delayed by offset seconds. [-]hh:mm:ss[.xxx] is also supported
B) Video options
-b bitrate sets the bitrate. The default value is 200kb/s
-r FPS The default frame rate is 25
-s size Sets the frame size format to WXH 160X128 by default. The following abbreviation can also be used directly:
Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576
– Aspect Set aspect ratio 4:3 16:9 or 1.3333 1.7777
– cropTop Size Sets the top strip size in pixel units
– Cropbottom size – Cropleft size – Cropright size
– padTOP Size Sets the size of the top fill in pixels
-padbottom size — padleft size — padright size — padcolor color Set the color of the patch bar (hex, red, green, blue, for example, 000000)
– VN does not record videos
-bt tolerance Sets the video bit rate tolerance kbit/s
-maxrate bitrate sets the maximum video bitrate tolerance
-minrate bitreate Sets the minimum video bit rate tolerance
-bufsize size Sets the bit rate control buffer size
-vcodec codec forces the codec mode to be used. If you use copy to mean that the original codec data must be copied.
– Sameq uses the same video quality as the source (VBR)
-pass n Indicates the number of processing times (1 or 2). Double coding is very useful. The first pass generates statistics, and the second pass generates the exact requested bit rate
– passlogFile file Specifies the name of the record file to be selected twice
C) Advanced video options
-g gop_size Sets the image group size
– INTRA Applies only to intra-frame coding
– QScale Q uses fixed video quantization scale (VBR)
– Qmin Q Minimum video quantization scale (VBR)
– Qmax Q Maximum video quantization scale (VBR)
-QDIFF Q Maximum deviation between quantization scales (VBR)
– QBLUR Blur Video Quantization Scale (VBR)
– QCOMP Video Quantization scale Compression (VBR)
-rc_init_cplx Specifies the initial complexity of the code
– b_qFactor Factor Indicates the QP factor between frames P and B
-i_qFactor Factor Indicates the QP factor between frames P and I
-b_qoffset Offset Specifies the QP offset between FRAMES P and B
-i_qoffset Offset Specifies the QP offset between FRAMES P and I
-rc_eq equation Sets the code rate control equation to default Tex ^qComp
-rc_override Override Overrides the rate control at a specified interval
-me method Zero Phods log X1 EPZS (default) full is available for setting motion estimation
-dct_algo algo Indicates the algorithm for setting DCT. The options are 0 FF_DCT_AUTO Default DCT 1 FF_DCT_FASTINT 2 FF_DCT_INT 3 FF_DCT_MMX 4 FF_DCT_MLIB 5 FF_DCT_ALTIVEC
-idct_algo algo Sets the IDCT algorithm. 0 FF_IDCT_AUTO Default IDCT 1 FF_IDCT_INT 2 FF_IDCT_SIMPLE 3 FF_IDCT_SIMPLEMMX 4 FF_IDCT_LIBMPEG2MMX 5 FF_IDct_ps26 FF_IDCT_MLIB 7 FF_IDCT_ARM 8 FF_IDCT_ALTIVEC 9 FF_IDCT_SH4 10 FF_IDCT_SIMPLEARM
-er n N 1 FF_ER_CAREFULL 2 FF_ER_COMPLIANT 3 FF_ER_AGGRESSIVE 4 FF_ER_VERY_AGGRESSIVE
-ec bit_mask Sets the error masking to bit_mask, which is the bitmask of the following values: 1 FF_EC_GUESS_MVS (default=enabled) 2 FF_EC_DEBLOCK (default=enabled)
-bf Frames Frames B frames and supports MPEg1, MPEG2, and MPEG4
– MBD mode Macro block decision 0 FF_MB_DECISION_SIMPLE Uses MB_CMP 1 FF_MB_DECISION_BITS 2 FF_MB_DECISION_RD
-4MV uses 4 motion vectors for MPEG4 only
– Part Uses data partition only for MPEG4
– Bug Param bypasses encoders that are not automatically detected
-strict strictness specifies the quality of being up to date
-aic Enables advanced intra-frame coding H263 +
– UMV Enables the infinite motion vector H263 +
– Deinterlace does not use interlace
– Interlace Is valid only for MPEG2 and MPEG4. Use this option when your input is interleaved and you want to keep it interleaved with minimal image loss. The alternative is not to interweave, but the loss is greater
– PSNR Computes the PSNR of compressed frames
-vstats Displays video coding statistics to vstats_hmmmss. log
-vhook Module Inserts the video processing module. The module contains the module name and parameters separated by Spaces
D) Audio options
-ab bitrate sets the audio bitrate
-ar freq Sets the audio sampling rate
– AC channels Sets the default value of channels to 1
-an Indicates that audio recording is disabled
-acodec codec codec is used
E) Audio/video capture options
-vd device Sets the video capture device. For example, / dev/video0
– VC channel Specifies the dedicated video capture channel DV1394
– TVSTD Standard sets NTSC PAL(SECAM)
-dv1394 Sets dv1394 capture
-av device Sets audio devices such as /dev/dsp
F) Advanced options
-map file:stream Sets the input stream mapping
-debug Displays specific debugging information
-benchmark Indicates the time of a benchmark test
-hex Dumps each input packet
-bitexact Uses only the bit-exact algorithm for codec testing
-ps size Sets the packet size, in bits
-re Reads data at the local frame rate and is used to simulate the capture device
-loop Loop input stream (image stream only, for FFServer testing)