tags:

views:

55

answers:

1

If I have an array that contains multiple FLV files like so:

my @src_files = qw (1.flv 2.flv 3.flv 4.flv 5.flv 6.flv 7.flv);

I can call flvbind.exe as an external commandline program to do the merging like so:

my $args = join(' ',@src_files);
my $dest_file = 'merged.flv';
system "flvbind $dest_file $args";

But the usage example for FLV::Splice is this:

use FLV::Splic; 
my $converter = FLV::Splice->new();
$converter->add_input('first.flv');
$converter->add_input('second.flv');
$converter->save('output.flv');

I seem to be unable to figure out how to do the same thing like the flvbind does. Do I have to verbosely add every param like so:

use FLV::Splice;

my $dest_file = 'merged.flv';
my $converter = FLV::Splice->new();
$converter->add_input('1.flv');
$converter->add_input('2.flv');
$converter->add_input('3.flv');
$converter->add_input('4.flv');
$converter->add_input('5.flv');
$converter->add_input('6.flv');
$converter->add_input('7.flv');
$converter->save("$dest_file");

This does not look like the correct way. I mean do I have to verbosely add every param? Is there a way to simplify the repeated use of the add_input method? Any pointers? Thanks like always :)

UPDATE: It turns out that this is a silly question. Thanks, @Eric for giving me the correct answer. I thought of using a for loop to reduce the repeated use of the add_input method but somehow I thought it would not work and I thought I was stuck. Well, I'll be reminding myself not to easily bother other people next time.

+3  A: 

It's fairly easy to reduce the repetition:

$converter->add_input($_) for @src_files;

Or wrap the whole thing in a subroutine:

sub flv_splice {
    my $dest_file = shift;
    my $converter = FLV::Splice->new();
    $converter->add_input($_) for @_;
    $converter->save($dest_file);
}

flv_splice 'merged.flv', @src_files;
Eric Strom
@Eric, thanks. Does this work? I thought of using for loops too. Well, I'll be giving it a test.
Mike
I can't say anything about `FLV::Splice` the module, I haven't used it (but will be giving it a try at some point, seems interesting), this is how to reduce the repetition and make it easier to use.
Eric Strom
@Eric, haha, yes, it does work! I thought of using a for loop and then somehow I thought it wouldn't work and then I thought I was stuck.
Mike