Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-16-2008, 08:37 AM   #1
LQ Newbie
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
Need a big buffer to introduce delay in a pipe. (FIFO)


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

some_video_output | my_big_buffer | delayed_video_output
Ideally I would be having some kind of
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.
Old 10-16-2008, 10:44 AM   #2
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,187

Rep: Reputation: 53
using && between two commands, waits for the previous command to complete successfully before starting the next.
Old 10-16-2008, 12:40 PM   #3
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,393

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
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)
Old 10-16-2008, 01:45 PM   #4
LQ Newbie
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
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:
dvgrab -|tee temp.dv|rawplay
And then in the second terminal 45sec later:
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
Old 10-16-2008, 01:56 PM   #5
LQ Newbie
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
@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.
Old 10-16-2008, 02:10 PM   #6
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,393

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
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)
Old 08-08-2014, 12:39 PM   #7
Registered: Jul 2004
Location: Tampa, Florida, USA
Distribution: Ubuntu
Posts: 734
Blog Entries: 1

Rep: Reputation: 32
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`.

some_video_output | pv -5g | delayed_video_output
1 members found this post helpful.
Old 08-09-2014, 07:30 AM   #8
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,606
Blog Entries: 4

Rep: Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996Reputation: 2996
Originally Posted by Sepero View Post
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.
Old 08-15-2014, 10:25 PM   #9
LQ Newbie
Registered: Aug 2014
Posts: 15

Rep: Reputation: Disabled
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
1 members found this post helpful.
Old 08-15-2014, 10:51 PM   #10
Registered: Jun 2010
Location: AZ
Distribution: Slackware
Posts: 105

Rep: Reputation: 1
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!



Last edited by slugman; 08-15-2014 at 10:57 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
any way to increase CD-ROM buffer, increase spindown delay, XMMS buffer r00tb33r Linux - Hardware 5 06-12-2009 01:10 AM
LXer: Why Big Compute and Big Storage will meet Big Pipe at the Last Mile LXer Syndicated Linux News 0 12-23-2007 02:20 PM
Clonning data, fifo/pipe/tee problem : Resource temporarily unavailable rmarco Linux - General 2 05-05-2005 12:15 PM
Creating FIFO messaege buffer using shared memory indika7777 Programming 1 03-27-2004 06:14 AM
How do i change FIFO-Buffer on SuSE 7.0 ?? Problemer Linux - Networking 0 01-10-2002 09:51 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration