![ffmpeg命令教程](https://i-blog.csdnimg.cn/blog_migrate/f85574b9039d05e65be4266bd7a1bdf7.png)
ffmpeg命令教程
In today’s multimedia world there are a lot of different formats for video and audio. In order to use video and audio we generally need to convert and edit operations. There are different tools for this job but the most popular and useful tool is FFmpeg. FFmpeg is used by a lot of different free and commercial software. It provides a very large feature set. In this tutorial, we will look most wanted and useful features like a convert, resize,… of FFmpeg. FFmpeg is a free video editing software that works from the command line. As we know FFmpeg is provided for Windows operating systems too. So following commands will work seamlessly in Windows operating systems to if FFmpeg is downloaded and set up correctly.
在当今的多媒体世界中,视频和音频有许多不同的格式。 为了使用视频和音频,我们通常需要转换和编辑操作。 有多种工具可用于此工作,但最流行和有用的工具是FFmpeg。 FFmpeg被许多不同的免费和商业软件使用。 它提供了非常大的功能集。 在本教程中,我们将介绍最常用和有用的功能,例如FFmpeg的转换,调整大小等。 FFmpeg是从命令行运行的免费视频编辑软件。 众所周知,FFmpeg也为Windows操作系统提供。 因此,如果下载并正确设置了FFmpeg,以下命令将在Windows操作系统中无缝运行。
显示视频信息 (Display Video Information)
Video files have different options about their structure. These information can be display with ffmpeg.
视频文件的结构有不同的选择。 这些信息可以用ffmpeg显示。
$ ffmpeg -i jellyfish-3-mbps-hd-h264.mkv
![Display Video Information](https://i-blog.csdnimg.cn/blog_migrate/2c129c85aa678403e1f305aa4dbc0c56.png)
Ffmeg will display following information;
Ffmeg将显示以下信息;
encoder
shows video encoder of the video file.encoder
显示视频文件的视频编码器。creation_time
describes the create time as year,month,day, hour, minute, second.creation_time
将创建时间描述为年,月,日,小时,分钟,秒。Duration
describes the length of the video file in hour:minute:second format.Duration
长以小时:分钟:秒格式描述视频文件的长度。Stream
show video stream information. A video file like mkv, mp4 may have more than one .stream for different purposes. In this example, we have only one stream with index 0:0 . There is information about the video stream like a video format resolution frame per second.Stream
显示视频流信息。 像mkv,mp4这样的视频文件可能出于不同目的具有多个.stream。 在此示例中,我们只有一个索引为0:0的流。 有关于视频流的信息,例如每秒的视频格式分辨率帧。
使用FFmpeg显示音频信息 (Display Audio Information with FFmpeg)
We can also get audio information from video file or audio file.
我们还可以从视频文件或音频文件中获取音频信息。
$ ffmpeg -i test.mp3
![Display Audio Information](https://i-blog.csdnimg.cn/blog_migrate/e300d03045f598cf60272a5853b45b6f.png)
There are following information about the audio file.
以下是有关音频文件的信息。
genre
describes the musical type of mp3 as metadatagenre
将mp3的音乐类型描述为元数据Duration
describes the length of the video file in hour:minute:second formatDuration
长以小时:分钟:秒格式描述视频文件的长度Stream
show audio information like format type, quality of the streamStream
显示音频信息,例如格式类型,流质量
将Mkv转换为Mp4(Convert Mkv To Mp4)
Now we can start converting files into different format. We will start converting Mkv
video file into Mp4
format. In this example we will convert file named jellyfish.mkv
into jellyfish.mp4
现在我们可以开始将文件转换为其他格式。 我们将开始将Mkv
视频文件转换为Mp4
格式。 在此示例中,我们将名为jellyfish.mkv
文件转换为jellyfish.mp4
$ ffmpeg -i jellyfish.mkv jellyfish.mp4
![Convert Mkv To Mp4](https://i-blog.csdnimg.cn/blog_migrate/ae8946e3aa5d60a91b1f76e7bfe7ed15.png)
In the example, the first thing is printing the source file information and then the convert operation starts. During the convert operation following statistical information is provided in real-time.
在该示例中,第一件事是打印源文件信息,然后开始转换操作。 在转换操作期间,实时提供以下统计信息。
frame
show currently processes frame countframe
显示当前正在处理帧数fps
show the count of frames processed in one secondfps
显示在一秒钟内处理的帧数Lsize
shows the destination or new file sizeLsize
显示目标或新文件的大小time
shows current position of the convert process in the video length in timetime
显示转换过程在视频时长中的当前位置bitrate
shows the bit size of a second length of the videobitrate
显示视频的第二长度的比特大小
将Flash和Flv转换为Mp4 (Convert Flash and Flv To Mp4)
Flash files can be converted to Mp4 like below.
可以将Flash文件转换为Mp4,如下所示。
$ ffmpeg -i jellyfish.flv jellyfish.mp4
![Convert Flash and Flv To Mp4](https://i-blog.csdnimg.cn/blog_migrate/e7e829b61b4cfd7df453815b5b7a8e80.png)
使用FFmpeg将Mp4转换为Mp3 (Convert Mp4 To Mp3 with FFmpeg)
Mp4 files are mainly used for mobile media devices or smartphones. This type of video can be converted to the mp3 audio file with the following command.
Mp4文件主要用于移动媒体设备或智能手机。 可以使用以下命令将这种类型的视频转换为mp3音频文件。
$ ffmpeg -i jellyfish.mp4 -q:a 0 jellyfish.mp3
使用FFmpeg将Mp4转换为Avi (Convert Mp4 To Avi with FFmpeg)
Mp4 is a popular format as stated before. In the old time avi
was the most popular advanced format.
如前所述,MP4是一种流行的格式。 在过去, avi
是最流行的高级格式。
$ ffmpeg -i jellyfish.mp4 jellyfish.avi
![Convert Mp4 To Avi](https://i-blog.csdnimg.cn/blog_migrate/d413d1fcd667078456fbada026d07e18.png)
使用FFmpeg将Mp4转换为Gif (Convert Mp4 To Gif with FFmpeg)
Gif
format is generally used to show simple, low size video to the user in the web pages without video players. Gif is a picture format that can store motions as different frames in pictures.
Gif
格式通常用于在没有视频播放器的情况下向用户显示简单的低尺寸视频。 Gif是一种图片格式,可以将运动存储为图片中的不同帧。
$ ffmpeg -i jellyfish.mp4 jellyfish.gif
![Convert Mp4 To Gif](https://i-blog.csdnimg.cn/blog_migrate/2d50e81b8a791e350b98b4976f263641.png)
使用FFmpeg将Avi转换为Mp4 (Convert Avi To Mp4 with FFmpeg)
We can convert avi
to mp4
with the following command.
我们可以使用以下命令将avi
转换为mp4
。
$ ffmpeg -i jellyfish.avi jellyfish.mp4
使用FFmpeg从视频文件中提取音频 (Extract Audio From Video File with FFmpeg)
We can extract audio stream from the video file and save audio as a separate file in formats like aac
, mp3
, vorbis
etc. We will provide -vn -ab 128
options. -ab 128
specifies the bitrate. The audio extraction will be done very little time.
我们可以从视频文件中提取音频流,并将音频保存为单独的文件,例如aac
, mp3
, vorbis
等格式。我们将提供-vn -ab 128
选项。 -ab 128
指定比特率。 音频提取将花费很少的时间。
$ ffmpeg -i Funny.mkv -vn -ab 128 Funny.mp3
![Extract Audio From Video File](https://i-blog.csdnimg.cn/blog_migrate/52b46f664d66b7662ee3a21e5a61d59a.png)
使用FFmpeg从视频中静音或删除音频(Mute or Remove Audio From Video with FFmpeg)
As we see previous example audio file is stored as separate stream. This gives the ability to mute audio of the video file. We will use -an
option to mute audio.
如我们所见,前面的示例音频文件存储为单独的流。 这样就可以使视频文件的音频静音。 我们将使用-an
选项使音频静音。
$ ffmpeg -i Funny.mkv -an Funny_muted.mkv
![Mute Audio](https://i-blog.csdnimg.cn/blog_migrate/c79992a7629cdedfaac2ddbccf264fd5.png)
使用FFmpeg调整视频分辨率(Resize Video Resolution with FFmpeg)
Video files can be resized. Scaling down the resolution will made the video file less in size. We will use -s
with the new resoution x
and y
sizes. In the example we will resize the video as 640x480
.
视频文件可以调整大小。 降低分辨率将减小视频文件的大小。 我们将-s
与新的x
和y
大小一起使用。 在示例中,我们将视频大小调整为640x480
。
$ ffmpeg -i Funny.mkv -s 640x480 -c:a copy Funny_resize.mkv
![Resize Video Resolution](https://i-blog.csdnimg.cn/blog_migrate/afb02a039c1aaf3556e2444fb3452079.png)
使用FFmpeg将海报图像添加到音频文件(Add Poster Image To Audio File with FFmpeg)
As audio files provides only sound the singers albums need some poster to show while playing the song. This poster image can be embedded into audio file as metadata like below.
由于音频文件仅提供声音,因此歌手专辑在播放歌曲时需要一些海报以显示。 该海报图像可以作为元数据嵌入到音频文件中,如下所示。
$ ffmpeg -i Funny.mkv -i smiley.jpg Funny_poster.mkv
![Add Poster Image To Audio File](https://i-blog.csdnimg.cn/blog_migrate/98a4741761e8eec566a8a488b3d636cf.png)
通过使用FFmpeg指定开始和结束时间来剪切视频(Cut Video By Specifying Start and End Time with FFmpeg)
We can cut video from specified time as specified time range. Original file will be kept without changing. We will specify the start time with -ss
option and duration with -t
option. In this example we will cut video from 20 seconds to 35 seconds.
我们可以在指定的时间范围内从指定的时间剪切视频。 原始文件将保留不变。 我们将使用-ss
选项指定开始时间,并使用-t
选项指定持续时间。 在此示例中,我们将视频从20秒剪切到35秒。
$ ffmpeg -i Funny.mkv -ss 00:00:20 -codec copy -t 15 Funny_cut.mkv
![Cut Video](https://i-blog.csdnimg.cn/blog_migrate/3b7c8815da99f57eda158c04cb829456.png)
使用FFmpeg合并视频文件(Merge Video Files with FFmpeg)
Multiple video files can be concatenated into single video file. We will provide the video file list as a text file with -f concat
and -c copy
options. The video files are listed like below named videos.txt
多个视频文件可以串联为单个视频文件。 我们将以文本文件形式提供视频文件列表,并带有-f concat
和-c copy
选项。 视频文件如下所列,命名为videos.txt
videos.txt (videos.txt)
part1.mkv
part2.mkv
Now we will join togather.
现在我们将加入聚会。
$ ffmpeg -f concat -i videos.txt -c copy Funny_join.mkv
裁剪音频文件 (Crop Audio File)
We have previously cut the video file. There is also an option to cut audio files. We will use the same options with video file but the output will be an audio file. In this example, we crop audio_crop.mp3
.
我们之前已经剪切了视频文件。 还有一个剪切音频文件的选项。 我们将对视频文件使用相同的选项,但输出将为音频文件。 在此示例中,我们裁剪audio_crop.mp3
。
$ ffmpeg -i Funny.mkv -ss 00:00:20 -t 15 Funny_cut.mp3
![Crop Audio File](https://i-blog.csdnimg.cn/blog_migrate/56b0b929ad8d77efeebc06c5601ffbd8.png)
使用FFmpeg设置音频的比特率(Set Bitrate Of Audio with FFmpeg)
Bitrate of a video effects the quality of the audio more bitrate means more quality but also more audio size. We can change the audio file bitrate -ab
option. In the example we will change bitrate to 128k
视频的比特率影响音频的质量,比特率越高,意味着质量越好,但音频大小也越大。 我们可以更改音频文件的bitrate -ab
选项。 在示例中,我们将比特率更改为128k
$ ffmpeg -i Funny.mp3 -ab 128k Funny_128k.mp3
![Set Bitrate Of Audio](https://i-blog.csdnimg.cn/blog_migrate/418258c8a9a79422cbddb20b5203ef9f.png)
使用FFmpeg设置视频帧率(Set Framerate Of Video with FFmpeg)
The framerate specifies the count of pictures in one second. High framerate means more fluid movies but costs more CPU and disk. We can change framerate with -r
option. In the example, we will set framerate 15
帧速率指定一秒钟内的图片计数。 高帧率意味着更流畅的电影,但会花费更多的CPU和磁盘。 我们可以使用-r
选项更改帧速率。 在示例中,我们将帧速率设置为15
$ ffmpeg -i Funny.mkv -r 15 Funny.mp4
![Set Framerate Of Video](https://i-blog.csdnimg.cn/blog_migrate/4f70ee1bbda7bb5d77e01c038f3d6e06.png)
使用FFmpeg设置视频的比特率(Set Bitrate Of Video with FFmpeg)
Bitrate of video provides color density about the frames. More bitrate means more detailed colors but more in size. We can set video bitrate with ffmpeg by using -b
option. In the example we will change bitrate to 100k
which means 100.000
bits
视频的比特率提供有关帧的颜色密度。 更高的比特率意味着更详细的颜色,但尺寸更大。 我们可以使用-b
选项通过ffmpeg设置视频比特率。 在示例中,我们将比特率更改为100k
,这表示100.000
位
$ ffmpeg -i Funny.mkv -b 100k Funny.mp4
![Set Bitrate Of Audio](https://i-blog.csdnimg.cn/blog_migrate/aa4c251be29118530a5d588c2915e7b3.png)
使用FFmpeg从视频中提取图像(Extract Images From Video with FFmpeg)
As you know movie rippers generally provide some picture thumbnail about movies and video files. This picture thumbnail can be created with FFmpeg. We will use -r
option to specify rate and -f
option for the format. In the example, we will create a thumbnail with rate 1
.
如您所知,电影开膛手通常会提供一些有关电影和视频文件的图片缩略图。 可以使用FFmpeg创建此图片缩略图。 我们将使用-r
选项指定速率,并使用-f
选项指定格式。 在示例中,我们将创建一个比率为1
的缩略图。
$ ffmpeg -i Funny.mkv -r 1 -f image image-%3d.jpeg
![Extract Images From Video](https://i-blog.csdnimg.cn/blog_migrate/88119e8c351ecc24e507201bc78a52e7.png)
翻译自: https://www.poftut.com/ffmpeg-command-tutorial-examples-video-audio/
ffmpeg命令教程