View Single Post
Old January 6th, 2017, 03:24 PM   #4
retroanalyst
in memoriam Max
 
retroanalyst's Avatar
 
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 121,979
Thanked 47,461 Times in 3,337 Posts
retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+retroanalyst 175000+
Default

Quote:
Originally Posted by bladess View Post
I've been trying to use your code to extract a few Digital Red avi s myself, but it only starts to decode the file, and after 20-50 kB of data it terminates (I have avi files ranging from 5MB to 100 MB).

Did you come across this kind of a problem?
(I was compiling your code under Win with minGW and also with Visual Studio 2015 without success, and I've started to wonder if the EOF is interpreted differently here than in Linux. )
Indeed, this is the problem. By default, the stdio functions in Windows compilers convert "\n" to "\r\n" on write, since the latter (carriage return + linefeed) is what Windows uses to separate lines in text files.

Of course this treatment corrupts binary files, but there is a solution: you can force binary I/O with the _setmode() function in MinGW, like so:

Code:
#include <fcntl.h>
_setmode(_fileno(stdin),_O_BINARY);
_setmode(_fileno(stdout),_O_BINARY);
See http://www.willus.com/mingw/_binary.shtml.
retroanalyst is offline   Reply With Quote
The Following 7 Users Say Thank You to retroanalyst For This Useful Post: