oyagev
oyagev

Reputation: 43

How to create a sized FIFO buffer in Linux?

Specifically I'm trying to capture audio or video stream from device and keep only X minutes (or Y MBytes) when a button is pressed. Any native way to do that in Linux?

I know about fifo but that just keeps all the data. I want to pipe my stream to a specific buffer which only keeps the last Y MBytes and discards the rest.

Thanks

Upvotes: 2

Views: 1745

Answers (1)

Guntram Blohm
Guntram Blohm

Reputation: 9819

The closest thing i'd see is piping your stream into the split command, with the -b and -v options. -b tells split to split lines by number of bytes, not number of lines, and -v tells you whenever split starts a new file. Pipe the output of split into some small script that starts deleting files when split starts new ones, so you'll never have more than files at the same time.

If you give the split command a prefix XXX (different prefix for different streams), you can just cat XXX* to put the parts together.

Of course, the start of your output will "hop" by individual file size, not by byte. But i think this is the closest you can get without a specific program.

Fifos won't work well in your case anyway since they have a limited buffer size; the writer will block when there's no reader, and you can't have more than one reader at the same time.

Upvotes: 2

Related Questions