Running `tail -F $file` then removing outputted lines

0

Long story short; I'm running this command to stream a forever growing audio file audio.mpg into ffmpeg

tail -F audio.mp3 | ffmpeg -i - http://127.0.0.1:8090/feed1.ffm

audio.mp3 is being SSH'd from another server which has a capture device feeding the data through. This is working correctly, however audio.mp3 is constantly growing, and all I really need is to send the tail mp3 data to ffmpeg in order encode and send it to ffserver on the same machine.

Is there a command I can run to output tail -F and also remove the outputted data from audio.mp3.

In essence, I want to put a 1MB limit on the file size of audio.mp3

Thanks in advance

Moe

Posted 2013-10-15T12:49:49.200

Reputation: 389

Answers

1

It sounds like a "named pipe" problem (Sherlock Holmes, please forgive me). Since the data is not supposed to remain on your system, you should create a named pipe,

 mkfifo my_pipe

and then have the SSH process write to it, and you can read from it:

cat < my_pipe | ffmpeg -i - http://127.0.0.1:8090/feed1.ffm

When the process that writes data has completed, an EOF will appear in cat, and you will be free to stop the cat-ing by means of Ctrl+C. Of course you can also be smarter, writing a small script that waits on an EOF; as long as it does not find it, it passes the data along, when it does find the EOF, it shuts down the operation. This way you do not have to monitor the whole process.

MariusMatutiae

Posted 2013-10-15T12:49:49.200

Reputation: 41 321

1(1) Rather than cat < my_pipe | ffmpeg -i - http://127.0.0.1:8090/feed1.ffm, you could say ffmpeg -i - http://127.0.0.1:8090/feed1.ffm < my_pipe or < my_pipe ffmpeg -i - http://127.0.0.1:8090/feed1.ffm.  (2) When the process that writes data has completed, an EOF will appear in the pipe, and ffmpeg should terminate, just as it would if it were reading from an ordinary file.  You shouldn’t need Ctrl+C. – Scott – 2013-10-16T00:25:50.507

good point, ty. – MariusMatutiae – 2013-10-16T04:23:39.620

Thanks Marius, I never knew FIFO's existed, but upon searching about them, I can see how handy they can be! – Moe – 2013-10-16T12:19:59.623

They are used for inter-process communication, of which this is but a simple example. There are spiffier ones. – MariusMatutiae – 2013-10-16T12:58:15.193