26

FFmpeg has a number of video generating filters, listed in the documentation as "video sources":

  • cellauto
  • color
  • mptestsrc
  • fei0r_src
  • life
  • nullsrc, rgbtestsrc, testsrc

Those are great for using with other filters like overlay, but is there any way that I can generate a movie consisting of just one of those video sources without any input video?

Something like:

ffmpeg -vf color=red" red_movie.mp4

Except that that errors out with At least one input file must be specified.

4

2 回答 2

54

在最近的版本中,选项似乎略有变化。

要使用过滤器输入源,您必须:

  1. 使用以下命令将输入​​格式设置为 libavfilter 虚拟设备:-f lavfi
  2. -i使用标志设置过滤器输入源(不是-vf
  3. 提供参数作为完整的键值对,例如:color=color=red

ffplay也适用于测试您的过滤器图: ffplay -f lavfi -i color

例子

在这些示例中,我添加-t 30了指定我只想要 30 秒的输出。

红色)

ffmpeg -f lavfi -i color=color=red -t 30 red.mp4
                     ^     ^    ^
                     |     |    |
                   filter key value

密钥可以缩短为其缩写形式:-i color=c=red

SMPTE 彩条图案

ffmpeg -f lavfi -i smptebars -t 30 smpte.mp4

测试源模式

ffmpeg -f lavfi -i testsrc -t 30 -pix_fmt yuv420p testsrc.mp4

为了让它可靠地播放,您可能需要设置像素格式:-pix_fmt yuv420p

默认情况下,ffmpeg 将使用 yuv444p (x264, High 4:4:4 Predictive),一些玩家还不能解码

例如,它创建的视频导致 VLC 2.0.7 崩溃,并且在 QuickTime Player 10.2 (Mac OS X 10.8.4) 中只有 30 秒的黑屏。

更多关于测试源的信息在这里

RGB 测试源

ffmpeg -f lavfi -i rgbtestsrc -pix_fmt yuv420p -t 30 rgbtestsrc.mp4

与上一个示例一样,这可能对您不起作用,除非您将像素格式设置为 yuv420p,如图所示。

对于后代,这是我正在使用的版本:

ffmpeg version 1.2.1
libavutil      52. 18.100 / 52. 18.100
libavcodec     54. 92.100 / 54. 92.100
libavformat    54. 63.104 / 54. 63.104
libavdevice    54.  3.103 / 54.  3.103
libavfilter     3. 42.103 /  3. 42.103
libswscale      2.  2.100 /  2.  2.100
libswresample   0. 17.102 /  0. 17.102
libpostproc    52.  2.100 / 52.  2.100
于 2013-08-09T06:55:43.710 回答
20

Though hinted at in the documentation, this isn't explicitly spelled out. I was pleased to figure it out, so I thought I'd share.

The key is to use the special format lavfi:

Libavfilter input virtual device.

This input device reads data from the open output pads of a libavfilter filtergraph.

For each filtergraph open output, the input device will create a corresponding stream which is mapped to the generated output. Currently only video data is supported. The filtergraph is specified through the option ‘graph’.

Essentially, lavfi format causes the input to be treated as a video filter instead of a filename.

Thus, to make a movie consisting of nothing but red, the command is:

ffmpeg -f lavfi -i color=red -frames:v 200 red_movie.mp4

(Specifying the number of frames or otherwise limiting the input is crucial as filters generally have no fixed "end" point, and will happily go on generating video forever.)

于 2012-07-24T22:53:27.373 回答