Format of a .wmv file. (or any video file would be great)

1.8k Views Asked by At

I want to take a video file and "encrypt" it using java. For now encrypting is just flipping the bits. I want the video to still be able to play, so the header needs to be intact. I'm finding it very difficult to find how big the header is. I tried with a .avi file and assumed the header size with this link AVI file details but this didn't seem to work. I then eventually guessed at leaving the first 40kb (seems very large?) intact and then flipped all the bits which followed. This succeeded I guess although the video gets buggy at the end, but it's not really acceptable to guess at 40kb. I then read here that .avi files have a trailer so I have decided to avoid them for the moment to avoid this extra complication.

Could anybody tell me what the format of a .wmv file is, crucially the size of it's header. If not .wmv any popular video file would do!

Apologies if this is unclear.

4

There are 4 best solutions below

1
On BEST ANSWER

As others have noted the ASF specification fully covers the format of WMV/WMA media files. If C# is an option for you there is AsfMojo which is an ASF file parser, i.e. the header size you can easily determine using properties of the AsfFile class.

using (AsfFile asfFile = new AsfFile(@"C:\samples\sample.wmv"))
{
    uint headerSize = asfFile.PacketConfiguration.AsfHeaderSize;
}

This will not allow you to scramble the data though, as this would make the file invalid. You don't want to scramble the packets, you want to scramble individual payloads and leave everything else intact. This is usually done (as far as I am aware) by using a codec that you need licensing for, otherwise the file won't play back.

For just getting access to the payloads you could do something like this:

using (AsfFile asfFile = new AsfFile(@"C:\samples\sample.wmv"))
{
    var dataObject = asfFile.GetAsfObject<AsfDataObject>();
    foreach (var packet in dataObject.Packets)
        foreach(var payload in packet.Payload)
        {
            //do something with the payload
        }
    }
}

If you cannot use C# you can use the project at least as a guide on how to parse ASF files in general.

0
On

It's not just the header you have to worry about. A lot of videos have a 'global' header, and then each individual video frame have their own header. Not every frame in a video is equal. Some frames may be the entire image. Some frames will only be the difference from the last frame, etc...

Skipping over the global header and then encrypting the rest will still result in a totally corrupted video file, as you've mangled all the sub-header bits as well as the actual video data.

So, the big question is, why do you want to make it look like it's a video, but have garbage displayed? If you're trying to protect the content, then you'd be better off encrypting the entire file without regard to headers/content.

1
On

If you flip bits in a video file, you are likely to render it unplayable, even if you avoid the header. There is typically "meta" information scattered throughout the file. And even if you avoid that, flipping some bits is liable to interfere with the compression and cause major disruption to the picture quality.

0
On

Format of .WMV File: Advanced Systems Format (ASF) Specification.

Normally you would either encrypt whole file or fixed file size at the beginning, in case you can (and have API) to decrypt in memory or into a temporary file and play from there.

Or, you would encrypt the payload stream attaching a new/custom/private media type, so that on playback your custom handler would be invoked in order to decode/decrypt the data.