views:

58

answers:

1

The situation is this: My system (Win XP Pro) is unable to copy a huge video file (around 6 gigs) from a DVD disk, which might be defective, scratched or whatever but which can be played back with mplayer with a few frames full of mosaic though. When the copying process lasted for a certain length of time, the system would abort the effort and give me this warning "A cyclic redundancy check checksum error occurred" . And then everything copied was automatically deleted.

I'm thinking a Perl app might solve the issue. My thought is this: I copy video data one meg at a time. If a reading error ever occurs, I let perl ignore this particular one meg of data and keep copying the rest of the video still one meg at a time.

Incidentally, I've also noticed that some commercial software can do the job, but there're limitations in the trials.

The following script is what I've tried so far. It copies data one meg at a time from the defective dvd disk but it fails like Win XP. The only difference is perl doesn't delete what has already been copied. For my case, it copied around 900 megs of video data to my hard disk and this 900 megs part of the video can still be played back with mplayer. But my goal is to copy all that is good, the majority, only leaving all that is bad, the minority.

    use strict;
    use warnings;

    $/ = \1_048_576;  

    open my $in, "<", 'D:\tobecopied.mkv' or die $!;
        binmode $in;
    open my $out, ">", 'E:\copied.mkv' or die $!;
        binmode $out;

    while (<$in>) {
        print $out $_;
    }

The problem is I don't know how to achiev this. Hope someone here can give me a hint or clue. Thanks like always :)

+4  A: 

You want ddrescue, no need to reinvent that wheel badly.

readline from your program is not low-level enough, one must use sysread instead where an offset can be specified to pick up after a portion failed reading.

daxim
@daxim, thanks for the answer. So it's harder than I imagined to do the job. ddrescue seesm to be a utility designed to solve the kind of problem. It isn't Windows-friendly though. Anyway thanks for the hint and the link :)
Mike