Some common commands of ffmpeg

Today's topic: some commonly used commands of ffmpeg What ...

Today's topic: some commonly used commands of ffmpeg

What is ffmpeg and why is it a tool? Its awesome point is that this tool is used at the bottom of most video editing software. It can perform various operations on video, and editing is OK. Let me talk about some simple commands.

reference resources: https://blog.csdn.net/weixin_42081389/article/details/100543007

ffmpeg visual interface software: Quick Cut reference: https://zhuanlan.zhihu.com/p/163652478

Some ffmpeg command parameters:

Insert picture description here

General options

command

explain

-L

license

-h

help

-fromats

Display available formats, codec, protocol...

-f fmt

Forced format fmt

-I filename

input file

-y

Overwrite output file

-t duration

Setting the recording time in hh:mm:ss[.xxx] format is also supported

-ss position

The format of searching for the specified time [-] hh:mm:ss[.xxx] is also supported

-title string

Set title

-author string

Set author

-copyright string

Set copyright

-comment string

Set comments

-target type

Set all format options (bit rate, codec and buffer size) of the target file type (vcd,svcd,dvd) automatically. Just enter the following: ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg

-hq

Activate high quality settings

-itsoffset offset

Set the time offset based on seconds, which 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. The format of [-] hh:mm:ss[.xxx] is also supported

Video options

command

explain

-b bitrate

Set the bit rate. The default is 200kb/s

-r fps

Set frame rate default 25

-s size

Set the frame size format to WXH default 160X128. The following abbreviations can also be used directly: Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576

-aspect aspect

Set the aspect ratio of 4:3 16:9 or 1.3333 1.7777

-croptop size

Sets the size of the top cut band in pixels

-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 complement bar (hex, six hexadecimal numbers, arranged in red: Green: blue, for example, 000000 represents black)

-vn

No video recording

-bt tolerance

Set video bit rate tolerance kbit/s

-maxrate bitrate

Set maximum video bit rate tolerance

-minrate bitreate

Set minimum video bit rate tolerance

-bufsize size

Set rate control buffer size

-vcodec codec

The codec encoding and decoding mode is mandatory. If copy is used, the original codec data must be copied.

-sameq

Use the same video quality as the source (VBR)

-pass n

Select the number of processing passes (1 or 2). Double coding is very useful. The first pass generates statistical information, and the second pass generates the exact requested bit rate

-passlogfile file

The name of the record file selected twice is file

advanced video option

command

explain

-g gop_size

Set image group size

-intra

Intra coding only

-qscale q

Use 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 softening (VBR)

-qcomp compression

Video quantization scale compression (VBR)

-rc_init_cplx complexity

Initial complexity of one pass coding

-b_qfactor factor

qp factor between p and b frames

-i_qfactor factor

qp factor between p and i frames

-b_qoffset offset

qp deviation between p and b frames

-i_qoffset offset

qp deviation between p and i frames

-rc_eq equation

Set default tex^qComp for rate control equation

-rc_override override

Rate control overload at specific interval

-me method

Set the method of motion estimation. The available methods are zero photos log X1 EPZs (default) full

-dct_algo algo

0 FF is available for the algorithm for setting dct_ 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

Set idct algorithm. 0 FF is available_ idct_ Auto default IDCT 1 FF_IDCT_INT 2 FF_IDCT_SIMPLE 3 FF_IDCT_SIMPLEMMX 4 FF_IDCT_LIBMPEG2MMX 5 FF_IDCT_PS2 6 FF_IDCT_MLIB 7 FF_IDCT_ARM 8 FF_IDCT_ALTIVEC 9 FF_IDCT_SH4 10 FF_IDCT_SIMPLEARM

-er n

Set error residue to n 1 FF_ER_CAREFULL default 2 FF_ER_COMPLIANT 3 FF_ER_AGGRESSIVE 4 FF_ER_VERY_AGGRESSIVE

-ec bit_mask

Set error masking to bit_mask, which is the bitmask 1 FF of the following values_ EC_ GUESS_ MVS (default=enabled) 2 FF_ EC_ DEBLOCK (default=enabled)

-bf frames

Use frames B frames and support MPEG1, MPEG2 and mpeg4

-mbd mode

Macroblock decision 0 FF_MB_DECISION_SIMPLE uses mb_cmp 1 FF_MB_DECISION_BITS 2 FF_MB_DECISION_RD

-4mv

Use 4 motion vectors for MPEG 4 only

-part

Use data partitioning for MPEG 4 only

-bug param

Bypass the problem that the encoder is not automatically monitored

-strict strictness

With the strictness of the standard

-aic

Enable advanced intra coding h263+

-umv

Enable infinite motion vector h263+

-deinterlace

No interleaving method

-interlace

Forced weaving coding is only valid for MPEG 2 and MPEG 4. Use this option when your input is interleaved and you want to keep interleaving with minimal image loss. The optional method is not interleaving, but the loss is greater

-psnr

Calculate psnr of compressed frame

-vstats

Output video coding statistics to vstats_hhmmss.log

-vhook module

Insert the video processing module. The module includes the module name and parameters, separated by spaces

Audio options

command

explain

-ab bitrate

Set audio bit rate

-ar freq

Set audio sampling rate

-ac channels

Set the channel to 1 by default

-an

Disable audio recording

-acodec codec

codec

Audio / video capture options

command

explain

-vd device

Set up a video capture device. For example, / dev/video0

-vc channel

Set the dedicated video capture channel DV1394

-tvstd standard

Set TV standard NTSC PAL(SECAM)

-dv1394

Set DV1394 capture

-av device

Set up audio devices such as / dev/dsp

Advanced options

command

explain

-map file:stream

Set input stream mapping

-debug

Print specific debugging information

-benchmark

Add time for benchmark

-hex

Dump each input packet

-bitexact

Only bit accurate algorithm is used for codec test

-ps size

Sets the package size in bits

-re

Read data at local frame rate, mainly used for analog capture equipment

-loop

Loop input stream. Only works in image stream for ffserver test

avi to MP4 command:
ffmpeg -i .\Video.avi -c copy -map 0 video.mp4 or ffmpeg -i .\Video.avi -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 video.mp4 //Cut video ffmpeg -ss 0:1:30 -t 0:0:50 -i 1.avi -vcodec copy -acodec copy 3.mp4 //-r frequency of image extraction, - ss start time, - t duration
MP4 RPM ts
ffmpeg -i .\video.mp4 output.ts
video compression
1)ffmpeg -i 123_ffmpeg.mp4 (The compressed file is larger and clearer, which is generally not used) 2)ffmpeg.exe -i 123.MP4 -b:v 700k 1231_ffmpeg.mp4(Compressed (smaller, relatively blurred)
Remove video sound
ffmpeg -i 1.avi -vcodec copy -an 2.avi
Merge audio and video
ffmpeg -i a.wav -i a.avi out.avi

If the audio is longer than the video, the picture stays at the last frame and continues to play the sound.

Add watermark to video
ffmpeg -i result2.mp4 -vf "drawtext=fontfile=FZBaoHTJW_Xi.TTF: text='Creator: Fen Yu_Brake':x=100:y=10:fontsize=24:fontcolor=yellow:shadowy=2" drawtext.mp4
Video clip
//Intercept 30s from the beginning ffmpeg -ss 00:00:00 -t 00:00:30 -i keyoutput.mp4 -vcodec copy -acodec copy split.mp4 //Intercept 30s from 30s ffmpeg -ss 00:00:30 -t 00:00:30 -i keyoutput.mp4 -vcodec copy -acodec copy split1.mp4
Add subtitles to video srt

reference resources: https://moejj.com/ffmpeg-add-subtitles-and-watermark/

ffmpeg -i video.avi -vf subtitles=subtitle.srt out.avi
Add music + subtitles to the video at the same time
ffmpeg -i .\1111.mp4 -i .\2222.mp3 -vf subtitles=all_mp3_srt.srt out2.avi
Convert mp4 using ffmpeg webm

reference resources: http://www.voidcn.com/article/p-evqojtvk-bta.html

ffmpeg -fflags +genpts -i .\111.webm -r 24 1.mp4

Explanation:

  • -The video generated by r 24 code is 24 frames, you can also change it to 30 or 60
  • -I. \ 111.webm 111.webm is a WebM format video in my current directory
  • 1.mp4 will generate this mp4 video in the current directory
Merge two mp4 videosFirst create a name.txt
file 'split1.mp4' file 'split2.mp4'

Insert picture description here

Command merge
ffmpeg -f concat -i name.txt -c copy output.mp4

Insert picture description here

Video format usage

ffmpeg -i 1.mp4 -vcodec mpeg2video -s 1920x1080 -q:v 1 -acodec copy -f mpegts 2.flv

The video definition of the conversion format is OK

Operate with java code

/** * Simple video processing -- (cmd(windows): ffmpeg.exe -i test1.mp4 newVideo.avi) * * @param ffmpegPath ffmpeg.exe The file path can be configured in rest or admin and read using the configuration file * @param videoInputPath Video file path (input) * @param videoOutputPath Converted file path (output) * @throws IOException */ public static void videoConvert(String ffmpegPath, String videoInputPath, String videoOutputPath) throws IOException { // Build command String videoCommend=ffmpegPath+" -i "+videoInputPath+" -vcodec mpeg2video -s 1920x1080 -q:v 1 -acodec copy -f mpegts "+videoOutputPath; // Perform operation ProcessBuilder builder = new ProcessBuilder(videoCommend.split(" ")); Process process = builder.start(); InputStream errorStream = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(errorStream); BufferedReader br = new BufferedReader(isr); String line = ""; while ((line = br.readLine()) != null) { } if (br != null) { br.close(); } if (isr != null) { isr.close(); } if (errorStream != null) { errorStream.close(); } }

Extract audio and video from video

The pure video extracted from a video does not contain audio:

ffmpeg -i E:\hevc\2.mp4 -vcodec copy -an E:\hevc\2_bak.mp4

Extract audio files from a video:

ffmpeg -i E:\hevc\2.mp4 -acodec libmp3lame -vn E:\hevc\2_copy.mp3

Other audio formats: https://blog.csdn.net/zhubao124/article/details/104740770

Merge audio and video

If there is no audio in this video

ffmpeg.exe -i C:\Users\29265\Desktop\Like fish.mp3 -i C:\Users\29265\Desktop\1\2_copy.mp4 -t 300 -y C:\Users\29265\Desktop\1\newVideo.mp4

Video screenshot by frame

reference resources: https://zhuanlan.zhihu.com/p/38961122

It is mainly used for users to manually take screenshots or upload videos to generate thumbnails.

Here: - ss position the format of the specified time [-] hh:mm:ss[.xxx] is also supported, and - vframes sets how many frames of video are converted. This command is to obtain a screenshot of the first frame in the first second.

Note: the generated screenshot is best in jpg format, which takes up less space. If other formats need to be used, it can be set according to business needs.

ffmpeg.exe -ss 00:00:01 -y -i test1.mp4 -vframes 1 new.jpg

Implemented in java code:

/** * Audio and video merge, video end, audio end -- (cmd(windows): ffmpeg.exe -i test2.mp3 -i test1.mp4 -t 10 -y newVideo.mp4) * * @param ffmpegPath ffmpeg.exe The file path can be configured in rest or admin and read using the configuration file * @param audioInputPath Audio file path (input) * @param videoInputPath Video file path (input) * @param time File duration * @param videoOutputPath Converted file path (output) * @throws IOException */ public static void audioVideoMerge(String ffmpegPath, String audioInputPath, String videoInputPath, double time, String videoOutputPath) throws IOException { // Build command List<String> command = Lists.newArrayList(); command.add(ffmpegPath); command.add("-i"); command.add(audioInputPath); command.add("-i"); command.add(videoInputPath); command.add("-t"); command.add(String.valueOf(time)); command.add("-y"); command.add(videoOutputPath); // Perform operation ProcessBuilder builder = new ProcessBuilder(command); Process process = builder.start(); InputStream errorStream = process.getErrorStream(); InputStreamReader isr = new InputStreamReader(errorStream); BufferedReader br = new BufferedReader(isr); String line = ""; while ((line = br.readLine()) != null) { } if (br != null) { br.close(); } if (isr != null) { isr.close(); } if (errorStream != null) { errorStream.close(); } }

30 November 2021, 04:46 | Views: 9672

Add new comment

For adding a comment, please log in
or create account

0 comments