-1

Can anyone suggest to me how to read a video file from Perl without using any third-party tools?

I know the opencv library for Python and C. I am not sure which one to use for Perl.

UPDATE

I get the output as

3 bytes read

´ˇÙ

Argument "M-+M-^?M-t" isn't numeric in bitwise and (&) at

0

I am novice in perl and I am missing something. I am reading 3 bytes from the file till EOF. I want to mask it and do some manipulation on the bits. I am reading pack/unpack it really doesn't make a clue to me.

open (FILE, "<:raw", $InputFile) or die "Couldn't open";
my ($buf, $data, $n); 

while (($n = read FILE, $data, 3) != 0) { 
    print "$n bytes read\n"; 
    $buf = $data; 
    print $buf . "\n";
    my $maskNumber = 0x4;
    my $value = ($buf & $maskNumber);
    print $value . "\n";
}
Neil Slater
  • 26,512
  • 6
  • 76
  • 94
Azzi
  • 1
  • 3
  • 1
    you could try the FFmpeg cpan module: http://search.cpan.org/~allenday/FFmpeg-6036/FFmpeg.pm – gatinueta Nov 09 '13 at 19:48
  • Please read http://stackoverflow.com/help/on-topic - "Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow". In addition, I cannot understand - what is your definition of a "without using third party tools" that includes using opencv? There *is* an opencv binding for Perl: http://search.cpan.org/~yuta/Cv-0.12/lib/Cv.pm - I don't know much about it though. – Neil Slater Nov 09 '13 at 19:55
  • There is `open my $fh, '<:raw', 'video_file'`. What do you want to do with this file once you have read it? – Borodin Nov 09 '13 at 21:50
  • Hi Borodin, I want to read the in bytes and want to switch few bits in it. I am trying to convert the i420 format any raw video file to NV12. without using FFmpeg – Azzi Nov 10 '13 at 00:05
  • @Azzi: That helps, thanks. I re-formatted the code with a more conventional indentation, I find it slightly easier to read like that. As per your other question, details of `I420` format will become relevant too. It's a pixel format, not a file format, so you need to give more information. Probably you should start just being able to read and write the single format rather than go straight for a conversion that you do not fully understand - how are you testing the video (e.g. how do you know input video is valid)? – Neil Slater Nov 10 '13 at 10:28

1 Answers1

1

Perl's bit operators have string modes and numeric modes; if either parameter is a number, the numeric mode is used.

So I suspect you want something like:

$buf & "\0\0\4"
ysth
  • 96,171
  • 6
  • 121
  • 214