Search code examples
perlflv

How do I merge multiple FLV files using FLV::Splice module?


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.


Solution

  • 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;