Log in

View Full Version : [C/C++] How do I pipe data to x264?


SledgeHammer_999
26th December 2009, 20:16
Hi, I am a C++ hobbyist and I have done a number of applications for my personal use. Most of them just use libraries(gtkmm and gstreamer in particular). As of late I had a question pop up in my head. How someone launches a second program from another program and pipe data into it?

I use linux obviously. I have figured out that I need to use fork() to launch another process. My problem is, how do I feed data to x264 afterwards?
I just want to do an experiment. First, test the decoding efficiency of gstreamer, second test the efficiency of x264 under 64bit linux compared to 32bit winxp. I know that the results aren't scientific because the decoding process is entirely different(and I suspect gstreamer will be worse than avisynth). I did some research on the gstreamer side and I found out that I can use the appsink element and have access to a data buffer that arrives on the element. From there I have 2 questions:
1.How do I pipe the data to x264(using the data pointer)?
2.What happens if I pipe more data(frames) than x264 can handle(encode)?

I am a total noob on the subject, so I may have some concepts wrong. Thanks for your time...

LoRd_MuldeR
26th December 2009, 20:26
Maybe this can help you:
http://code.google.com/p/mulder/source/browse/trunk/Utils/pipebuf/pipebuf.dpr

That's the source code of my "pipebuf" utility. It's not C/C++ but Pascal, however it should contain all the info you need.
It's mainly a wrapper around the required Win32 API calls to create two processes and connect them with a pipe.
On Linux you will have the use the equivalent POSIX API calls, I guess. But the basic idea should be very similar, I think.

[EDIT]

This should help for a Linux implementation:
http://linux.die.net/man/2/pipe

SledgeHammer_999
27th December 2009, 17:18
Thanks for the info Lord_Mulder. I did understand how pipes work on linux(and their really cool lol), but how do I make x264 read from a pipe? (I have no intention of messing with the source code).

Dark Shikari
27th December 2009, 18:23
Pass the input filename as "-" and specify your input format with --stdin.

LoRd_MuldeR
27th December 2009, 19:41
Also I think you'll need dup2() to connect/replace the STDIN of the forked process (x264 in this case) with the "read" end of your pipe:
http://codewiki.wikidot.com/c:system-calls:dup2

SledgeHammer_999
28th December 2009, 12:31
hmmm interesting... I'll try to code something after the holidays.