当前位置:网站首页>Memo list: useful commands for ffmpeg command line tools

Memo list: useful commands for ffmpeg command line tools

2022-06-24 16:20:00 mariolu

FFmpeg Memo list

ffmpeg A list of useful commands for command line tools .

download FFmpeg: https://www.ffmpeg.org/download.html

Complete documentation : https://www.ffmpeg.org/ffmpeg.html


Basic conversion

ffmpeg -i in.mp4 out.avi

take MKV File remixing MP4

ffmpeg -i in.mkv -c:v copy -c:a copy out.mp4

High quality coding

Use crf( Constant rate factor ) Parameters to control the output quality .crf The lower the , The higher the quality ( Range :0-51). The default value is 23, And visual lossless compression corresponds to -crf 18. Use preset The parameter controls the speed of the compression process . Additional information : https://trac.ffmpeg.org/wiki/Encode/H.264

ffmpeg -i in.mp4 -preset slower -crf 18 out.mp4

Trim

No need to recode :

ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
  • -ss Specify the start time , for example 00:01:23.000 or 83( In seconds )
  • -t Specify the duration of the clip ( Same format ).
  • Latest version ffmpeg There is also a flag to provide the end time -to.
  • -c Copy the first video , Audio and caption bitstreams are copied from the input to the output file , Without having to recode it . This does not compromise quality and makes the command run in seconds .

Use recoding :

If you don't specify -c copy This option ,ffmpeg The output video and audio will be automatically re encoded according to the format you select . To get high quality video and audio , Please read separately 《x264 Coding guide 》 and 《AAC Coding guide 》.

https://ffmpeg.org/trac/ffmpeg/wiki/x264EncodingGuide

http://ffmpeg.org/trac/ffmpeg/wiki/AACEncodingGuide

for example :

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4

Mix audio from video and other videos

From you to in0.mp4 Copy the video and from in1.mp4 Copy audio , Do the following :

ffmpeg -i in0.mp4 -i in1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4
  • Use -c Copy , Carry out convection stream copied Recode , Without recoding it , Therefore, it will not cause quality loss . If you want to recode , Please see the FFmpeg Wiki:H.264 Coding guide .
  • The -shortest Option will match the output duration to the duration of the shortest input stream .
  • For more information , see also -map file .

Merge video

First , Make a text file

file 'in1.mp4'
file 'in2.mp4'
file 'in3.mp4'
file 'in4.mp4'

then , function ffmpeg:

ffmpeg -f concat -i list.txt -c copy out.mp4

Delayed audio / video

Delay movie 3.84 second :

ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 1:v -map 0:a -vcodec copy -acodec copy out.mp4

Delayed audio 3.84 second :

ffmpeg -i in.mp4 -itsoffset 3.84 -i in.mp4 -map 0:v -map 1:a -vcodec copy -acodec copy out.mp4

Burn subtitles

Use libass library ( Make sure ffmpeg The installation has this library in the configuration --enable-libass).

First convert the subtitle to .ass Format :

ffmpeg -i sub.srt sub.ass

Then add them using video filters :

ffmpeg -i in.mp4 -vf ass=sub.ass out.mp4

Extract frames from video

To extract 1 To 5 Seconds and 11 To 15 All frames between seconds , Do the following :

ffmpeg -i in.mp4 -vf select='between(t,1,5)+between(t,11,15)' -vsync 0 out%d.png

Only one frame per second is extracted :

ffmpeg -i in.mp4 -fps=1 -vsync 0 out%d.png

Rotate video

Clockwise rotation 90:

ffmpeg -i in.mov -vf "transpose=1" out.mov

about transpose Parameters , You can deliver :

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

Use -vf "transpose=2,transpose=2"180 degree .


download “ Transport stream ” Video streaming

  1. Find the playlist file , For example, using Chrome> F12> The Internet > filter :m3u8
  2. Download and connect video clips :
ffmpeg -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4

If you receive “ agreement 'https Not on the white list ' file , password ' On !” error , Please add protocol_whitelist Options :

ffmpeg -protocol_whitelist "file,http,https,tcp,tls" -i "path_to_playlist.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4

Mute some audio clips

To set the front of the audio 90 Seconds is replaced by mute , Do the following :

ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='lte(t,90)':volume=0" out.mp4

To put 1'20“ and 1'30” Replace all audio between with mute , Do the following :

ffmpeg -i in.mp4 -vcodec copy -af "volume=enable='between(t,80,90)':volume=0" out.mp4

Deinterlace

ffmpeg -i in.mp4 -vf yadif out.mp4

Create video slides from images

Parameters :-r Mark image frame rate ( Countdown time of each image );-vf fps=25 Mark the real frame rate of the output .

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4

Extract images from video

  • Extract all frames : ffmpeg -i input.mp4 thumb%04d.jpg -hide_banner
  • Extract one frame per second : ffmpeg -i input.mp4 -vf fps=1 thumb%04d.jpg -hide_banner
  • Only one frame is extracted : ffmpeg -i input.mp4 -ss 00:00:10.000 -vframes 1 thumb.jpg

Metadata : Change the title

ffmpeg -i in.mp4 -map_metadata -1 -metadata title="My Title" -c:v copy -c:a copy out.mp4
原网站

版权声明
本文为[mariolu]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/04/20210428085908217l.html