LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need a big buffer to introduce delay in a pipe. (FIFO) (https://www.linuxquestions.org/questions/programming-9/need-a-big-buffer-to-introduce-delay-in-a-pipe-fifo-676780/)

bwashed 10-16-2008 07:37 AM

Need a big buffer to introduce delay in a pipe. (FIFO)
 
Hi,

I've been scratching my head to try to figure out how to achieve something like the following:

Code:

some_video_output | my_big_buffer | delayed_video_output
Ideally I would be having some kind of
Code:

mkfifo --buffer=5GB
-command, where the FIFO has to be filled before data comes out at the other end.

I'm sure there is an easy way to do this, but I'm fairly new to linux and I just can't figure it out so I'd be terribly happy for some advice.

whansard 10-16-2008 09:44 AM

using && between two commands, waits for the previous command to complete successfully before starting the next.

keefaz 10-16-2008 11:40 AM

Why not just use video file, I don't see the advantage of a "buffered pipe", especially if you want to fill the buffer completly (eg, it becomes a full video file)

bwashed 10-16-2008 12:45 PM

Thanks for the replies

I'm using dvgrab to catch live video from a camcorder and rawplay to show it on screen. Eventually what I want to achieve is a setup where I can press a button (or send a network signal or sth) so that the video instantly jumps back a fixed amount of seconds (45 sec in my case). Much like a replay of a goal in a sports match.

The main problem has been to figure out how to save those 45 seconds in a proper way. That's where I thought it made sense to store in a file in a FIFO kind of way..

A mock-up way of achieving what I want is to use two terminals.
In the first terminal, issue the following command:
Code:

dvgrab -|tee temp.dv|rawplay
And then in the second terminal 45sec later:
Code:

rawplay <temp.dv
By doing that there will be two videos running, one of which is 45 sec delayed and we can easily switch between them with alt-tab. But there are of course drawbacks:
  • Both windows play the sound at the same time
  • temp.dv is constantly growing
  • There are two cpu-heavy rawplay instances at the same time.
  • I don't know how to switch between the two windows over network or from a program

bwashed 10-16-2008 12:56 PM

@keefaz: Do you mean why don't I just use a regular file instead of FIFO? If it's easier just using a regular file I don't mind that at all. I was just hoping to keep the buffer in RAM to keep diskload down and not having to worry about HD space. But not a big issue.

keefaz 10-16-2008 01:10 PM

I would search on video player side, try to find one video player that could use a large buffer
(mplayer with -rawvideo would work for watching raw video but no buffer big enough to scroll back 45sec I am afraid)

Sepero 08-08-2014 11:39 AM

Apologies for resurrecting this thread, but I was also trying to solve this problem. Here's the solution for 5 gigabyte buffer. Use the program `pv`.

Code:

some_video_output | pv -5g | delayed_video_output

sundialsvcs 08-09-2014 06:30 AM

Quote:

Originally Posted by Sepero (Post 5217635)
Apologies for resurrecting this thread ...

It's not "resurrecting a thread" if you find an important new discovery. Threads from many years past are regularly searched-for by people who are encountering problems (again) now. Thanks.

BowCatShot 08-15-2014 09:25 PM

Would something like this work?

t=$(date "+%m%d%H%M.%S" --date="now + 45 seconds")
at -t $t
at> rawplay < temp.dv
at> <EOT> #entered by pressing ctl-D

dvgrab -|tee temp.dv|rawplay

slugman 08-15-2014 09:51 PM

If I understood this correctly, you simply need to wait 45 seconds before the output temp.dv to be written, before you can re-direct temp.dv back into rawplay for input?

dvgrab -|tee temp.dv|rawplay; sleep 45 && rawplay < temp.dv

The semicolon will allow the sleep command to run concurrently with the first. The && operator will succeed after 45s and then run the next command.

I am a little unsure if this is the way you want to proceed however. I've had bad experiences of using a input file that is currently being written too. Perhaps copy it and running the 2nd command off of the copy?

And thanks Sepero and BowCatShot, I learned both the PV and AT commands!

Diego

- http://en.wikipedia.org/wiki/Tee_(command)
- http://www.tldp.org/LDP/abs/html/io-redirection.html
- http://tldp.org/LDP/abs/html/special-chars.html


All times are GMT -5. The time now is 04:49 PM.