1、组成

程序:ffmpeg、ffplay、ffprobe、ffserver
ffmpeg:转码程序
ffplay:播放程序
ffserver:服务器程序

库:libavcodec、libavdevice、libavfilter、libavformat、libavresample、libavutil、libpostproc、libswresample、libswscale
libavcodec:编解码器库,提供所有支持的编解码器
libavformat:格式库,提供所有支持的文件、流格式
libavfilter:过滤器
libswscale:图像处理库
libavdevice:输入设备库。包括视频、音频的捕获设备接口。例如:windows下的vfw、directshow;linux下video4linux

2、使用

ffmpeg格式
ffmpeg [[options][`-i' input_file]]... {[options] output_file}...
如果没有输入文件,那么视音频捕捉(只在Linux下有效,因为Linux下把音视频设备当作文件句柄来处理)就会起作用。作为通用的规则,选项一般用于下一个特定的文件。如果你给 –b 64选项,改选会设置下一个视频速率。对于原始输入文件,格式选项可能是需要的。缺省情况下,ffmpeg试图尽可能的无损转换,采用与输入同样的音频视频参数来输出。

流复制:复制文件的流,只更改容器(文件)格式。
./ffmpeg –v debug –i inputfile.mpg –c copy -f asf outfile.asf
-f:设置混合器
-c:设置编码器。当为 copy:指复制编码流
-i:输入文件
-v:调试信息级别(quiet、panic、fatal、error、warning、info、verbose、debug)

指定流:
一个容器里可以包含许多流,包括任何的音视频流。那么在命令行怎样区分流呢?
答:由“:”进行分隔
./ffmpeg –i inputfile.mpg –c:v h263 –c:a g722 –f asf outfile.asf
./ffmpeg –i inputfile.mpg –c:0 h263 –c:1 g722 –f asf outfile.asf
上面命令表示把输入文件 inputfile文件的视频流转换成h263格式,把音频流转换成g722格式。
v:视频
a:音频
数字:表示第几路,从0开始

3、通用选项

-L license
-h 帮助
-fromats显示可用的格式,编解码的,协议的
-codecs 显示可用的编解码器
-bsfs 显示bit流过滤器
-protocols显示可用的协议
-pix_fmts显示可用的位图格式
-sample_fmts显示可用的音频采样格式
-loglevel loglevel set libav* logging level
-v loglevel set libav* logging level
-debug flags set debug flags
-fdebug flags set debug flags
-report generate a report

-f fmt强迫采用格式fmt
-i filename输入文件
-y 覆盖输出文件
-c编解码器名字
-t duration 设置纪录时间 hh:mm:ss[.xxx]格式的记录时间也支持
-ss position 搜索到指定的时间 [-]hh:mm:ss[.xxx]的格式也支持
-timestamp time 设置记录时间戳(‘now’指定当前时间)
-title string 设置标题
-author string 设置作者
-copyright string 设置版权
-comment string 设置评论

4、视频选项

-vframes number 设置记录的视频帧数
-r rate 设置帧率 (Hz value, fraction or abbreviation)
-s size 设置帧的大小 (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-bits_per_raw_sample number set the number of bits per raw sample
-croptop size Removed, use the crop filter instead
-cropbottom size Removed, use the crop filter instead
-cropleft size Removed, use the crop filter instead
-cropright size Removed, use the crop filter instead
-padtop size Removed, use the pad filter instead
-padbottom size Removed, use the pad filter instead
-padleft size Removed, use the pad filter instead
-padright size Removed, use the pad filter instead
-padcolor color Removed, use the pad filter instead
-vn 禁用视频
-vcodec codec force video codec ('copy' to copy stream)
-sameq use same quantizer as source (implies VBR)
-same_quant use same quantizer as source (implies VBR)
-timecode hh:mm:ss[:;.]ff set initial TimeCode value.
-pass n select the pass number (1 or 2)
-passlogfile prefix select two pass log file name prefix
-vf filter list video filters
-b bitrate video bitrate (please use -b:v)
-dn disable data

5、高级视频选项

-pix_fmt format 设置位图格式
-intra deprecated use -g 1
-vdt n discard threshold
-rc_override override rate control override for specific intervals
-deinterlace this option is deprecated, use the yadif filter instead
-psnr calculate PSNR of compressed frames
-vstats dump video coding statistics to file
-vstats_file file dump video coding statistics to file
-intra_matrix matrix specify intra matrix coeffs
-inter_matrix matrix specify inter matrix coeffs
-top top=1/bottom=0/auto=-1 field first
-dc precision intra_dc_precision
-vtag fourcc/tag force video tag/fourcc
-qphist show QP histogram
-force_fps force the selected framerate, disable the best supported framerate selection
-force_key_frames timestamps force key frames at specified timestamps
-vbsf video bitstream_filters deprecated
-vpre preset set the video options to the indicated preset

6、音频选项

-aframes number set the number of audio frames to record
-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)
-af filter list audio filters

7、音频/视频捕获选项

-vc channel deprecated, use -channel
-tvstd standard deprecated, use -standard
-isync sync read on input
-vd device 设置视频捕获设备。比如/dev/video0
-dv1394 设置DV1394捕获
-av device 设置音频设备比如/dev/dsp

8、高级选项

-cpuflags flags force specific cpu flags
-map [-]input_file_id[:stream_specifier][,sync_file_id[:stream_s set input stream mapping
-map_channel file.stream.channel[:syncfile.syncstream] map an audio channel from one stream to another
-map_chapters input_file_index set chapters mapping
-benchmark add timings for benchmarking
-benchmark_all add timings for each task
-progress url write program-readable progress information
-dump dump 每个输入包
-hex 当 dumping包时,也dump其荷载
-re read input at native frame rate
-vsync video sync method
-async audio sync method
-adrift_threshold threshold audio drift threshold
-copyts copy timestamps
-copytb mode copy input stream time base when stream copying
-shortest finish encoding within shortest input
-dts_delta_threshold threshold timestamp discontinuity delta threshold
-dts_error_threshold threshold timestamp error delta threshold
-copyinkf copy initial non-keyframes
-q q use fixed quality scale (VBR)
-qscale q use fixed quality scale (VBR)
-profile profile set profile
-filter_complex graph_description create a complex filtergraph
-debug_ts 打印调试信息时间戳
-streamid streamIndex:value set the value of an outfile streamid
-muxdelay seconds set the maximum demux-decode delay
-muxpreload seconds set the initial demux-decode delay
-fpre filename set options from indicated preset file

9、例程

1.1.1 截取一张352x240尺寸大小的,格式为jpg的图片:
ffmpeg -i test.asf -y -f image2 -t 0.001 -s 352x240 a.jpg

1.1.2 把视频的前30帧转换成一个Animated Gif
ffmpeg -i test.asf -vframes 30 -y -f gif a.gif

1.1.3 截取指定时间的缩微图
ffmpeg -i test.avi -y -f image2 -ss 8 -t 0.001 -s 350x240 test.jpg
-ss后跟的时间单位为秒

1.1.4 转换文件为3GP格式
ffmpeg -y -i test.mpeg -bitexact -vcodec h263 -b 128 -r 15 -s 176x144
-acodec aac -ac 2 -ar 22500 -ab 24 -f 3gp test.3gp

1.1.5 使用ffmpeg录像屏幕
ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -vd x11:0,0 -s 1024x768 ~/test.avi
:其中,-vd x11:0,0指录制所使用的偏移为 x=0和 y=0,-s 1024×768指录制视频的大小为 1024×768。录制的视频文件为 test.avi,将保存到用户主目录中
如果你只想录制一个应用程序窗口或者桌面上的一个固定区域,那么可以指定偏移位置和区域大小。使用xwininfo -frame命令可以完成查找上述参数。
重新调整视频尺寸大小
ffmpeg -vcodec mpeg4 -b 1000 -r 10 -g 300 -i ~/test.avi -s 800×600 ~/test-800-600.avi
注:上面的ffmpeg的屏幕录制功能只能在Linux环境下有效。在windows下是否可行,本人还不知道如何操作,如果你知道,请告诉我J

1.1.6 把摄像头的实时视频录制下来,存储为文件
在windows有两种视频捕获方式,使用VFW或DSHOW,你需要在编译ffmpeg时,把相应的组件编译进libavdevice中,下面使用vfw方式捕获:
./ffmpeg -t 10 -f vfwcap -i 0 -r 25 -f asf cap.asf
我们采集10秒,采集设备为vfwcap类型设备,第0个vfwcap采集设备(如果系统有多个vfw的视频采集设备,可以通过-i num来选择),每秒25帧,输出方式为文件,格式为asf
在Linux平台上,ffmpeg对V4L2的视频设备提高了很好的支持,如:
./ffmpeg -t 10 -f video4linux2 -s 176*144 -r 8 -i /dev/video0 -vcodec h263 -f rtp rtp://192.168.1.105:5060 > /tmp/ffmpeg.sdp
以上命令表示:采集10秒钟视频,对video4linux2视频设备进行采集,采集QCIF(176*144)的视频,每秒8帧,视频设备为/dev/video0,视频编码为h263,输出格式为RTP,后面定义了IP地址及端口,将该码流所对应的SDP文件重定向到/tmp/ffmpeg.sdp中,将此SDP文件上传到流媒体服务器就可以实现直播了。
./ffmpeg -t 10 -f video4linux2 -s 176*144 -r 10 -vpre libx264-hq.ffpreset -i /dev/video0 -vcodec libx264 -f rtp rtp://192.168.1.105:6060 > /tmp/x264.sdp
这条命令与上面的类似,但是视频编码为h264,由于ffmpeg是用外部库x264支持h264编码,因此h264的视频采集需要更多参数。主要是需要指定-vpre libx264-hq.ffpreset 才可以。

下面命令则是把捕获到的视频保存成文件:
ffmpeg -f video4linux -s 320*240 -r 10 -i /dev/video0 test.asf

1.1.1 接收组播直播流,并保存成文件:
./ffmpeg -i udp://@ip:port test.ts

1.1.2 从文件生成直播流:
ffmpeg -i a.flv -f flv rtmp://IP/livepkgr/livestream?adbe-live-event=liveevent
IP是你的fms服务器的IP地址

1.1.3 从组播地址接收组播,并把它转成rtmp协议发给 fms服务器
ffmpeg –i udp://@:port –f flv rtmp://IP/livepkgr/livestream?adbe-live-event=liveevent

1.1.4 对流进行分片(支持hls协议)
ffmpeg -I a.asf -codec copy -map 0 -f segment-segment_list out.m3u8 out%03d.tss

ffmpeg命令学习的更多相关文章

  1. FFmpeg常用命令学习笔记(一)基本信息查询命令

    笔者才开始学习音视频开发,FFmpeg学习笔记系列主要是从慕课网李超老师的FFmpeg音视频核心技术精讲与实战课程学习的心得体会. FFmpeg音视频核心技术精讲与实战:https://coding. ...

  2. FFmpeg命令行工具学习(一):查看媒体文件头信息工具ffprobe

    一.简述 ffprobe是ffmpeg命令行工具中相对简单的,此命令是用来查看媒体文件格式的工具. 二.命令格式 在命令行中输入如下格式的命令: ffprobe [文件名] 三.使用ffprobe查看 ...

  3. FFmpeg Android 学习(一):Android 如何调用 FFMPEG 编辑音视频

    一.概述 在Android开发中,我们对一些音视频的处理比较无力,特别是编辑音视频这部分.而且在Android上对视频编辑方面,几乎没有任何API做支持,MediaCodec(硬编码)也没有做支持.那 ...

  4. FFmpeg Basic学习笔记(3)

    视频叠加--画中画效果 overlay video filter 视频叠加比较常见的应用场景是台标的叠加,在画面左上角.右上角.左下角或右下角叠加台标. ffmpeg提供的overlay filter ...

  5. FFmpeg Basics学习笔记(2)

    帧率 fps的概念 帧率,单位FPS(frame per second), 用于衡量视频每秒的处理帧数,对于编码器而言说明编码器在1s的编码的速度,通常可以使用一帧的编码时间倒数简单计算:对于解码器而 ...

  6. FFmpeg Basics学习笔记(1)ffmpeg基础

    1 FFmpeg的由来 FFmpeg缩写中,FF指的是Fast Forward,mpeg是 Moving Pictures Experts Group的缩写.官网:ffmpeg.org 编译好的可执行 ...

  7. FFmpeg再学习 -- SDL 环境搭建和视频显示

    继续看雷霄骅的 课程资料 - 基于FFmpeg+SDL的视频播放器的制作 一.SDL 简介 参看:WIKI -- Simple DirectMedia Layer 参看:最简单的视音频播放示例9:SD ...

  8. FFmpeg再学习 -- FFmpeg解码知识

    继续看雷霄骅的 课程资料 - 基于FFmpeg+SDL的视频播放器的制作 前面用了五个篇幅来讲 FFmpeg,其主要目的是为实现将图片转视频的功能. 总的来说,对于 FFmepg 多少有一些了解了.但 ...

  9. FFmpeg再学习 -- 硬件加速编解码

    为了搞硬件加速编解码,用了一周时间来看 CUDA,接下来开始加以总结. 一.什么是 CUDA (1)首先需要了解一下,什么是 CUDA. 参看:百度百科 -- CUDA 参看:CUDA基础介绍 参看: ...

随机推荐

  1. 机器学习在 IT 运维管理中的必要性!

    机器学习技术在监控工具中的应用已经成为 IT 运维与 DevOps 团队的一大热点话题.尽管相关的使用案例很多,对 IT 团队而已真正的「杀手级应用」是机器学习如何提高实时事件管理能力,从而帮助较大规 ...

  2. POJ 2533 Longest Ordered Subsequence

    题目描述:LIS(Longest Increasing Subsequence)模板题 分析:O(n^2)的方法 状态表示:d[i]表示以i结尾的最长上升子序列长度 转移方程:d[i]=max{ 1, ...

  3. Razor视图引擎 语法学习(一)

    ASP.NET MVC是一种构建web应用程序的框架,它将一般的MVC(Model-View-Controller)模式应用于ASP.NET框架: ASP.NET约定优于配置:基本分为模型(对实体数据 ...

  4. (转)Android之ListView原理学习与优化总结

    转自: http://jishu.zol.com.cn/12893.html 在整理前几篇文章的时候有朋友提出写一下ListView的性能优化方面的东西,这个问题也是小马在面试过程中被别人问到的….. ...

  5. (转)两分钟彻底让你明白Android Activity生命周期(图文)!

    转自: http://blog.csdn.net/android_tutor/article/details/5772285 大家好,今天给大家详解一下Android中Activity的生命周期,我在 ...

  6. 网络处理2-异步POST请求和同步请求

    一.异步POST请求 假如请求路径是http://192.168.1.102:8080/MJServer/login,请求参数有2个: username :母鸡 pwd :123 1.POST请求细节 ...

  7. ffmpeg转码时对编码率和固定码率的处理

    http://www.rosoo.net/a/201107/14663.html 一般fps在代码里这样表示 Fps = den/num 如果den = 15,num=1,则fps = 15. 如果帧 ...

  8. 10 signs you’re dating the wrong person

    10 signs you’re dating the wrong person10个迹象表明TA不是你的真心人       Do you have any exes who were so awful ...

  9. 客户端用httpurlconnection来进行http连接的

    客户端用httpurlconnection来进行http连接的,并设置restful风格 请求响应流程 设置连接参数的方法 setAllowUserInteraction setDoInput set ...

  10. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-002Table per concrete class with implicit polymorphism(@MappedSuperclass、@AttributeOverride)

    一.结构 二.代码 1. package org.jpwh.model.inheritance.mappedsuperclass; import javax.persistence.MappedSup ...