ffmpeg命令教程_FFmpeg命令教程

ffmpeg命令教程

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
Display Video Information
显示视频信息

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
Display Audio Information
显示音频信息

There are following information about the audio file.

以下是有关音频文件的信息。

  • genre describes the musical type of mp3 as metadata

    genre将mp3的音乐类型描述为元数据

  • Duration describes the length of the video file in hour:minute:second format

    Duration长以小时:分钟:秒格式描述视频文件的长度

  • Stream show audio information like format type, quality of the stream

    Stream显示音频信息,例如格式类型,流质量

将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
Convert Mkv To Mp4
将Mkv转换为Mp4

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 count

    frame显示当前正在处理帧数

  • fps show the count of frames processed in one second

    fps显示在一秒钟内处理的帧数

  • Lsize shows the destination or new file size

    Lsize显示目标或新文件的大小

  • time shows current position of the convert process in the video length in time

    time显示转换过程在视频时长中的当前位置

  • bitrate shows the bit size of a second length of the video

    bitrate显示视频的第二长度的比特大小

LEARN MORE  What Is VGA (Video Graphics Array)?
了解更多什么是VGA(视频图形阵列)?

将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
Convert Flash and Flv To Mp4
将Flash和Flv转换为Mp4

使用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
Convert Mp4 To Avi
转换MP4到AVI

使用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
Convert Mp4 To Gif
转换MP4到GIF

使用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.

我们可以从视频文件中提取音频流,并将音频保存为单独的文件,例如aacmp3vorbis等格式。我们将提供-vn -ab 128选项。 -ab 128指定比特率。 音频提取将花费很少的时间。

$ ffmpeg -i Funny.mkv -vn -ab 128 Funny.mp3
Extract Audio From Video File
Extract Audio From Video File
从视频文件中提取音频

使用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
Mute Audio
静音

使用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与新的xy大小一起使用。 在示例中,我们将视频大小调整为640x480

$ ffmpeg -i Funny.mkv -s 640x480 -c:a copy  Funny_resize.mkv
Resize Video Resolution
Resize Video Resolution
调整视频分辨率

使用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
Add Poster Image To Audio File
将海报图像添加到音频文件

通过使用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
Cut Video
剪辑视频

使用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
Crop Audio File
裁剪音频文件

使用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
Set Bitrate Of Audio
设置音频的比特率

使用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
Set Framerate Of Video
设置视频帧率

使用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
Set Bitrate Of Audio
设置音频的比特率

使用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
Extract Images From Video
从视频中提取图像

翻译自: https://www.poftut.com/ffmpeg-command-tutorial-examples-video-audio/

ffmpeg命令教程

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值