开发者

Reroute File Output to stdout in Bash Script

I have a script, wacaw (http://webcam-tools.sourceforge.net/) that outputs video from my webcam to a file. I am trying to basically stream that to some sort of display i.e vlc, quicktime, etc to get a "mirror" type effect.

Aside from altering the source code for wacaw, is there any way to force a script's file output to stdout so I can pipe it to something like vlc? Is it even possible to stream video like that?

Thanks for your help!

UPDATE: just to clarify:

running the wacaw script is formatted as follows:

./wacaw --video --duration 5 --VGA myFile

and it outputs a file myFile.avi. If I try to do a named pipe:

mkfifo pipe
开发者_StackOverflow中文版./wacaw --video --duration 5 --VGA pipe

it outputs a file pipe.avi


You can use named pipes. You use mkfifo to create the pipe, hand that filename to the writing process and then read from that file with the other process. I have no idea if video in particular would work that way, but many other things do.


At least in bash you can do like this:

Original command:

write-to-file-command -f my-file -c

Updated command:

write-to-file-command -f >(pipe-to-command) -c

write-to-file-command will think >(pipe-to-command) is a write-only file and pipe-command will receive the file data on its stdin.

(If you just want the output to stdout you could do

write-to-file-command >(cat)

)


You may also try using tail -F myFile.avi:

# save stdout to file stdout.avi
man tail | less -p '-F option'
(rm -f myFile.avi stdout.avi; touch myFile.avi; exec tail -F myFile.avi > stdout.avi ) &
rm -f myFile.avi; wacaw --video --duration 1 --VGA myFile

md5 -q myFile.avi stdout.avi
stat -f "bytes: %z" myFile.avi stdout.avi

# pipe stdout to mplayer (didn't work for me though)
# Terminal window 1
# [mov,mp4,m4a,3gp,3g2,mj2 @ ...]moov atom not found
#rm -f myFile.avi; touch myFile.avi; tail -F myFile.avi | mplayer -cache 8192 -   
# Terminal window 2
#rm -f myFile.avi; wacaw --video --duration 1 --VGA myFile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜