如何在没有实际输入文件的情况下直接从 FFmpeg 过滤器生成视频文件? [英] How can I generate a video file directly from an FFmpeg filter with no actual input file?

查看:18
本文介绍了如何在没有实际输入文件的情况下直接从 FFmpeg 过滤器生成视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FFmpeg 有许多视频生成过滤器,在文档中列为.

例如,它创建的视频在 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 1.2.1 版libavutil 52. 18.100/52. 18.100libavcodec 54. 92.100/54. 92.100libav格式 54. 63.104/54. 63.104libavdevice 54. 3.103/54. 3.103libavfilter 3. 42.103/3. 42.103libswscale 2. 2.100/2. 2.100libswresample 0. 17.102/0. 17.102libpostproc 52. 2.100/52. 2.100

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.

解决方案

It looks like the options have changed slightly in recent versions.

To use the filter input sources, you have to:

  1. Set the input format to the libavfilter virtual device using: -f lavfi
  2. Set the filter input source using the -i flag (not -vf)
  3. Provide arguments as complete key-value pairs, like: color=color=red

This works for ffplay, too, to test your filtergraph: ffplay -f lavfi -i color

Examples

In these examples I've added -t 30 to specify that I only want 30 seconds of output.

Color (Red)

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

The key can be shortened to its abbreviated form: -i color=c=red

SMPTE Color Bars Pattern

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

Test Source Pattern

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

In order for this to playback reliably, you might need to set the pixel format with: -pix_fmt yuv420p

By default, ffmpeg will use yuv444p (x264, High 4:4:4 Predictive), which some players aren't yet able to decode.

For instance, the video it creates is crashing VLC 2.0.7 and is just 30 seconds of black in QuickTime Player 10.2 (Mac OS X 10.8.4).

More info on test source here.

RGB Test Source

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

As with the last example, this might not work for you unless you set the pixel format to yuv420p as shown.

For posterity, here's the version I'm using:

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

这篇关于如何在没有实际输入文件的情况下直接从 FFmpeg 过滤器生成视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆