ffmpeg - 命令大全-看这个就够了 useful commands (FFMPEG 命令大全)

访问量: 9495

see: http://www.labnol.org/internet/useful-ffmpeg-commands/28490/ for details


普通格式,转换成  libx264 的mp4:  (最标准最通用的mp4文件)

ffmpeg -i youtube.flv -c:v libx264 filename.mp4

把VCD DAT转换成mp4: 

ffmpeg - vcd dat 转换成mp4的注意: -vcodec copy, -acodec copy , 缺了就会报错

"C:\Dir\ffmpeg\bin\ffmpeg" -i %1 -vcodec copy -acodec copy "F:\TargetDir\%~n1.mp4"



ffmpeg -i "concat:VTS_01_1.VOB|VTS_01_2.VOB|VTS_01_3.VOB|VTS_01_4.VOB" -f dvd -c copy output.mpeg

这个时候得到的画面比例会失调(例如 720 x 480 , 而不是 720 x 540) ,


ffmpeg -i output.mpeg -s 720x540 -c:a copy output-720x540.mp4


ffmpeg -i 洗髓经上-720x540_2.00x_1920x1080_amq-12.mp4 -b:v 12000k xi-sui-jing-shang_1920.mp4

# 合并静态 图片和 声音 (声音需要先生成静音文件)

$ ffmpeg -i silence.mp3 -loop 1 -i zuoshi_title.jpg  -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest zuoshi_title.mp4

# 合并 音乐和 视频 (mp3 + mp4 )

$ ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental -shortest output.mp4


# add srt format subtitle to mp4:
$ ffmpeg -i zhangong-header.mp4 -vf subtitles=zhangong.srt zhangong-header-out.mp4

 # add subtitle to mp4 file (using ass format)
 ffmpeg -i zhangong.srt zhangong.ass
 ffmpeg -i zhangong-header.mp4 -vf 'ass=zhangong.ass' zhangong-header-subtitle.mp4

# 如果向现有的MP4中增加背景音乐,需要:

# 1. 从原来的MP4中获取MP3
 $ ffmpeg -i zuogong-ok.mp4 -vn -ab 256k zuogong_koulingci.mp3
# 2. 将 mp3 与 背景音乐MP3合并 ,成为 new_music.mp3 (using audacity) 
可以使用audacity, 具体过程略。
# 3. 将 原来的MP4静音, 注意这个 -c copy 特别关键,可以节约大量的时间, 并且回避mp4只能导出一部分的情况
 $ ffmpeg -i zuogong-ok.mp4 -an -c copy zuogong-muted.mp4
# 4. 合并静音后的MP4与 new_music.mp3
 $ ffmpeg -i zuogong-muted.mp4 -i zuogong-koulingci-with-music.mp3 -c:v copy -c:a aac -strict experimental zuogong-with-koulingci-and-music.mp4

转换成GIF动画: $ffmpeg -i climax.mp4 -ss 00:00:00 -pix_fmt rgb24 -r 10 -s 320x180 -t 00:00:12 out.gif

Extract the audio from a video file with this simple FFmpeg command.

Extract the audio from a video file with this simple FFmpeg command.

2. 把大video切割成多个小视频 Split a video into multiple parts

下面是说明: 一个是 从50s开始到结束, 切割成2个视频

If you want to split a large video into multiple smaller clips without re-encoding, ffmpeg can help. This command will split the source video into 2 parts – one ending at 50s from the start and the other beginning at 50s and ending at the end of the input video.

也可以用 -to 来代替 -t

ffmpeg -i video.mp4 -t 00:00:50 -c copy small-1.mp4 -ss 00:00:50 -codec copy small-2.mp4

ffmpeg.exe -ss 00:01:00 -i "in file.mp4" -to 00:01:00 -c copy out.mp4

分割完之后,一定要用播放器看一看,因为有时候会发现切割出来的视频,前9秒的画面是静止的。不知道是啥原因,你可以稍微修改一下 视频的切割时间(例如提前1秒)。就好了。

3. 转换视频格式 Convert video from one format to another

You can use the -vcodec parameter to specify the encoding format to be used for the output video. Encoding a video takes time but you can speed up the process by forcing a preset though it would degrade the quality of the output video.

ffmpeg -i youtube.flv -c:v libx264 filename.mp4
ffmpeg -i video.wmv -c:v libx264 -preset ultrafast video.mp4

4. Join (concatenate) video files 合并 多个文件:只能用这个。(concat -i file-list.txt的方式,见:https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg )

If you have multiple audio or video files encoded with the same codecs, you can join them into a single file using FFmpeg. Create a input file with a list of all source files that you wish to concatenate and then run this command.

ffmpeg -f concat -i file-list.txt -c copy output.mp4

file-list.txt 看起来是这样: (注意,在win7中文件名不能是中文。另外,只能用这个情况,不能用其他的 concat:file1|file2的形式)

file '2.1-register.mp4'
file '2.2-install.mp4'

把视频消音 . Mute a video (Remove the audio component)

Use the -an parameter to disable the audio portion of a video stream.

ffmpeg -i video.mp4 -an -c copy mute-video.mp4


The -vn switch extracts the audio portion from a video and we are using the -ab switch to save the audio as a 256kbps MP3 audio file.

ffmpeg -i video.mp4 -vn -ab 256k audio.mp3

合并视频和音频 10. Merge an audio and video file

You can also specify the -shortest switch to finish the encoding when the shortest clip ends.

ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental output.mp4
ffmpeg -i video.mp4 -i audio.mp3 -c:v copy -c:a aac -strict experimental -shortest output.mp4

7. Convert a video into animated GIF

FFmpeg is an excellent tool for converting videos into animated GIFs and the quality isn’t bad either. Use the scale filter to specify the width of the GIF, the -t parameter specific the duration while -r specifies the frame rate (fps).

ffmpeg -i video.mp4 -vf scale=500:-1 -t 10 -r 10 image.gif

8. Extract image frames from a video

This command will extract the video frame at the 15s mark and saves it as a 800px wide JPEG image. You can also use the -s switch (like -s 400×300) to specify the exact dimensions of the image file though it will probably create a stretched image if the image size doesn’t follow the aspect ratio of the original video file.

ffmpeg -ss 00:00:15 -i video.mp4 -vf scale=800:-1 -vframes 1 image.jpg

9. Convert Video into Images

You can use FFmpeg to automatically extract image frames from a video every ‘n’ seconds and the images are saved in a sequence. This command saves image frame after every 4 seconds.

ffmpeg -i movie.mp4 -r 0.25 frames_%04d.png

12. Create video slideshow from images

This command creates a video slideshow using a series of images that are named as img001.png, img002.png, etc. Each image will have a duration of 5 seconds (-r 1/5).

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p slideshow.mp4

13. Add a poster image to audio

You can add a cover image to an audio file and the length of the output video will be the same as that of the input audio stream. This may come handy for uploading MP3s to YouTube.

ffmpeg -loop 1 -i image.jpg -i audio.mp3 -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest output.mp4

14. Convert a single image into a video

Use the -t parameter to specify the duration of the video.

ffmpeg -loop 1 -i image.png -c:v libx264 -t 30 -pix_fmt yuv420p video.mp4

15. Add subtitles to a movie

This will take the subtitles from the .srt file. FFmpeg can decode most common subtitle formats.

ffmpeg -i movie.mp4 -i subtitles.srt -map 0 -map 1 -c copy -c:v libx264 -crf 23 -preset veryfast output.mkv

16. Crop an audio file

This will create a 30 second audio file starting at 90 seconds from the original audio file without transcoding.

ffmpeg -ss 00:01:30 -t 30 -acodec copy -i inputfile.mp3 outputfile.mp3

17. Change the audio volume

You can use the volume filter to alter the volume of a media file using FFmpeg. This command will half the volume of the audio file.

ffmpeg -i input.wav -af 'volume=0.5' output.wav

18. Rotate a video

This command will rotate a video clip 90° clockwise. You can set transpose to 2 to rotate the video 90° anti-clockwise.

ffmpeg -i input.mp4 -filter:v 'transpose=1' rotated-video.mp4

This will rotate the video 180° counter-clockwise.

ffmpeg -i input.mp4 -filter:v 'transpose=2,transpose=2' rotated-video.mp4

19. Speed up or Slow down the video

You can change the speed of your video using the setpts (set presentation time stamp) filter of FFmpeg. This command will make the video 8x (1/8) faster or use setpts=4*PTS to make the video 4x slower.

ffmpeg -i input.mp4 -filter:v "setpts=0.125*PTS" output.mp4

20. Speed up or Slow down the audio

For changing the speed of audio, use the atempo audio filter. This command will double the speed of audio. You can use any value between 0.5 and 2.0 for audio.

ffmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv

Stack Exchange has a good overview to get you started with FFmpeg. You should also check out the official documentation at ffmpeg.org or the wiki at trac.ffmpeg.org to know about all the possible things you can do with FFmpeg.

Also see: Essential Linux Commands

订阅/RSS Feed