using pipes to channel file i/o to another process

2019-02-28 08:56发布

Just started learning/using pipes and was wondering how to route file output of an application into a pipe so that another application can use it.

To be exact, I want to pipe ffmpeg's output (transcoded video data) into my application to use it. If I create a named pipe like /tmp/out.mp4 and give it to ffmpeg as output filename, ffmpeg is going to try to create this file again, probably overwriting my pipe (Or something like that). How to deal with this kind of situation?

is there any general way to divert File IO of an application transparently?

(I am trying to write a video streaming server (Just for learning and fun) which transcodes formats like avi into streaming friendly format like mpeg4 during streaming, I found ffmpeg to be too slow for this purpose, it was taking like 2 secs to transcode 1 sec video :(

Is it the problem with my setup/PC or ffmpeg is known for sluggishness? )

PS : I am writing this in C by the way.

2条回答
来,给爷笑一个
2楼-- · 2019-02-28 09:31

ffmpeg can also read from stdin and write to stdout like this:

ffmpeg -i pipe:0 -f wav pipe:1

where 0 and 1 are the standard POSIX file descriptors.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-28 09:32

ffmpeg can be persuaded to output to a pipe:

ffmpeg -i whatever.avi -f mp4 -

The "-" tells it to output to stdout instead of to a file, and the "-f" tells it what output the output file should be.

You could redirect that to a named pipe, of course, but calling it with popen to get the output as a file descriptor directly seems the way to go to me.

查看更多
登录 后发表回答