Well, it turns out the DVD itself didn't create correctly...
The DVD authoring software I'm using is having a very hard time with the modified MPEG-2 files and refuses to work with them. I'm just going to put the all the files on a data DVD and a normal player should work with them. Windows Media Player might have problem with them but VLC should work.. I KNOW Mplayer does play them correctly.
Some modern DVD players may still play the videos directly in them despite not being an offical DVD and following the file format standards...
Tuesday, November 6, 2007
Software to make changes
Below is the PHP script I wrote in order to make the random changes based on percent. It's not perfect because it uses a random number between 1/100 and compares it with the percent chance to change.
It's not always going to change exactly the percent of the file specified but it should be very close and I'd say without a 1% margin of error.
function Modify_File($filename, $percent)
{
$size = filesize($filename);
$input_file = fopen($filename, "r");
$output_name = sprintf("%s-%03d.mpg",$filename, $percent);
$output_file = fopen($output_name, "w");
$total_changes = $size * ($percent / 100);
for ($i = 0; $i < $size; $i++)
{
$temp_value = fread($input_file, 1); // We also have to get the original value to stay in sync
if ($i < 12288) { /* We don't want to change the VERY first part of the video so we skip ahead
the number of bytes that exist in the almostempty.mpg file which happens to be
12288 bytes)
*/
fwrite($output_file, $temp_value, 1);
}
else {
$change_to_change = rand(1,100); /* Pick a random number between 1 and 100
and if it's less than or equal to our percent chance
to change then we use a random number for the byte
ELSE
we use the original byte value
*/
if ($change_to_change <= $percent)
fwrite($output_file, rand(0,255), 1);
else
fwrite($output_file, $temp_value, 1);
}
}
fclose($input_file);
fclose($output_file);
}
Modify_File("black.mpg", 1);
Modify_File("white.mpg", 1);
Modify_File("almostempty.mpg", 1);
Modify_File("test.mpg", 1);
Modify_File("black.mpg", 10);
Modify_File("white.mpg", 10);
Modify_File("almostempty.mpg", 10);
Modify_File("test.mpg", 10);
Modify_File("black.mpg", 25);
Modify_File("white.mpg", 25);
Modify_File("almostempty.mpg", 25);
Modify_File("test.mpg", 25);
Modify_File("black.mpg", 50);
Modify_File("white.mpg", 50);
Modify_File("almostempty.mpg", 50);
Modify_File("test.mpg", 50);
Modify_File("black.mpg", 75);
Modify_File("white.mpg", 75);
Modify_File("almostempty.mpg", 75);
Modify_File("test.mpg", 75);
Modify_File("black.mpg", 100);
Modify_File("white.mpg", 100);
Modify_File("almostempty.mpg", 100);
Modify_File("test.mpg", 100);
?>
It's not always going to change exactly the percent of the file specified but it should be very close and I'd say without a 1% margin of error.
function Modify_File($filename, $percent)
{
$size = filesize($filename);
$input_file = fopen($filename, "r");
$output_name = sprintf("%s-%03d.mpg",$filename, $percent);
$output_file = fopen($output_name, "w");
$total_changes = $size * ($percent / 100);
for ($i = 0; $i < $size; $i++)
{
$temp_value = fread($input_file, 1); // We also have to get the original value to stay in sync
if ($i < 12288) { /* We don't want to change the VERY first part of the video so we skip ahead
the number of bytes that exist in the almostempty.mpg file which happens to be
12288 bytes)
*/
fwrite($output_file, $temp_value, 1);
}
else {
$change_to_change = rand(1,100); /* Pick a random number between 1 and 100
and if it's less than or equal to our percent chance
to change then we use a random number for the byte
ELSE
we use the original byte value
*/
if ($change_to_change <= $percent)
fwrite($output_file, rand(0,255), 1);
else
fwrite($output_file, $temp_value, 1);
}
}
fclose($input_file);
fclose($output_file);
}
Modify_File("black.mpg", 1);
Modify_File("white.mpg", 1);
Modify_File("almostempty.mpg", 1);
Modify_File("test.mpg", 1);
Modify_File("black.mpg", 10);
Modify_File("white.mpg", 10);
Modify_File("almostempty.mpg", 10);
Modify_File("test.mpg", 10);
Modify_File("black.mpg", 25);
Modify_File("white.mpg", 25);
Modify_File("almostempty.mpg", 25);
Modify_File("test.mpg", 25);
Modify_File("black.mpg", 50);
Modify_File("white.mpg", 50);
Modify_File("almostempty.mpg", 50);
Modify_File("test.mpg", 50);
Modify_File("black.mpg", 75);
Modify_File("white.mpg", 75);
Modify_File("almostempty.mpg", 75);
Modify_File("test.mpg", 75);
Modify_File("black.mpg", 100);
Modify_File("white.mpg", 100);
Modify_File("almostempty.mpg", 100);
Modify_File("test.mpg", 100);
?>
Results
Well, the outcome is sort of what I expected.. Pretty much garbled video with no discernible shapes/objects.
I really would have liked to been able to swap out key frames but the amount of time to write such software would have been way too long for this project so I'll have to settle with random changes.
One thing I did notice is that when I manually changed things by hand there were some cases where you couldn't see ANY visible difference in the video. Either I changed dummy data (which is possible) or the MPEG2 error correction algorithms are pretty good.
They developed mathematical techniques used to predict values based on previous values in case the DVD is scratched and can't be correctly read. MPEG2 is the standard video file format for a DVD. It's pretty impressive how many changes you can make w/o changing the video.
Although 100 changes isn't much when we're talking about billions of bytes.. It's still impressive none the less.
It seems that after around 25% change the file just aborts playback after a second or so. I'm assuming this is because I've changed vital information about what image/keyframe to use next and overwrote it with garbage data.
This wouldn't be an issue if I could have wrote software to swap keyframes instead of just being forced to replace random parts of the file.
I really would have liked to been able to swap out key frames but the amount of time to write such software would have been way too long for this project so I'll have to settle with random changes.
One thing I did notice is that when I manually changed things by hand there were some cases where you couldn't see ANY visible difference in the video. Either I changed dummy data (which is possible) or the MPEG2 error correction algorithms are pretty good.
They developed mathematical techniques used to predict values based on previous values in case the DVD is scratched and can't be correctly read. MPEG2 is the standard video file format for a DVD. It's pretty impressive how many changes you can make w/o changing the video.
Although 100 changes isn't much when we're talking about billions of bytes.. It's still impressive none the less.
It seems that after around 25% change the file just aborts playback after a second or so. I'm assuming this is because I've changed vital information about what image/keyframe to use next and overwrote it with garbage data.
This wouldn't be an issue if I could have wrote software to swap keyframes instead of just being forced to replace random parts of the file.
DVD
I created my modified videos and now I intend to create a DVD with a very basic menu system
so you can easily play each video
so you can easily play each video
Encoder a no go...
Due to time constraints I've decided to just generate a few different video files and modify them in different ways.
The first is by hand I'll manually change random 100 random portions of the file and see what happens.
Next I'll write software that will randomly change 1%, 10%, 25%, 50%, 75%, and 100% of the file
The video files that I will use are as follows (All are MPEG-2 files which is the standard for DVD)
Black.mpg - 5 seconds of black
White.mpg - 4 seconds of white
test.mpg - 5 seconds of black, 5 seconds of white, 5 seconds of black, 5 seconds of white and 5 seconds of black with two dissolves between the last black/white so it fades in.
almostempty.mpg - contains a fraction of a second of black. I use this file to determine the starting point of my modifications
The first is by hand I'll manually change random 100 random portions of the file and see what happens.
Next I'll write software that will randomly change 1%, 10%, 25%, 50%, 75%, and 100% of the file
The video files that I will use are as follows (All are MPEG-2 files which is the standard for DVD)
Black.mpg - 5 seconds of black
White.mpg - 4 seconds of white
test.mpg - 5 seconds of black, 5 seconds of white, 5 seconds of black, 5 seconds of white and 5 seconds of black with two dissolves between the last black/white so it fades in.
almostempty.mpg - contains a fraction of a second of black. I use this file to determine the starting point of my modifications
Hurdle #1
Well, I wanted to find software that would allow me to completely change a keyframe w/o changing the rest of the video but it turns out nothing like this exists. I assume it doesn't exist is because swapping out a keyframe will completely destroy any images that use the keyframe as a reference.
I'm doing research on the various video file formats in an attempt to find one that is simple enough where I could write a software encoder and thus swap keyframes out myself. However it's not looking very good at this point.
I'm doing research on the various video file formats in an attempt to find one that is simple enough where I could write a software encoder and thus swap keyframes out myself. However it's not looking very good at this point.
Wednesday, October 24, 2007
Digital Video Lession #4 - Compression
There are two methods of compression lossless and lossy.
Lossless is a process in which the compressed data and be restore 100% identical to the original uncompressed data. An example being a ZIP file where you compress data to save space but when you uncompress it you need it to be exactly the same as the original files.
Lossy is different in that the compression results in a good aproximation of the original data. You can never go from a compressed file to the original as data has just been losted (deemed expendable) in the compression process.
You may be wondering why the heck you would ever use a lossy compression method when you can never revert to the original data? Well it turns out making a good lossless compression algorithm is extremely difficult and chances are you won't get much better than 2:1 ration (1meg file compressed to 1/2 a meg file) where as a lossy algorithm can have incredibly high ratios. It is not uncommon for a 50:1 ratio in video compression. Think of the previous example where an hour video took 100gigs of space. Now we can have an hour stored in 5 gigs and thus able to fit on a DVD disc. For the average person chances are if they were shown the original uncompressed directly next to the lossy compressed DVD they would not be able to tell any significant differences. This is where the advantage of lossy compression lies in extremely high ratios and being able to produce a final product that is a very good aproximation of the original.
Now, I'll present you with how "I believe" the current algorithms work in compression video images (like mpeg2/mpeg4 DVD/HDDVD) actually work.
A keyframe is the basis of a compressed video. The keyframe is a single image (of course a video normally contains thousands if not millions of keyframes) that other images can be mathmatically derived from.
Let's say you have a keyframe that contains mountains, grass, trees, sky, and clouds.
Now let's say the next frame of the video contains all the elements in the keyframe except a red house.
Well, since they're very similar we can say for this frame use the keyframe + 1 red house and now we have our image. Granted it's significantly more complicated in terms of math but that's the general idea. Find an image that is similar enough that we can mathmatically create it from a keyframe.
Lossless is a process in which the compressed data and be restore 100% identical to the original uncompressed data. An example being a ZIP file where you compress data to save space but when you uncompress it you need it to be exactly the same as the original files.
Lossy is different in that the compression results in a good aproximation of the original data. You can never go from a compressed file to the original as data has just been losted (deemed expendable) in the compression process.
You may be wondering why the heck you would ever use a lossy compression method when you can never revert to the original data? Well it turns out making a good lossless compression algorithm is extremely difficult and chances are you won't get much better than 2:1 ration (1meg file compressed to 1/2 a meg file) where as a lossy algorithm can have incredibly high ratios. It is not uncommon for a 50:1 ratio in video compression. Think of the previous example where an hour video took 100gigs of space. Now we can have an hour stored in 5 gigs and thus able to fit on a DVD disc. For the average person chances are if they were shown the original uncompressed directly next to the lossy compressed DVD they would not be able to tell any significant differences. This is where the advantage of lossy compression lies in extremely high ratios and being able to produce a final product that is a very good aproximation of the original.
Now, I'll present you with how "I believe" the current algorithms work in compression video images (like mpeg2/mpeg4 DVD/HDDVD) actually work.
A keyframe is the basis of a compressed video. The keyframe is a single image (of course a video normally contains thousands if not millions of keyframes) that other images can be mathmatically derived from.
Let's say you have a keyframe that contains mountains, grass, trees, sky, and clouds.
Now let's say the next frame of the video contains all the elements in the keyframe except a red house.
Well, since they're very similar we can say for this frame use the keyframe + 1 red house and now we have our image. Granted it's significantly more complicated in terms of math but that's the general idea. Find an image that is similar enough that we can mathmatically create it from a keyframe.
Subscribe to:
Posts (Atom)