Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG: extract a fram from a live stream once every 5 seconds

Tags:

ffmpeg

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.

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

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

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.

like image 999
Steve Avatar asked Oct 24 '25 12:10

Steve


1 Answers

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.

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

The piping syntax pipe: works here on Windows. Believe it should work on linux as well.

like image 70
Gyan Avatar answered Oct 26 '25 01:10

Gyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!