ffmpeg选项详解(ffmpeg常用命令)

ffmpeg是什么?,我来为大家讲解一下关于ffmpeg选项详解?跟着小编一起来看一看吧!

ffmpeg选项详解(ffmpeg常用命令)

ffmpeg选项详解

本文为整理,转载请标明原文链接、原作者、参考文章链接、参考文章作者。

一、ffmpeg简介


ffmpeg是什么?

A complete, cross-platform solution to record, convert and STREAM audio and video.


ffmpeg官网

官方网址:http://ffmpeg.org/about.html

ffmpeg 主要由三个命令构成分别是、ffmpeg、ffplay、ffprobe


ffmpeg

官方说明网址:http://ffmpeg.org/ffmpeg.html

ffmpeg is a very fast video and audio converter that can also grab from a live audio/video source. It can also convert between arbitrary sample rates and resize video on the fly with a high quality polyphase filter.

ffmpeg reads from an arbitrary number of input "files" (which can be regular files, Pipes, network streams, grabbing devices, etc.), specified by the -i option, and writes to an arbitrary number of output "files", which are specified by a plain output url. Anything found on the command line which cannot be interpreted as an option is considered to be an output url.

Each input or output url can, in principle, contain any number of streams of different types (video/audio/subtitle/attachment/data). The allowed number and/or types of streams may be limited by the container FORMAT. Selecting which streams from which inputs will go into which output is either done automatically or with the -map option (see the Stream selection chapter).

To refer to input files in options, you must use their indices (0-based). E.g. the first input file is 0, the second is 1, etc. Similarly, streams within a file are referred to by their indices. E.g. 2:3 refers to the fourth stream in the third input file. Also see the Stream specifiers chapter.

As a general rule, options are applied to the next specified file. Therefore, order is important, and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file. Exceptions from this rule are the global options (e.g. verbosity level), which should be specified first.

Do not mix input and output files – first specify all input files, then all output files. Also do not mix options which belong to different files. All options apply ONLY to the next input or output file and are reset between files.

To set the video bitrate of the output file to 64 kbit/s:

ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi

To force the frame rate of the output file to 24 fps:

ffmpeg -i input.avi -r 24 output.avi

To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24 fps:

ffmpeg -r 1 -i input.m2v -r 24 output.avi

The format option may be needed for raw input files.


ffplay

介绍说明网址:http://ffmpeg.org/ffplay.html

FFplay is a very simple and portable media player using the FFmpeg libraries and the SDL library. It is mostly used as a testbed for the various FFmpeg APIs.


ffprobe

官方说明网址:http://ffmpeg.org/ffprobe.html

ffprobe gathers information from multimedia streams and prints it in human- and machine-readable fashion.

For example it can be used to check the format of the container used by a multimedia stream and the format and type of each media stream contained in it.

If a url is specified in input, ffprobe will try to open and probe the url content. If the url cannot be opened or recognized as a multimedia file, a positive exit code is returned.

ffprobe may be employed both as a standalone application or in combination with a textual filter, which may perform more sophisticated processing, e.g. statistical processing or plotting.

Options are used to list some of the formats supported by ffprobe or for specifying which information to display, and for setting how ffprobe will show it.

ffprobe output is designed to be easily parsable by a textual filter, and consists of one or more sections of a form defined by the selected writer, which is specified by the print_format option.

Sections may contain other nested sections, and are identified by a name (which may be shared by other sections), and an unique name. See the output of sections.

Metadata tags stored in the container or in the streams are recognized and printed in the corresponding "FORMAT", "STREAM" or "PROGRAM_STREAM" section.


二、ffmpeg安装

ffmpeg可以自己编译,也可以下载官方编译好的版本。如果没有特殊的需求,建议直接使用官方的版本即可。


ffmpeg下载地址

下载地址:

http://ffmpeg.org/download.html

这里选择自己的系统地址下载,支持linux、windows、macOS.


三、ffmpeg 使用实例

记录一些个人使用过的ffmpeg实例。

1. 分割音频或者视频

ffmpeg -ss 00:00:00 -t 00:00:30 -i test.mp4 -vcodec copy -acodec copy output.mp4

选项释义: -ss 指定从视频的哪个时间点开始截取。时间格式是时分秒。
-t 指定截取多长时间的视频。时间格式为时分秒。
-i 指定要截取的文件。
-vocodec copy 拷贝视频格式,-vocodec是选用的视频库,copy是指原样拷贝视频格式。
-acodec copy 拷贝音频格式,-acodec是选用的音频库,copy是指原样拷贝音频格式。
output.mp4输出的视频格式

2. 合并音频或视频

ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

命令会把filelist.txt中的视频按照文件的顺序合并成一个视频。

-f 强制指定格式
-c 复制视频格式
output.mp4 输出的视频名字。
filelist.txt文件内容格式:

file 'D:\voide\1.mp4' file 'D:\voide\2.mp4'

3. 抽取音频

ffmpeg -i 3.mp4 -vn -y -acodec copy 3.aac

4. 抽取视频

ffmpeg -i Life.of.Pi.has.subtitles.mkv -vcodec copy –an videoNoAudioSubtitle.mp4

5. 合成音频和视频

ffmpeg -i video2.avi -i audio.mp3 -vcodec copy -acodec copy output.avi

6.查看音视频文件信息

ffmpeg -i output.avi

四、参考文章

ffmpeg视频抽取音频,视音频分离

https://blog.csdn.net/fakine/article/details/79204501

作者: fakine


使用ffmpeg何兵多个视频文件

https://blog.csdn.net/winniezhang/article/details/89260841

作者: winfredzhang


FFMPEG视频分割和合并

https://www.jianshu.com/p/cf1e61eb6fc8

作者: 松撻

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页