0

I have a video file, saying a mp4 file, I want to add few characters at the beginning of the file making the file cannot be played. how can I do this on Windows 7?

EDIT:

how about commands in Linux, such as dd command? I can use Linux to do this if necessary, adding few characters in and then removing them when needed.

4
  • There is no internal command for that. better option is to change the extension of the file and then explicitly open the file with any media player.
    – Zeeshan
    Commented Jul 8, 2019 at 5:10
  • I know how to change the extension but I think it is better to corrupt the file and then restore it later. Commented Jul 8, 2019 at 7:12
  • If the intended purpose is protect the file against unauthorized playback, it may be worth trying to just encrypt it with a password. Many compressors do this (without compressing anything).
    – DroidW
    Commented Jul 8, 2019 at 7:37
  • I want to corrupt and uncorrupt many files very quickly. encrypt it is a way to go but cannot do it in one batch action? Commented Jul 8, 2019 at 7:41

1 Answer 1

2

Warning:

You cannot easily undo this using CMD.exe or any other simple Windows tools.


To do, as you have actually asked, add a few characters, you can use the Windows copy command.

First, use Notepad, or some other editor, to create a file with a few characters in it. Perhaps it could be "Don't Play This!". Of course, just one space, or any other character, would be enough. Save the file using a name you want, say NoPlay.txt.

The command COPY /b NoPlay.txt+MyVideo.mp4 LockedVideo.mp4 will create the new file LockedVideo.mp4 by combining the two files NoPlay.txt and MyVideo.mp4. The /b tells copy to use binary mode, so it will not try to do anything to the files other than copy them. (Change the names to suit your files.)

Now the new file will be a "corrupted" video file, the player will detect that, and fail to play the file. It may not even recognize it as a video file at all.


As stated in the warning at the top, using Windows commands the reversal of the "corruption" is not simple. Probably not even possible with commands directly. A hex editor could be used to fix it, but that's not exactly a smooth workflow.

Using Linux, however, to reverse the corruption is almost trivial.

Taking the sample given above: Don't Play This!, there are 16 characters. How, and where, the file is created can change how real size of that file. Whether or not the file has an Enter at the end, and if it has Windows or Linux line endings matters.

In Windows, and Linux, the directory listing (DIR or ls -l) will show the real size, and you need to know that for unlocking the file. On Linux, using the echo command to create the file makes it 17 bytes in size. With the known exact size of the file you use replacing the 17 in the command below, you can unlock the video. I'll stick to using the same file names as used in the corruption process above. The obvious use of dd will work, but you won't like the speed.

dd if=dd if=LockedVideo.mp4 of=MyVideo.mp4 bs=1 skip=17

The reason for the options is that skip is the number of blocks to skip. With the default block size of 512 bytes it would remove too much, even with skip=1. Setting the block size to one, bs=1, you have complete control over the number of bytes skipped. The downside is that dd will read one block, write one block, repeat. For a 1.5 GB file, that's going to take a very long time. dd has a work around for this, iflag=skip_bytes meaning that the skip value is bytes, not blocks. With that option you can still control the number of bytes dropped, but use a larger block size. (Videos are often involved with DVDs so a block size of 4K seems reasonable.)

dd if=LockedVideo.mp4 of=MyVideo.mp4 bs=4096 iflag=skip_bytes skip=17 

A Different, All-Linux, Approach

If, as the edit to the question suggest, you're willing to use Linux for the process both ways, the whole process becomes a bit simpler, as no file is needed for the "corruption". There are two options, depending on how pressed your storage is for space. Near as I can tell there's no significant difference in speed between the options.

One option is to pad the beginning of the video file with random bytes of a full block size. A reasonable block size could be 4096, same as used for ISO files anyway.

The second option is to add a single byte to the beginning of the file. That should be enough to make it non-playable, and take the least additional space for the new file.

Option 1, full block of random bytes:

# Corrupting the video file
dd if=/dev/random of=LockedVideo.mkv bs=4096 count=1
dd if=MyVideo.mp4 of=LockedVideo.mp4 bs=4096 conv=notrunc seek=1
# Cleaning the video file for playing
dd if=LockedVideo.mp4 of=MyNewVideo.mp4 bs=4096 skip=1

Option 2, single byte added to beginning

# Corrupting the video file
dd if=MyVideo.mp4 of=LockedVideo.mp4 bs=4096 oflag=seek_bytes seek=1
# Cleaning the video file for playing
dd if=LockedVideo.mp4 of=MyNewVideo.mp4 bs=4096 iflag=skip_bytes skip=1

Last word

There is a very old implementation of dd for Windows (Win32 environment), which may, or may not, be usable now. The options and workings "appear" to match the ancient Linux version, i.e.: no iflag=skip_bytes, but the full block option above should work, if the program works. YMMV, however.

4
  • how about use Linux command to corrupt it and then restore it back? Commented Jul 8, 2019 at 7:13
  • Of course the number of characters is very important, including end-of-line marker from the "text" file, but for five characters you could use sed 's/^.\{5\}//' LockedVideo.mp4, which would, probably, uncorrupt, without renaming, LockedVideo.mp4
    – Chindraba
    Commented Jul 8, 2019 at 7:32
  • @ user686699 then how to restore MyVideo.mp4? I know I can use Linux split command. any counterpart in windows? Commented Jul 18, 2020 at 14:24
  • 1
    The new edit information should handle all the rest of your questions, and needs.
    – Chindraba
    Commented Jul 18, 2020 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .