using pipes to channel file i/o to another process

独自空忆成欢 提交于 2019-12-02 12:56:20

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5284982/using-pipes-to-channel-file-i-o-to-another-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!