views:

180

answers:

4

I would like to know if it is possible, using Windows and c++, to take a large video file (several gigabytes in length) and delete the first and last few hundred megabytes of it “in-place”.

The traditional approach of copying the useful data to a new file often takes upwards of 20 minutes of seemingly needless copying.

Is there anything clever that can be done low-level with the disk to make this happen?

+4  A: 

Are you hoping to just fiddle around with sector addresses in the directory entry? It's virtually inconceivable that plan would work.

First of all, it would require that the amount of data you wish to delete be exactly a sector size. That's not very likely considering that there is probably some header data at the very start that must remain there.

Even if it mets those requirements, it would take a low-level modification, which Windows tries very hard to prevent you from doing.

James Curran
"Are you hoping to just fiddle around with sector addresses in the directory entry?"Actually, yes :)Although I don't know enough about disks to know if that's even possible, hence the post here.
+5  A: 

Sure, it's possible in theory. But if your filesystem is NTFS, be prepared to spend a few months learning about all the data structures that you'll need to update. (All of which are officially undocumented BTW.)

Also, you'll need to either

  1. Somehow unmount the volume and make your changes then; or
  2. Learn how to write a kernel filesystem driver, buy a license from MS, develop the driver and use it to make changes to a live filesystem.

It's a bit easier if your filesystem is something simpler like FAT32. But either way: in short, it might be possible, but even if it is it'll take years out of your life. My advice: don't bother.

Instead, look at other ways you could solve the problem: e.g. by using an avisynth script to serve just the frames from the region you are interested in.

j_random_hacker
> officially undocumented BTWSorry, what? http://technet.microsoft.com/en-us/library/cc781134.aspx
Mark
...and if your filesystem is FAT32 then your files will be 4 GB or smaller anyway. :)
bk1e
+2  A: 

Maybe your file format allows to 'skip' the bytes, so that you could simply write over (i.e. with memory mapping) the necessary parts. This would of course still use up unnecessarily much disk space.

akauppi
+1  A: 

Even if low level filesystem operations were easy, editing a video file is not simply a matter of deleting unwanted megabytes. You still do have to consider concepts such as compression, frames, audio and video muxing, media file containers, and many others...

Your best solution is to simply accept your idle twenty minutes.

mouviciel