Question

I've got an application (app1.exe) that generates mpeg4 frames using ffmpeg libraries, and I want to dump these frames to another application reading from stdin.

The easiest way to connect them is via a file, and this works, but now I want to use pipes.

So in app1.exe I have

fwrite(pkt.data, 1, pkt.size, (FILE*) f ); // for each frame

which creates a test.m4v file, works OK, but when I change it to

fwrite(pkt.data, 1, pkt.size, stdout ); // for each frame

and then dump it to a file app1.exe > test.m4v the file is generated correctly, but the content is corrupted:

Generated using FILE:

generated using FILE

Generated using STDOUT:

generated using STDOUT

My first thought was to check if the application generated any stdout other than the frames, but it doesn't, checked using the FILE version and dumping stdout via app1.exe>text.txt, but the file is empty. The only "outs" are stderrs, but they only occurr when the application exits.

Opening the resulting test.m4v for both versions with notepad++ shows pretty similar data, I would even say the same in both.

So my question is, what is the difference between writing to FILE and dumping stdout to file?

Was it helpful?

Solution

Because you mention .exe, I'll guess this is on Windows. Ensure that the fopen() corresponding to the fwrite() uses binary mode, so newlines don't get mangled. For example, fopen()'s second argument should be "wb", not "w".

what's the differences between r and rb in fopen

OTHER TIPS

(I think) Windows opens stdout in ascii mode by default, and automatically converts line endings. If you set stdout to binmode, it should solve the issue.

What is the simplest way to write to stdout in binary mode?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top