ffmpeg教程

转自:http://blog.csdn.net/kl222/article/details/7819301

 

1.1         ffmpeg格式

ffmpeg [[options][`-i' input_file]]... {[options] output_file}...

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

1.2         流复制:复制文件的流,只更改容器(文件)格式。

./ffmpeg –v debug –i inputfile.mpg –c copy  -f asf outfile.asf

-f:设置混合器

-c:设置编码器。当为 copy:指复制编码流

-i:输入文件

-v:调试信息级别(quietpanicfatalerrorwarninginfoverbosedebug

1.3         指定流:

一个容器里可以包含许多流,包括任何的音视频流。那么在命令行怎样区分流呢?

答:由“:”进行分隔

./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开始

 

ffmpeg教程五 —— 使用举例

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有两种视频捕获方式,使用VFWDSHOW,你需要在编译ffmpeg时,把相应的组件编译进libavdevice中,下面使用vfw方式捕获:

./ffmpeg -t 10 -f vfwcap -i 0 -r 25 -f asf cap.asf

我们采集10秒,采集设备为vfwcap类型设备,第0vfwcap采集设备(如果系统有多个vfw的视频采集设备,可以通过-i num来选择),每秒25帧,输出方式为文件,格式为asf

Linux平台上,ffmpegV4L2的视频设备提高了很好的支持,如:

./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视频设备进行采集,采集QCIF176*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

 

---------------------------------------------------------------------------------------------------------------------------------------

 

1.1        Ffmpeg选项详解

你可以使用:ffmpeg –help来获得选项内容

1.1.1   通用选项

-L license

-h 帮助

-fromats显示可用的格式,编解码的,协议的

-codecs显示可用的编解码器

-bsfs     显示bit流过滤器

-protocols显示可用的协议

-pix_fmts显示可用的位图格式

-sample_fmts显示可用的音频采样格式

-loglevel loglevelset 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 设置评论

1.1.2   视频选项

-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

1.1.3   高级视频选项

-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

1.1.4   音频选项

-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

1.1.5   音频/视频捕获选项

-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

1.1.6   高级选项

-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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值