1. ffmpeg 是什么?

ffmpeg(命令行工具) 是一个快速的音视频转换工具。

2. ffmpeg 的使用方式

命令行: ffmpeg [全局选项] {[输入文件选项] -i ‘输入文件’} ... {[输出文件选项] ‘输出文件’} ...

3. ffmpeg 可使用的选项

3.1 通用选项

ff* 工具的通用选项是共享的。(FFplayFFprobe)

‘-L’	显示 license
‘-h, -?, -help, --help [arg]’ 打印帮助信息;可以指定一个参数 arg ,如果不指定,只打印基本选项
可选的 arg 选项:
‘long’ 除基本选项外,还将打印高级选项
‘full’ 打印一个完整的选项列表,包含 encoders, decoders, demuxers, muxers, filters 等的共享以及私有选项
‘decoder=decoder_name’ 打印名称为 “decoder_name” 的解码器的详细信息
‘encoder=encoder_name’ 打印名称为 “encoder_name” 的编码器的详细信息
‘demuxer=demuxer_name’ 打印名称为 “demuxer_name” 的 demuxer 的详细信息
‘muxer=muxer_name’ 打印名称为 “muxer_name” 的 muxer 的详细信息
‘filter=filter_name’ 打印名称为 “filter_name” 的过滤器的详细信息 ‘-version’ 显示版本信息
‘-formats’ 显示有效的格式
‘-codecs’ 显示 libavcodec 已知的所有编解码器
‘-decoders’ 显示有效的解码器
‘-encoders’ 显示有效的编码器
‘-bsfs’ 显示有效的比特流过滤器
‘-protocols’ 显示有效的协议
‘-filters’ 显示 libavfilter 有效的过滤器
‘-pix_fmts’ 显示有效的像素格式
‘-sample_fmts’ 显示有效的采样格式
‘-layouts’ 显示通道名称以及标准通道布局
‘-colors’ 显示认可的颜色名称
‘-hide_banner’ 禁止打印欢迎语;也就是禁止默认会显示的版权信息、编译选项以及库版本信息等
3.2 一些主要选项
‘-f fmt (input/output)’
强制输入或输出文件格式。通常,输入文件的格式是自动检测的,
输出文件的格式是通过文件扩展名来进行猜测的,所有该选项大
多数时候不需要。
‘-i filename (input)’
输入文件名
‘-y (global)’
覆盖输出文件而不询问
‘-n (global)’
不覆盖输出文件,如果一个给定的输出文件已经存在,则立即
退出
‘-c[:stream_specifier] codec (input/output,per-stream)’
‘-codec[:stream_specifier] codec (input/output,per-stream)’
为一个或多个流选择一个编码器(当使用在一个输出文件之前时)
或者一个解码器(当使用在一个输入文件之前时)。codec 是一个
编码器/解码器名称或者一个特定值“copy”(只适用输出)。
‘-t duration (output)’
当到达 duration 时,停止写输出。
duration 可以是一个数字(秒),或者使用hh:mm:ss[.xxx]形式。
-to 和 -t 是互斥的,-t 优先级更高。
‘-to position (output)’
在 position 处停止写输出。
duration 可以是一个数字(秒),或者使用hh:mm:ss[.xxx]形式。
-to 和 -t 是互斥的,-t 优先级更高。
‘-fs limit_size (output)’
设置文件大小限制,以字节表示
‘-ss position (input/output)’
当作为输入选项时(在 -i 之前),在输入文件中跳转到 position。
需要注意的是,在大多数格式中,不太可能精确的跳转,因此,
ffmpeg 将跳转到 position 之前最接近的位置。当进行转码
并且 ‘-accurate_seek’ 打开时(默认),位于跳转点和 position
之间的额外部分将被解码并且丢弃。当做流拷贝或者当使用
‘-noaccurate_seek’时,它将被保留下来。
当作为输出选项时(在输出文件名前),解码但是丢弃输入,直到
时间戳到达 position。
position 可以是秒或者 hh:mm:ss[.xxx] 形式
‘-itsoffset offset (input)’
设置输入时间偏移。 offset 将被添加到输入文件的时间戳。指定
一个正偏移,意味着相应的流将被延时指定时间。
‘-timestamp date (output)’
在容器中设置录音时间戳
‘-metadata[:metadata_specifier] key=value (output,per-metadata)’
设置metadata key/value对
‘-target type (output)’
指定目标文件类型(vcd, svcd, dvd, dv, dv50)。
type 可以带有 pal-, ntsc- 或 film- 前缀,以使用相应的标准。
所有的格式选项(bitrate, codecs, buffer sizes)将自动设定。
‘-dframes number (output)’
设置要录制数据帧的个数。这是 -frames:d 的别名
‘-frames[:stream_specifier] framecount (output,per-stream)’
framecount 帧以后,停止写流。
‘-q[:stream_specifier] q (output,per-stream)’
‘-qscale[:stream_specifier] q (output,per-stream)’
使用固定质量范围(VBR)。
‘-filter[:stream_specifier] filtergraph (output,per-stream)’
创建filtergraph 指定的过滤图,并使用它来过滤流。
‘-filter_script[:stream_specifier] filename (output,per-stream)’
该选项与‘-filter’相似,唯一的不同是,它的参数是一个存放
过滤图的文件的名称。
‘-pre[:stream_specifier] preset_name (output,per-stream)’
指定匹配流的预设
‘-stats (global)’
打印编码进程/统计信息。默认打开,可以使用 -nostats 禁用。
‘-stdin’
开启标准输入交互。默认打开,除非标准输入作为一个输入。
可以使用 -nostdin 禁止。
‘-debug_ts (global)’
打印时间戳信息。默认关闭。
‘-attach filename (output)’
添加一个附件到输出文件中
‘-dump_attachment[:stream_specifier] filename (input,per-stream)’
提取匹配的附件流到filename指定的文件中。
3.3 视频选项
‘-vframes number (output)’
设置录制视频帧的个数。这是 -frames:v 的别名
‘-r[:stream_specifier] fps (input/output,per-stream)’
设置帧率(Hz 值, 分数或缩写)
‘-s[:stream_specifier] size (input/output,per-stream)’
设置帧大小。格式为 ‘wxh’ (默认与源相同)
‘-aspect[:stream_specifier] aspect (output,per-stream)’
设置视频显示长宽比
‘-vn (output)’
禁止视频录制
‘-vcodec codec (output)’
设置视频 codec。这是 -codec:v 的别名
‘-pass[:stream_specifier] n (output,per-stream)’
选择pass number (1 or 2)。用来进行双行程视频编码。
‘-passlogfile[:stream_specifier] prefix (output,per-stream)’
设置 two-pass 日志文件名前缀,默认为“ffmpeg2pass”。
‘-vf filtergraph (output)’
创建 filtergraph 指定的过滤图,并使用它来过滤流。
3.4 高级视频选项
‘-pix_fmt[:stream_specifier] format (input/output,per-stream)’
设置像素格式。
‘-sws_flags flags (input/output)’
设置软缩放标志
‘-vdt n’
丢弃阈值
‘-psnr’
计算压缩帧的 PSNR
‘-vstats’
复制视频编码统计信息到‘vstats_HHMMSS.log’
‘-vstats_file file’
复制视频编码统计信息到 file
‘-force_key_frames[:stream_specifier] time[,time...] (output,per-stream)’
‘-force_key_frames[:stream_specifier] expr:expr (output,per-stream)’
在指定的时间戳强制关键帧
‘-copyinkf[:stream_specifier] (output,per-stream)’
当进行流拷贝时,同时拷贝开头的非关键帧
‘-hwaccel[:stream_specifier] hwaccel (input,per-stream)’
使用硬件加速来解码匹配的流
‘-hwaccel_device[:stream_specifier] hwaccel_device (input,per-stream)’
选择硬件加速所使用的设备。该选项只有‘-hwaccel’同时指定时才有意义。
3.5 音频选项
‘-aframes number (output)’
设置录制音频帧的个数。这是 -frames:a 的别名
‘-ar[:stream_specifier] freq (input/output,per-stream)’
设置音频采样率。
‘-aq q (output)’
设置音频质量。这是 -q:a 的别名
‘-ac[:stream_specifier] channels (input/output,per-stream)’
设置音频通道数。
‘-an (output)’
禁止音频录制
‘-acodec codec (input/output)’
设置音频codec。这是-codec:a的别名
‘-sample_fmt[:stream_specifier] sample_fmt (output,per-stream)’
设置音频采样格式
‘-af filtergraph (output)’
创建filtergraph 所指定的过滤图,并使用它来过滤流
3.6 字幕选项
‘-scodec codec (input/output)’
设置字幕codec。这是 -codec:s 的别名
‘-sn (output)’
禁止字幕录制
3.7 高级选项
‘-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]] | [linklabel] (output)’
指定一个或多个流作为输出文件的源。
命令行中的第一个 -map 选项,指定输出流0的源,
第二个 -map 选项,指定输出流1的源,等等。
‘-map_channel [input_file_id.stream_specifier.channel_id|-1][:output_file_id.stream_specifier]’
将一个给定输入的音频通道映射到一个输出。
‘-map_metadata[:metadata_spec_out] infile[:metadata_spec_in] (output,per-metadata)’
设置下一个输出文件的 metadata 信息。
‘-map_chapters input_file_index (output)’
从索引号为 input_file_index 的输入文件中拷贝章节到下一个输出文件中。
‘-timelimit duration (global)’
ffmpeg 运行 duration 秒后推出
‘-dump (global)’
将每一个输入包复制到标准输出
‘-hex (global)’
复制包时,同时复制负载
‘-re (input)’
以本地帧率读取数据。主要用来模拟一个采集设备,
或者实时输入流(例如:当从一个文件读取时).
‘-vsync parameter’
视频同步方法
‘-async samples_per_second’
音频同步方法
‘-shortest (output)’
当最短的输入流结束时,终止编码
‘-muxdelay seconds (input)’
设置最大解封装-解码延时
‘-muxpreload seconds (input)’
设置初始解封装-解码延时
‘-streamid output-stream-index:new-value (output)’
为一个输出流分配一个新的stream-id。
‘-bsf[:stream_specifier] bitstream_filters (output,per-stream)’
为匹配的流设置比特流过滤器
‘-filter_complex filtergraph (global)’
定义一个复杂的过滤图
‘-lavfi filtergraph (global)’
定义一个复杂的过滤图。相当于‘-filter_complex’
‘-filter_complex_script filename (global)’
该选项类似于‘-filter_complex’,唯一的不同是
它的参数是一个定义过滤图的文件的文件名
‘-accurate_seek (input)’
打开或禁止在输入文件中的精确跳转。默认打开。 更详细的高级选项说明,请查阅 ffmpeg 文档

4. ffmpeg 使用示例

1) 输出 YUV420P 原始数据
ffmpeg -i test.mp4 test.yuv
2) 从视频前10s中提取图像,1s提取一帧
ffmpeg -i test.mp4 -t 10 -r 1 -f image2 pic-%03d.jpeg
3) 从视频中提取音频
ffmpeg -i test.mp4 -vn music.mp2
4) 转换 wav 格式,同时改变其采样率
ffmpeg -i test.wav -ar 32K test.mp2
5) 输出 mp3 原始 PCM 数据
ffmpeg -i test.mp3 -f s16le test.pcm 转自http://www.tuicool.com/articles/nquMZv

黄聪:FFmpeg 使用指南的更多相关文章

  1. 黄聪:《跟黄聪学WordPress插件开发》

    续<跟黄聪学WordPress主题开发>之后,又一个作品完成!<跟黄聪学Wordpress插件开发>,国内最好的Wordpress插件开发视频教程!! 目录预览: WordPr ...

  2. 黄聪:PHP使用Simple_HTML_DOM遍历、过滤及保留指定属性

    <? /* * 参考资料: * http://www.phpddt.com/manual/simplehtmldom_1_5/manual_api.htm * http://www.phpddt ...

  3. 黄聪:《跟黄聪学WordPress主题开发》

    又一个作品完成!<跟黄聪学Wordpress主题开发>,国内最好的Wordpress主题模版开发视频教程!! 目录预览: WordPress官方源文件层式结构讲解 WordPress数据库 ...

  4. 黄聪:VS2010开发如何在c#中使用Ctrl、Alt、Tab等全局组合快捷键

    1.新建一个类 HotkeyHelper  using System; using System.Runtime.InteropServices; using System.Windows.Forms ...

  5. 黄聪:如何使用CodeSmith批量生成代码(转:http://www.cnblogs.com/huangcong/archive/2010/06/14/1758201.html)

    先看看CodeSmith的工作原理: 简单的说:CodeSmith首先会去数据库获取数据库的结构,如各个表的名称,表的字段,表间的关系等等,之后再根据用户自定义好的模板文件,用数据库结构中的关键字替代 ...

  6. 黄聪:Microsoft Enterprise Library 5.0 系列教程(六) Security Application Block

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(六) Security Application Block 开发人员经常编写需要安全功能的应用程序.这些应用程序 ...

  7. 黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(七) Exception Handling Application Block 使用企业库异常处理应用程序模块的 ...

  8. 黄聪:Microsoft Enterprise Library 5.0 系列教程(五) Data Access Application Block

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(五) Data Access Application Block 企业库数据库访问模块通过抽象工厂模式,允许用户 ...

  9. 黄聪:Microsoft Enterprise Library 5.0 系列教程(四) Logging Application Block

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(四) Logging Application Block 企业库日志应用程序模块工作原理图:   从上图我们可以 ...

  10. 黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级)

    原文:黄聪:Microsoft Enterprise Library 5.0 系列教程(三) Validation Application Block (高级) 企业库验证应用程序模块之配置文件模式: ...

随机推荐

  1. 服务器安装wordpress,搭建自己的博客平台

    自己构造网站的话,建立一个简单的网页还可以(比如,yongjieshi.com),对于建立复杂的博客就需要借助第三方的工具,常见的有wordpress,在阿里云上安装wordpress,我主要参考了这 ...

  2. Python学习之---Python中的内置函数(方法)(更新中。。。)

    add(item)   #将item添加到s中,如果item已经在s中,则无任何效果 break        #退出循环,不会再运行循环中余下的代码 bool()     #将参数转换为布尔型 by ...

  3. 树莓派ssh服务

    从官网下载的镜像更新raspberry pi 3 B,但默认是不支持SSH的,即不可外部通过SSH登陆到板子里. 解决办法很简单,在SD卡的根目录下创建一个"ssh"的文件夹即可.

  4. 《DSP using MATLAB》Problem 5.20

    窗外的知了叽叽喳喳叫个不停,屋里温度应该有30°,伏天的日子难过啊! 频率域的方法来计算圆周移位 代码: 子函数的 function y = cirshftf(x, m, N) %% -------- ...

  5. 【BZOJ3238】【AHOI2013】差异

    sam好,好写好调好ac! 原题: 图片题面好评 2<=N<=500000 在syq大神的指点下终于理解一道后缀自动姬了quq (其实是因为这道题的dp主要是在后缀树(就是拓扑序)上搞树形 ...

  6. mysql export query result

    1 . export by shell a.sql use dbname; SELECT id,iab_num FROM iab_list ; mysql -h host -uusername -P3 ...

  7. linux 变量定义

    本地变量:用户自定义的变量. 环境变量:用于所有用户变量,用于用户进程前,必须用export命令导出. 位置变量:$0(脚本名),$1-$9:脚本参数. 特定变量:脚本运行时的一些相关信息. $# 传 ...

  8. nakadi-ui nakadi event broker 的可视化UI工具

    nakadi 是一款很不错的基于fafka 开发的event broker ,我们只需要使用http 请求就可以调用kafka 方便的发布订阅功能 环境准备 docker-compose 文件 ver ...

  9. 用Hi3518EV200板当spi烧录器

    1. setenv bootargs setenv bootcmd 2.ddr烧录uboot 3.uboot下tftp下载文件 mw.b ff ;tftp ;sf erase ;sf write ; ...

  10. Navicat permium工具连接Oracle的配置

    目标数据库是Oracle11g R2 64位的 搜索很多说是需要32位的Oracle客户端,而且是要下载 Basic 版本,但是下载32位的Oracle客户端还是不行 最后把Navicat Premi ...