FFMPEG:每5秒从直播流中提取一个帧 [英] FFMPEG: extract a fram from a live stream once every 5 seconds
问题描述
我正在尝试从实时流中每5秒提取一次帧,而无需使用-vf选项.我正在使用Raspberry Pi,因此CPU至关重要.
I'm tryin gto extract a single frame from a live stream, every 5 seconds without using the -vf option. I'm using a Raspberry Pi so CPU is all important.
基本上,我正在从实时源流式传输UDP流,该源使用的CPU很少,但是我想每5秒拍摄一次快照.
Basically, I'm streaming a UDP stream from a live source, which uses very little CPU but I want to take a snapshot every 5 seconds.
这有效,但仅产生单个图像.
This works, but only produces a single image.
-c copy -f mpegts udp://239.0.0.1:1234 -vcodec copy -vframes 1 out.png
这有效,但是使用了所有CPU和更多CPU.
This works, but uses all the CPU and more.
-c copy -f mpegts udp://239.0.0.1:1234 -vcodec copy -vf fps=1 out%d.png
有人知道我是否可以不使用过滤器来做到这一点吗?我的另一个解决方案是运行第二个ffmpeg并连接到UDP流,这确实很麻烦.
Anyone know if I can do this without using a filter? My other solution is to run a second ffmpeg and connect to the UDP stream, which is really cumbersome.
推荐答案
由于关键帧是每秒一帧,并且您希望每5秒一帧,因此需要进行一些过滤,除非您可以从每5个中删除4个就可以了图片已创建.
Since your keyframes are one per second, and you want one frame every 5 seconds, some filtering is needed, unless you are okay with deleting 4 out of every 5 images created.
这里是假设关键帧间隔为1/s的情况下,每5秒创建一帧的模板.
Here's the template that creates one frame for every 5 seconds, assuming that keyframe interval is 1/s.
ffmpeg -i ... -c copy -map 0 -f tee "[f=mpegts]udp://239.0.0.1:1234|[f=mpegts]pipe:" | ffmpeg -f mpegts -skip_frame nokey -i pipe: -vf select='not(mod(n,5))' -vsync 0 out%d.png
这是将每个关键帧作为图像转储,然后删除不需要的关键帧:
and here's for dumping each keyframe as an image and then removing unneeded ones:
ffmpeg -i ... -c copy -map 0 -f tee "[f=mpegts]udp://239.0.0.1:1234|[f=mpegts]pipe:" | ffmpeg -f mpegts -skip_frame nokey -i pipe: -vsync 0 out%d.png
管道语法pipe:
在Windows上适用.相信它也可以在linux上运行.
The piping syntax pipe:
works here on Windows. Believe it should work on linux as well.
这篇关于FFMPEG:每5秒从直播流中提取一个帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!