快捷搜索:  汽车  科技

ffmpeg命令大全(FFMPEG完美入门资料---002---FFmpeg)

ffmpeg命令大全(FFMPEG完美入门资料---002---FFmpeg)Pass the source unchanged to the output.anull说明aformatConvert the input audio to one of the specified formats.


接着上文写:

2.3.1 ffmpeg 对编码解码器的支持 ffmpeg 支持的编解码器种类共有 280 多种, 涵盖了几乎所有常见音视频编码格式, 能解码几乎所有的音视频, 每种音视频编解码器的实现都在 libavcodec 目录下有具体的 C 语言实现。

  • 注:编码器和解码器的名称不是完全匹配的,因此有些编码器没有对应相同名称的解码器,反之, 解码器也一样。即使编码和解码都支持也不一定是完全对应的,例如 h263 解码器对应有 h263p 和 h263 编码器。

2.3.2 FFmpeg 对容器格式的支持 ffmpeg 支持对绝大多数的容器格式的读写操作,共计 190 多种, 涵盖了互联网上各 种常见媒体格式及日常生活中及专业应用中的各种媒体格式。 2.3.3 FFmpeg 对过滤器的支持

Filters

说明

aformat

Convert the input audio to one of the specified formats.

anull

Pass the source unchanged to the output.

aresample

Resample audio data.

ashowinfo

Show textual information for each audio frame.

abuffer

Buffer audio frames, and make them accessible to the filterchain.

anullsrc

Null audio source, never return audio frames.

abuffersink

Buffer audio frames, and make them available to the end of the filter graph.

anullsink

Do absolutely nothing with the input audio.

copy

Copy the input video unchanged to the output.

crop

Crop the input video to width:height❌y.

drawbox

Draw a colored box on the input video.

fade

Fade in/out input video

fieldorder

Set the field order.

fifo

Buffer input images and send them when they are requested.

format

Convert the input video to one of the specified pixel formats.

gradfun

Debands video quickly using gradients.

hflip

Horizontally flip the input video.

lut

Compute and apply a lookup table to the RGB/YUV input video.

lutrgb

Compute and apply a lookup table to the RGB input video.

lutyuv

Compute and apply a lookup table to the YUV input video.

negate

Negate input video.

noformat

Force libavfilter not to use any of the specified pixel formats for the input to the next filter.

null

Pass the source unchanged to the output.

overlay

Overlay a video source on top of the input.

pad

Pad input image to width:height[❌y[:color]] (default x and y: 0, default color: black).

pixdesctest

Test pixel format definitions.

scale

Scale the input video to width:height size and/or convert the image format.

select

Select frames to pass in output.

setdar

Set the frame display aspect ratio.

setpts

Set PTS for the output video frame.

setsar

Set the pixel sample aspect ratio.

settb

Set timebase for the output link.

showinfo

Show textual information for each video frame.

slicify

Pass the images of input video on to next video filter as multiple slices.

split

Pass on the input to two outputs.

transpose

Transpose input video.

unsharp

Sharpen or blur the input video.

vflip

Flip the input video vertically.

buffer

Buffer video frames, and make them accessible to the filterchain.

color

Provide an uniformly colored input, syntax is: [color[:size[:rate]]]

movie

Read from a movie source.

nullsrc

Null video source, never return images.

rgbtestsrc

Generate RGB test pattern.

testsrc

Generate test pattern.

buffersink

Buffer video frames, and make them available to the end of the filter graph.

nullsink

Do absolutely nothing with the input video.

2.3.4 FFmpeg 对图像颜色空间的支持 ffmpeg 支持常见的图像颜色空间,并且在 libavswcale 中定义了颜色空间转换的相关 函数实现各种颜色模式的互转。 2.4 FFmpeg 功能及使用说明 2.4.1 ffplay 对多媒体的支持能力验证

一、视频 3gp 177X144 支持播放, 在 windows 下播放正常, 但是在 Linux 下面偶有 BUG 如果 发现画面无法显示而声音可以播放的情况下 可以试着切换全屏或者切换分辨率。

AVI

208X176

支持

320X240

支持

720X400

支持

720X576

支持

DAT

352X288

支持

DiVX

720X576

支持

MKV

320X240

支持

352X288

支持

704X304

支持

720X576

支持

MP4

320X240

支持

352X288

支持

720X400

支持

MPG

320X240

支持

352X288

支持

480X576

支持

720X576

支持

720X480

支持

VOB

352X288

支持

XVID

720X576

支持

MOV

支持

RMVB

支持

做音视频开发要掌握哪些知识?

ffmpeg命令大全(FFMPEG完美入门资料---002---FFmpeg)(1)

二、音频

AC3

48KHZ

支持

APE

11KHZ

支持

22KHZ

支持

44KHZ

支持

48KHZ

支持

MP3

32KHZ

64Kbps

支持

32KHZ

128KbpS

支持

32KHZ

160Kbps

支持

32KHZ

192Kbps

支持

32KHZ

320Kbps

支持

44KHZ

64Kbps

支持

44KHZ

128Kbps

支持

44KHZ

160Kbps

支持

44KHZ

192Kbps

支持

44KHZ

320Kbps

支持

48KHZ

64Kbps

支持

48KHZ

128Kbps

支持

48KHZ

160Kbps

支持

48KHZ

192Kbps

支持

48KHZ

320Kbps

支持

OGG

32KHZ

128Kbps

支持

32KHZ

192Kbps

支持

44KHZ

64Kbps

支持

44KHZ

128Kbps

支持

44KHZ

192Kbps

支持

48KHZ

64Kbps

支持

44KHZ

128Kbps

支持

44KHZ

192Kbps

支持

WAV

11KHZ

支持

22KHZ

16Kbps

支持

44KHZ

16Kbps

支持

48KHZ

16Kbps

支持

WMA

8KHZ

16Kbps

支持

11KHZ

16Kbps

支持

16KHZ

16Kbps

支持

22KHZ

16Kbps

支持

44KHZ

16Kbps

支持

48KHZ

16Kbps

支持

三、图像

PNG

支持

JPG

支持

JPEG

支持

GIF

支持

BMP

支持

2.4.2 FFmpeg 格式转换第一步:准备媒体

前面已经讲的很清楚了, ffmpeg 如何安装不在赘述。 准备好相应的文件, 如图 2-1 所示。

ffmpeg命令大全(FFMPEG完美入门资料---002---FFmpeg)(2)

第二步:启动 ffmpeg 由于做的是格式转换,在 ffserver 上不能直观的看见结果,故我是在 linux 下进行的。 打开终端,值得一提的是格式转换需要超级用户才能进行,故在命令行输入:su,<回车>, 输入密码进入超级用户, 本例中, 以 FFmpeg 将 test.avi 转换为 test.mpg。 在命令行中输 入:./ffmpeg –i test.avi –r 25 –s 720x400 test.mpg<回车>。 其中原格式分辨率为 320x240, 将转为 720x400, -r 前面已经解释其含义, 表示设置帧频为 25。 转换成功后如图 2-2 所 示,前后两种格式播放效果如图 2-3 所示。相应的,转换为其他格式做相应的变化即可。

同时还可以在转换格式时进行强制的音视频转换, 如–vcodec 格式, 将会强制将 视频按指定格式编码, -acodec 格式, 将会强制按指定格式编码音频信息。 在转换中有 很多其他参数可以指定,如码率、分辨率、帧率等,具体按照 ffmpeg 的参数说明指定参 数即可。 但有一条转低不转高的原则需要注意, 即品质差的音视频转换不建议转换到品 质好的音视频。

ffmpeg命令大全(FFMPEG完美入门资料---002---FFmpeg)(3)

ffmpeg命令大全(FFMPEG完美入门资料---002---FFmpeg)(4)

再说说如何在转换视频的时候将音频合成到视频中, 且覆盖其原来的音频。 这个现 在摸索出两种方法。 方法一:需要两条命令实现, 先在命令行中输入:

./ffmpeg –i test.avi -an –r 25 test.mpg <回车>

此时将生成一个没有声音的 test.mpg 视频, 再在命令行中输入:

./ffmpeg –i test.mpg –i test.mp3 –r 25 test1.mpg<回车>

此时将会生成一个名为 test1.mpg 的视频。 该视频播放时视频为 test.avi 的视频, 但音频 变为了 test.mp3 的音频了。 方法二:只要一条指令即可实现。 在命令行中输入:

./ffmpeg –i test.avi –i test.mp3 –vcodec copy –acodec copy –r 25 test2.mpg<回车>

此时将会生成一个名为 test2.mpg 的视频, 播放时其视频为 test.avi 的视频, 音频为 test.mp3。 –vcodec copy 为 force video codec(‘copy’ to copy stream)。 有一点需要注意, 文件命名不能有空格, 否则会导致编译时不能通过。 另外, -an 为不能使音频记录。 第三步:播放媒体 播放我们转换的媒体, 看看是否满足我们当初的愿望, 不出什么差错的话, 是完全 能够满足我们的要求的。 2.4.3 FFmpeg 视频截图 截取一张 300x200 尺寸大小的格式为 jpg 的一张图片:

./ffmpeg –i test.avi –y –f image2 –t 0.001 –s 300x200 test.jpg

要截取指定时间的图片, 如 5 秒之后的:

./ffmpeg –i test.avi –y –f image2 –ss 5 –t 0.001 –s 300x200 test.jpg

其中, -ss 后的单位为秒, 也可写成:-ss 00:00:05。 把视频的前 30 帧转换为一个动态的 gif 图。 需要说明的是, 转换成功之后, 如果用 ffplay 播放是看不出效果的, 建议换成其他图片播放器播放。 其转换命令为:

./ffmpeg –i test.avi –vframes 30 –pix_fmt rgb24–y –f gif test.gif

也可以从视频中的第 10 秒开始截取后面的 5 秒内容转换为一个无限重播的动态 gif 图。 其命令为:

./ffmpeg –i test.avi –pix_fmt rgb24 –ss 10 –t 5 –y –f gif test.gif

上面两种动态 gif 都是只播一次, 想让其一直播, 可再加一个参数:-loop_output 0。

2.4.4 FFmpeg 屏幕录制

屏幕录制其命令为:

./ffmpeg -f x11grab -r 25 -s wxga -i :0.0 /tmp/outputFile.mpg

其他相关参数可自行添加。 需要说明的是, 各个版本的 ffmpeg 对屏幕录制的命令不一。 如果你只想录制一个应用程序窗口或者桌面上的一个固定区域, 那么可以指定偏移位置 和区域大小。 使用 xwininfo -frame 命令可以完成查找上述参数。 注:ffmpeg 的屏幕录制功能只能在 Linux 环境下有效。 并且在配置时需要添加 –enable-x11grub 指令, 默认关闭。 2.4.5 FFmpeg 音视频采集 把摄像头的实时视频录制下来, 存储为文件

./ffmpeg -f video4linux -s 320x240 -r 10 -i /dev/video0 test.asf

录音, 其命令为:

./ffmpeg –i /dev/dsp -f oss test.mp3

2.5 FFmpeg 应用实例 2.5.1 用 FFserver 从文件生成流媒体 一、安装 ffmpeg 在 ubuntu 下, 运行 sudo apt-get ffmpeg 安装 ffmpeg, 在其他 linux 操作系统下, 见 ffmpeg 的编译过程(编译完成后可执行自动安装)。 二、准备预播放的媒体文件 如 test.Mp3,在本文档中,默认放入用户文件夹下得 Music 文件夹内.(直接从设备采 集不在本文档叙述范围之内) 三、修改 ffserver 配置信息 ffserver 配置文件为: /etc/ffserver.conf 打开, 填写配置信息.配置信息包括三方面:

  • 1.端口绑定等基本信息,在/etc/ffserver.conf 中有详细注释,在此不再重复,最终配 置信息为:

Port 8090

BindAddress 0.0.0.0

MaxHTTPConnections 2000

MaxClients 1000

MaxBandwidth 1000

2.媒体文件配置信息.本信息根据具体的媒体文件类型直接在配置文件中取消注释 掉相应文件类型的配置信息, 然后填写文件路径即可:

# MP3 audio <Stream test.mp3> File "/home/xiaoma/Music/test.mp3" Format mp2 NoVideo </Stream>四、启动 ffserver

在终端中运行如下代码来启动ffserver

sudo ffserver -f /etc/ffserver.conf

五、播放流媒体 在浏览器中输入http://127.0.0.1:8090/test.mp3即可播放音乐. 在终端中输入 ffplay http://localhost:8090/test.mp3 可播放流媒体. 2.5.2 用 FFserver 从设备生成实时流 一、准备媒体 按照上节步骤安装 ffmpeg,保证摄像头和声卡可用, 将从摄像头和声卡获取音视频 信息。 二、修改 ffserver 配置信息 ffserver 配置文件为: /etc/ffserver.conf 打开, 填写配置信息.配置信息包括三方面:

  • 1.端口绑定等基本信息,在/etc/ffserver.conf 中有详细注释,在此不再重复,最终配 置信息为:

Port 8090

BindAddress 0.0.0.0

MaxHTTPConnections 2000

MaxClients 1000

MaxBandwidth 1000

2.fend(传冲信息),在文件播放中,基本不用动本配置信息,只需要根据具体情况分 配缓冲文件.最终配置信息如下:

<Feed feed1.ffm> File /tmp/feed1.ffm FileMaxSize 2M ACL allow 127.0.0.1 </Feed>

(中间会有很多很多配置信息,都是关于音视频的,有些配置还不懂,慢慢摸索吧)

<Stream test1.mpg> Feed feed1.ffm Format mpeg AudioBitRate 32 AudioChannels 1 AudioSampleRate 44100 VideoBitRate 64 VideoBufferSize 40 VideoFrameRate 3 VideoSize 160x128 VideoGopSize 12 </Stream> # Flash <Stream test.swf> Feed feed1.ffm Format swf VideoFrameRate 2 VideoIntraOnly NoAudio </Stream>三、启动 FFserver

在终端中运行如下代码来启动 ffserver.

sudo ffserver -f /etc/ffserver.conf

四、启动 ffmpeg 本例中, 以 ffmpeg 作为实时摄像头采集输入.在命令行中输入:

./ffmpeg -f video4linux2 -r 25 -i /dev/video0 /tmp/feed1.ffm

如果有音频设备, 则采集音频的命令如下:

./ffmpeg -f oss -i /dev/dsp -f video4linux2 -r 25 -i /dev/video0 /tmp/feed1.ffm

(音频格式参数自己配置) 五、播放流媒体 在浏览器中输入 http://127.0.0.1:8090/test1.mpg 即可播放音乐. 在终端中输入 ffplay http://localhost:8090/test.swf 可播放流媒体.

作者:张芳涛

猜您喜欢: