Hi Everybody,
My question is half about programming, half about the video structures.
I hope you can help me.
1)I want to write a program to open a .mpg file as a binary file(can any file be opend as binary file?), then packetize it (every 188 bytes should be a packet, and then zero out some packets)
I have never worked with binary files in C/C++, so I wanted to see how can I write a code to access the packets (which are blockes of 188 bytes), and zero out each of them that I want(say, in a simple scenario, every 5 packets)

2)I also wanted to know, whether these binary files have some headers, and/or I need to skip them, or I can work with them from the beginning?(Honestly, I don't expect a reply for this second section, since it is more video related than C/C++ related)

1) Google is your friend -there's lots of information out there about reading/writing files in binary mode.

2) - most any image, audio, video file has some type of formatted header. You need to look up the data for the specific file type you're dealing with.

1) Google is your friend -there's lots of information out there about reading/writing files in binary mode.

2) - most any image, audio, video file has some type of formatted header. You need to look up the data for the specific file type you're dealing with.

Hi,
Thanks for the reply.
I read some tutorials on google, so just to make sure I get it righ I have a few questions:

1) Can I store each Byte in an "int", and the block of 188 Bytes at an array of "int"s?

2)Does the method, "seekp" and "seekg", in their one parameter version, use the number of the Byte, relative to the beginning, where I want to position my "get" or "put" pointer?

3) Does the method "write", called like "blabla.write(0,1)" write one byte(the current one "put" points to) to zero?

Thanks

For bytes use char, or you could shove four bytes an int.

Are you familiar with C++ file i/o?

For bytes use char, or you could shove four bytes an int.

Are you familiar with C++ file i/o?

Hi,
Unfortunately not.
I have worked with C++, but not with its file I/O.
So you mean every Byte is stored in a "char", and a block of a88 Bytes is a string of 188 "chars".
Zeroing a byte can be done like:

char myChar = "0";
myFileHandle.write(myChar,1);

Is this correct?

And also another simple question:

I have a basic problem with file opening.
I want to open a video file "myVideo.m2v",
when I open it in the text mode:

fstream videoFile("myVideo.m2v");

It opens correctly, when I try to open in binary mode"

fstream videoFile("myVideo.m2v",ios::binary);

the check of:

if (videoFile.is_open() )

fails ,and I see it cannot open the file.
Is there anything wrong with this, shouldn't it be able to open all files in binary mode?

When reading files in binary you must specify whether you are opening it for in or out operations or both using fstream videoFile("myVideo.m2v", ios::in | ios::out | ios::binary); that would open the file for input and output in binary mode.

you use single quites for char's also is by zero'ing a byte you mean a null terminated char then it should be '\0'

Chris

When reading files in binary you must specify whether you are opening it for in or out operations or both using fstream videoFile("myVideo.m2v", ios::in | ios::out | ios::binary); that would open the file for input and output in binary mode.

you use single quites for char's also is by zero'ing a byte you mean a null terminated char then it should be '\0'

Chris

Thanks for the reply.
I solved the opening problem using your tip.
But, I just didn't get the last sentence.
You mean, I zero out each byte with something like this?

char zero = '\0';
myVideoHandle.write(zero,sizeof(char)); 
//OR myVideoHandle(zero,1); I DON'T KNOW WHICH?

Both of your examples will do the same thing as the sizeof(char) is 1.

Both of your examples will do the same thing as the sizeof(char) is 1.

And are they zeroing ONLY 1 Byte?

yes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.