ffmpeg命令行工具

对于ffmpeg命令行的使用  之前一直都是通过百度(惭愧),一边找 一边用   感觉写起来比较麻烦 就在这记录下  方便以后温习

我们都知道从官网下来的可以直接运行的程序有三个  一个是ffmpeg.exe  ffplay.exe   ffprobe.exe

关于ffmpeg的官网里边  一般是提供三种(static  shared  dev)  

第一个static是提供了之前说的那三个程序   并且人家把各个dll集成了进去  导致程序的大小比较大

第二个shared  也提供了那三个程序  只不过大小就小得多  因为它还提供了各种dll

第三个就完全适用于开发人员  提供了lib以及头文件

 

这边我们就直接来说说提供的那三个程序怎么用(直接点是没用的哈   直接在命令行里边用就好)

ffmpeg是用来转码的工具  ffplay是用来播放的  ffprobe是用来查看文件格式的

 

**************************************************************************************************************************************

首先我们来看下ffmpeg

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

我自己输入  ffmpeg -h

首先会显示ffmpeg的版本  以及编译这个用的GCC的版本  以及编译之前configure的选项   之后就是依赖各种库的版本

基本的信息显示完了以后  就会告诉你怎么使用

usage: ffmpeg [options]  [[infile options] -i infile]... {[outfile options] outfile}...

当然我们也可以活用help信息

Getting help:

    -h      -- print basic options    会打印基本的选项

    -h long -- print more options  会打印更多的选项

    -h full -- print all options (including all format and codec specific options, very long)  打印所有的选项(包括所有格式和编解码器特定选项,很长)

    -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter  可以打印指定的选项

    See man ffmpeg for detailed description of the options.   当然了你要想看得仔细  有关选项的详细描述,请参阅man ffmpeg。

 

下面我们就来看看各个选项(之后再来一个个试)

Print help / information / capabilities:

-L                  show license  

-h topic            show help

-? topic            show help

-help topic         show help

--help topic        show help

-version            show version

-buildconf          show build configuration

-formats            show available formats                                            显示所支持的格式

-muxers             show available muxers                                            显示所有可用的封装格式

-demuxers           show available demuxers                                      显示所有可用的解封装格式

-devices            show available devices                                             显示支持的设备(这里显示的只是很大的范围  并不会显示具体的设备  比如我输入ffmpeg -devices   只会像是下面输出的那样)

                       Devices:

                       D. = Demuxing supported  可以理解为输入设备(我们可以这么理解  解封装是获取流  这个设备其实干的也是获取流的事)

                       .E = Muxing supported    可以理解为输出设备(同理  输出设备是使用流的  和封装类似)

                        --

                        E caca            caca (color ASCII art) output device

                       D  dshow           DirectShow capture

                        D  lavfi           Libavfilter virtual input device

                         E sdl,sdl2        SDL2 output device

                        D  vfwcap          VfW video capture

-codecs             show available codecs                                             显示支持的编解码器(看清楚   是编解码器)

                        需要注意的就是前面的那些什么    D,E,V,A,S,I,L,S的一类的意思

                                   D..... = Decoding supported   解码

                                   .E.... = Encoding supported     编码

                                    ..V... = Video codec                 视频

                                   ..A... = Audio codec                 音频

                                   ..S... = Subtitle codec               字幕

                                  ...I.. = Intra frame-only codec  帧内编解码器

                                  ....L. = Lossy compression        有损

                                  .....S = Lossless compression    无损

-decoders           show available decoders                                        显示支持的解码器

-encoders           show available encoders                                        显示支持的编码器

-bsfs               show available bit stream filters                                 显示可用的比特流过滤器

-protocols          show available protocols                                        显示支持的协议

-filters            show available filters                                                   显示可用的过滤器(需要注意下下面的几个的意思   现在我还是没有搞懂什么意思   要去找找代码看看了)

                        Filters:

                           T.. = Timeline support

                           .S. = Slice threading

                           ..C = Command support

                          A = Audio input/output

                         V = Video input/output

                         N = Dynamic number and/or type of input/output

                         | = Source or sink filter

-pix_fmts           show available pixel formats                                    显示可用像素格式

                       Pixel formats:

                        I.... = Supported Input  format for conversion        支持转换的输入格式

                       .O... = Supported Output format for conversion    支持的转换输出格式

                        ..H.. = Hardware accelerated format                       硬件加速格式

                          ...P. = Paletted format                                              调色格式

                         ....B = Bitstream format                                            位流格式

                        下面这个是输出的格式

        FLAGS NAME  (标志名称)NB_COMPONENTS (组成数量  yuv420  就是有三个组成的)        BITS_PER_PIXEL(每个像素占得位数)

-layouts            show standard channel layouts                                显示标准通道布局  

-sample_fmts        show available audio sample formats                    显示可用的音频示例格式

-colors             show available color names                                         显示可用颜色名称

-sources device     list sources of the input device                              列出输入设备的源(这个  还不清楚怎么用   到时看看官方文档)

-sinks device       list sinks of the output device                                  列出输出设备的接收器

-hwaccels           show available HW acceleration methods                显示可用的硬件加速方法

 

Global options (affect whole program instead of just one file:       全局选项-----影响整个程序,而不仅仅是一个文件:

-loglevel loglevel  set logging level          设定log等级    "quiet" "panic" "fatal" "error" "warning" "info" "verbose" "debug" "trace"

            补充说明: Flags can also be used alone by adding a ’+’/’-’ prefix to set/reset a single flag without affecting other flags or changing loglevel. When setting both flags and loglevel, a ’+’ separator is expected between the last flags value and before loglevel.

                   意思就是----还可以单独使用标志,添加‘+’/‘-’前缀来设置/重置单个标志,而不影响其他标志或更改日志级别。当同时设置标志和日志级别时,需要在最后一个标志值之间和日志级别之前使用。   

                 eg:ffmpeg -loglevel repeat+level+verbose -i input output

-v loglevel         set logging level                                                                                                   和上面一样的

-report             generate a report                                                                                                   生成报表

-max_alloc bytes    set maximum size of a single allocated block                                                 设置单个分配块的最大大小

-y                  overwrite output files                                                                                                覆盖输出文件

-n                  never overwrite output files                                                                                     永远不要覆盖输出文件

-ignore_unknown     Ignore unknown stream types                                                                      忽略未知流类型

-filter_threads     number of non-complex filter threads                                                                非复杂过滤线程数 (后边要加数字)

-filter_complex_threads  number of threads for -filter_complex                                                    过滤器复合体的线程数 (后边要加数字)

-stats              print progress report during encoding                                                                    在编码期间打印进度报告

-max_error_rate ratio of errors (0.0: no errors, 1.0: 100% error  maximum error rate                    错误率(0:无错误,1:100%错误最大错误率)

-bits_per_raw_sample number  set the number of bits per raw sample                                        设置每个原始样本的位数

-vol volume         change audio volume (256=normal)                                                                   改变音频音量(256=正常)

 

Per-file main options:    每个文件的主要选项

-f fmt              force format                                                                强迫使用格式‘fmt’

-c codec            codec name

-codec codec        codec name

-pre preset         preset name          预先设定名称                                         

-map_metadata outfile[,metadata]:infile[,metadata]  set metadata information of outfile from infile         依据输入文件设置输出文件的元数据信息

-t duration         record or transcode "duration" seconds of audio/video        编码或转码音频/视频的“ duration”秒

-to time_stop       record or transcode stop time                 记录或转码停止时间

-fs limit_size      set the limit file size in bytes               设置限制文件大小(以字节为单位)

-ss time_off        set the start time offset                设置起始时间偏移量

-sseof time_off     set the start time offset relative to EOF                    设置相对于eof的起始时间偏移量。

-seek_timestamp     enable/disable seeking by timestamp with -ss                  使用-ss启用/禁用时间戳查找

-timestamp time     set the recording timestamp ('now' to set the current time)                   设置录制时间戳(“立即”设置当前时间)

-metadata string=string  add metadata                        添加元数据

-program title=string:st=number...  add program with specified streams               添加具有指定流的程序

-target type        specify target file type ("vcd", "svcd", "dvd", "dv" or "dv50" with optional prefixes "pal-", "ntsc-" or "film-")                             指定目标文件类型( "vcd", "svcd", "dvd", "dv" or "dv50",可选前缀为 "pal-", "ntsc-" or "film-")

-apad               audio pad                  音频垫

-frames number      set the number of frames to output                将帧数设置为输出

-filter filter_graph  set stream filtergraph                   设置流滤波器

-filter_script filename  read stream filtergraph description from a file         从文件中读取流过滤图描述

-reinit_filter      reinit filtergraph on input parameter changes              输入参数变化的 reinit滤波图

-discard            discard                         丢弃

-disposition        disposition                              配置

 

Video options:   视频选项

-vframes number     set the number of video frames to output                         设置输出视频的帧数

-r rate             set frame rate (Hz value, fraction or abbreviation)                      设置帧速率(Hz值、分数或缩写)

-s size             set frame size (WxH or abbreviation)                                           设置帧大小(WXH或缩写——Sqcif 128X96 qcif 176X144 cif 252X288 4cif 704X576)

-aspect aspect      set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)                          设定高宽比(4:3,16:9或1.3333,1.7777)

-bits_per_raw_sample number  set the number of bits per raw sample             设置每个原始样本的位数。

-vn                 disable video                                                                                  禁用视频

-vcodec codec       force video codec ('copy' to copy stream)                            强制视频编解码器(“复制流)

-timecode hh:mm:ss[:;.]ff  set initial TimeCode value.                                         设置初始时间码值

-pass n             select the pass number (1 to 3)                                                   选择通行证号码(1到3)

-vf filter_graph    set video filters                                                                         设置视频滤波器

-ab bitrate         audio bitrate (please use -b:a)                                                   音频比特率(请使用-b:a)

-b bitrate          video bitrate (please use -b:v)                                                    视频比特率(请使用-b:v)

-dn                 disable data                                                                                   禁用数据

 

Audio options:   音频选项    

-aframes number     set the number of audio frames to output                         设置输出音频流的帧数

-aq quality         set audio quality (codec-specific)                                              设置音频质量(特定编解码器)

-ar rate            set audio sampling rate (in Hz)                                                    设置音频采样率(以赫兹为单位)

-ac channels        set number of audio channels                                                 设置音频通道数

-an                 disable audio                                                                                  禁用音频

-acodec codec       force audio codec ('copy' to copy stream)                            强制音频编解码器(“复制流)

-vol volume         change audio volume (256=normal)                                       改变音频音量(256=正常)

-af filter_graph    set audio filters                                                                        设置音频过滤器

 

Subtitle options:   字幕选项

-s size             set frame size (WxH or abbreviation)                                           设置帧大小(WxH或省略)

-sn                 disable subtitle                                                                               禁用字幕

-scodec codec       force subtitle codec ('copy' to copy stream)                         强制字幕编解码器(“复制流)

-stag fourcc/tag    force subtitle tag/fourcc                                                        强制字幕标签/fourcc码

-fix_sub_duration   fix subtitles duration                                                             修正字幕持续时间

-canvas_size size   set canvas size (WxH or abbreviation)                                   设置画布大小(WXH或缩写)

-spre preset        set the subtitle options to the indicated preset                       将字幕选项设置为指定的预置

 

好了   我们就开始用实例进行巩固

ffmpeg -i cyq.avi  out.avi  

这个是最简单的转码命令   转码的内部参数都是取的默认值

我们来看下相关的参数

后来才意识到之前为什么会写错  现在  我们再来重温一遍ffmpeg的书写格式

ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...

ffmpeg  +  全局的选项(可省略)+{输入文件选项  -i 文件} +{输出文件选项  文件}

 

 

 

 

**************************************************************************************************************************************

 

ffplay  是用SDL来写的一个播放器 

(官方的解释:ffplay是一个非常简单和可移植的媒体播放器,使用ffmpeg库和SDL库。它主要用作各种ffmpeg API的测试床。)

他的功能可谓是很强大  但是就是没有图形化的操作界面  只能通过键盘来操作

这边就分  快捷键以及选项来进行说明

http://ffmpeg.org/ffplay.html   官网的使用说明

我们先来看下ffplay -h

因为显示的东西太多  我这边就来挑选着记录

前边显示的和ffmpeg的差不多

我们先看下他的用法:ffplay [options] input_file

接下来看下主选项:

Main options:

-L                  show license

-h topic            show help

-? topic            show help

-help topic         show help

--help topic        show help

-version            show version

-buildconf          show build configuration

-formats            show available formats

-muxers             show available muxers

-demuxers           show available demuxers

-devices            show available devices

-codecs             show available codecs

-decoders           show available decoders

-encoders           show available encoders

-bsfs               show available bit stream filters

-protocols          show available protocols

-filters            show available filters

-pix_fmts           show available pixel formats

-layouts            show standard channel layouts

-sample_fmts        show available audio sample formats

-colors             show available color names

-loglevel loglevel  set logging level

-v loglevel         set logging level

-report             generate a report

-max_alloc bytes    set maximum size of a single allocated block

-sources device     list sources of the input device  显示输入设备的自动检测源。

-sinks device       list sinks of the output device   显示输出设备的自动检测接收器。

-x width            force displayed width

-y height           force displayed height

-s size             set frame size (WxH or abbreviation)

-fs                 force full screen      强制全屏(和ffmpeg中的fs是不一样的用法)

-an                 disable audio

-vn                 disable video

-sn                 disable subtitling

-ss pos             seek to a given position in seconds     以秒为单位寻找给定位置

-t duration         play  "duration" seconds of audio/video    播放音频/视频的“ duration”秒

-bytes val          seek by bytes 0=off 1=on -1=auto      按字节查找  0=OFF   1=ON     -1=AUTO

-nodisp             disable graphical display    禁用图形显示

-noborder           borderless window     无边界窗口

-volume volume      set startup volume 0=min 100=max   设置启动 volume0=min 100=max

-f fmt              force format

-window_title window title  set window title  窗口标题集窗口标题

-af filter_graph    set audio filters   设置音频过滤器

-showmode mode      select show mode (0 = video, 1 = waves, 2 = RDFT)  选择显示模式(0=视频,1=波形,2=RDFT)

-i input_file       read specified file  读取指定文件

-codec decoder_name  force decoder

-autorotate         automatically rotate video  自动旋转视频

 

下面是几个高级选项:

Advanced options:

-cpuflags flags     force specific cpu flags   强制特定CPU标志

-hide_banner hide_banner  do not show program banner  不要显示程序横幅

-ast stream_specifier  select desired audio stream   选择所需的音频流

-vst stream_specifier  select desired video stream   选择所需视频流

-sst stream_specifier  select desired subtitle stream   选择想要的字幕流

-pix_fmt format     set pixel format   设置像素格式

-stats              show status  显示当前状态

-fast               non spec compliant optimizations   不符合规范的优化

-genpts             generate pts   生成PTS

-drp                let decoder reorder pts 0=off 1=on -1=auto   让解码器重新排序0=OFF 1=ON   -1=AUTO

-lowres

-sync type          set audio-video sync. type (type=audio/video/ext)  设置音视频同步类型(type=音频/视频/ext)

-autoexit           exit at the end   最后退出

-exitonkeydown      exit on key down  按下键退出

-exitonmousedown    exit on mouse down   鼠标向下退出

-loop loop count    set number of times the playback shall be looped      设置回放的次数

-framedrop          drop frames when cpu is too slow         CPU太慢时丢弃帧

-infbuf             don't limit the input buffer size (useful with realtime streams)   不要限制输入缓冲区的大小(对实时流有用)

-vf filter_graph    set video filters   设置视频滤波器

-rdftspeed msecs    rdft speed   rdft速度

-default            generic catch all option  捕获通用所有选项

-acodec decoder_name  force audio decoder

-scodec decoder_name  force subtitle decoder

-vcodec decoder_name  force video decoder

 

接下来就是快捷键了(其实就是在已经在播放的时候  有什么功能)

While playing:

q, ESC              quit      退出

f                   toggle full screen     全屏

p, SPC              pause    暂停

m                   toggle mute   切换静音

9, 0                decrease and increase volume respectively            减少量和增加量

/, *                decrease and increase volume respectively            减少量和增加量

a                   cycle audio channel in the current program           循环当前程序中的音频通道

v                   cycle video channel         循环视频信道

t                   cycle subtitle channel in the current program       循环当前程序中的字幕通道

c                   cycle program  循环程序

w                   cycle video filters or show modes       循环视频过滤器或显示模式

s                   activate frame-step mode      激活帧步模式(逐帧显示)

left/right          seek backward/forward 10 seconds    先后/向前10S

down/up             seek backward/forward 1 minute     先后/向前1minute

page down/page up   seek backward/forward 10 minutes     先后/向前10minute

right mouse click   seek to percentage in file corresponding to fraction of width   在文件中寻求与宽度分数相对应的百分比

left double-click(双击)   toggle full screen    切换全屏

 

 

**************************************************************************************************************************************

 

ffprobe

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

ffprobe -h   显示的太多  我这边就不全贴上来了  就把主选项写一下

开始  和之前的ffmpeg显示的是一样的

 

我们来看下用法: ffprobe [OPTIONS] [INPUT_FILE]

下面的就是主选项:

Main options:

-L                  show license

-h topic            show help

-? topic            show help

-help topic         show help

--help topic        show help

-version            show version

-buildconf          show build configuration

-formats            show available formats

-muxers             show available muxers

-demuxers           show available demuxers

-devices            show available devices

-codecs             show available codecs

-decoders           show available decoders

-encoders           show available encoders

-bsfs               show available bit stream filters

-protocols          show available protocols

-filters            show available filters

-pix_fmts           show available pixel formats

-layouts            show standard channel layouts

-sample_fmts        show available audio sample formats

-colors             show available color names

-loglevel loglevel  set logging level

-v loglevel         set logging level

-report             generate a report

-max_alloc bytes    set maximum size of a single allocated block

-cpuflags flags     force specific cpu flags                                                        强制特定CPU标志

-hide_banner hide_banner  do not show program banner                             不要显示程序横幅

-sources device     list sources of the input device

-sinks device       list sinks of the output device

-f format           force format

-unit               show unit of the displayed values                                              显示所显示值的单位

-prefix             use SI prefixes for the displayed values                                     对显示的值使用si前缀

-byte_binary_prefix  use binary prefixes for byte units                                    字节单位使用二进制前缀

-sexagesimal        use sexagesimal format HOURS:MM:SS.MICROSECONDS for time units    使用六十进制格式小时:毫米:单位时间的微秒

-pretty             prettify the format of displayed values, make it more human readable      美化显示值的格式,使其更具可读性。

-print_format format  set the output printing format (available formats are: default, compact, csv, flat, ini, json, xml)    设置输出打印格式(可用格式有:默认格式、紧凑格式、csv格式、平面格式、ini格式、json格式、xml格式)

-of format          alias for -print_format      别名-打印格式

-select_streams stream_specifier  select the specified streams   选择指定的流

-sections           print sections structure and section information, and exit   打印区段结构和区段信息,并退出

-show_data          show packets data  显示数据包数据

-show_data_hash     show packets data hash   显示数据包数据散列

-show_error         show probing error  显示探测误差

-show_format        show format/container info  显示格式/容器信息

-show_frames        show frames info  显示帧信息

-show_format_entry entry  show a particular entry from the format/container info    显示格式/容器信息中的特定条目

-show_entries entry_list  show a set of specified entries   显示一组指定的条目

-show_log           show log

-show_packets       show packets info   显示数据包信息

-show_programs      show programs info   显示程序信息

-show_streams       show streams info   显示流信息

-show_chapters      show chapters info   展示章节信息

-count_frames       count the number of frames per stream     计算每个流的帧数。

-count_packets      count the number of packets per stream     计算每个流的数据包数。

-show_program_version  show ffprobe version   显示 ffprobe版本

-show_library_versions  show library versions     显示库版本

-show_versions      show program and library versions    显示程序和库版本

-show_pixel_formats  show pixel format descriptions      显示像素格式描述

-show_private_data  show private data           显示私有数据

-private            same as show_private_data   类似 show_private_data

-bitexact           force bitexact output    强制位数输出

-read_intervals read_intervals  set read intervals   设定读间隔

-default            generic catch all option       通用捕获所有选项

-i input_file       read specified file       读取指定文件

 

 

 

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值