looping .mpeg dump

1

Need to dump an MPEG2 file in a loop, either to stdout or a named pipe.

This works:

$ { while : ; do cat myLoop.mpg; done; } | vlc -

This works on a text file containing "1234\n":

$ mkfifo myPipe
$ cat test.txt > myPipe & < myPipe tee -a myPipe | cat -

(it correctly loops, outputting "1234" on every line). Why does the following NOT work?

$ cat myLoop.mpg > myPipe & < myPipe tee -a myPipe | vlc myPipe

I'm primarily interested in re-writing the first statement to remove the improper "cat myLoop.mpg" statement. Will be inputting into VLC, or into FFMPEG and then piped into VLC.

Matt Cook

Posted 2011-01-17T23:00:47.590

Reputation: 11

Please review the FAQ. This is not a forum, please use comments to reply to others, edits to update your questions and answer only for... well answers.

– BinaryMisfit – 2011-01-18T06:42:55.477

Answers

1

The last one probably doesn't work because you've got vlc reading from the named pipe instead of stdin.

See if this works:

cat myLoop.mpg > myPipe & < myPipe tee -a myPipe | vlc -

What's wrong with your first example? The curly braces aren't necessary, by the way:

while :; do cat myLoop.mpg; done | vlc -

Paused until further notice.

Posted 2011-01-17T23:00:47.590

Reputation: 86 075

Good catch. That was a typo in the post, not the problem, sadly. As you said, it should have been:

cat myLoop.mpg > myPipe & < myPipe tee -a myPipe | vlc -

I was under the impression cat was for concatenating multiple files and using it to output a single file was inefficient/hackish. Reading/writting the same pipe + tee may not be any better. Question still stands if anyone has suggestions/alternatives. – Matthew Cook – 2011-01-18T06:40:04.453

@Matt: It's a useless use of cat when you use it to pass a file to another utility via a pipe when the utility will accept a filename as an argument cat file | grep foo vs. grep foo file. It's also unnecessary to use cat in Bash to read a file into a variable: var=$(cat file) vs. var=$(<file) or to feed it into a loop cat file | while vs. while ... done < file. However, sometimes cat is exactly right. I think my revision of your first example is one of those times. It's much more straightforward than the named pipe version. – Paused until further notice. – 2011-01-18T08:23:13.130