#!/usr/bin/perl -w

package main;

use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use English qw(-no_match_vars);
use FLV::FromSWF;

our $VERSION = '0.03';

my %opts = (
   skipframes => 1,
   verbose    => 0,
   help       => 0,
   version    => 0,
);

Getopt::Long::Configure('bundling');
GetOptions('s|skipframes=i' => \$opts{skipframes},
           'v|verbose'      => \$opts{verbose},
           'h|help'         => \$opts{help},
           'V|version'      => \$opts{version},
           ) or pod2usage(1);
if ($opts{help})
{
   pod2usage(-exitstatus => 0, -verbose => 2);
}
if ($opts{version})
{
   print "v$VERSION\n";
   exit 0;
}

if (@ARGV < 2)
{
   pod2usage(1);
}

my $infile = shift;
my $outfile = shift;

my $converter = FLV::FromSWF->new();
$converter->{audio_skipframes} = $opts{skipframes};
$converter->parse_swf($infile);
$converter->save($outfile);

__END__

=for stopwords SWF FLV MX swf2flv file.swf file.flv transcode

=head1 NAME

swf2flv - Transform a video SWF into an FLV

=head1 SYNOPSIS

swf2flv [options] file.swf file.flv

 Options:
   -s --skipframes=n   How many blank frames are expected at the beginning of the video
                       Defaults to 1, which is appropriate for On2 Flix output.
   -v --verbose        Print diagnostic messages
   -h --help           Verbose help message
   -V --version        Print version

=head1 DESCRIPTION

With respect to video and audio content, FLV and SWF files have very
similar data inside, and differ primarily in metadata.  Very roughly,
one can think of an FLV file as a subset of a SWF file.

Therefore, one can easily transcode from SWF to FLV and back without
much work apart from fiddling with headers and the like.

=head1 CAVEATS AND LIMITATIONS

C<flv2swf> does not yet exist...

Supports Flash MX video (that is, Sorenson H.263).  Does not support Flash 8
video (that is, On2 VP6).  Flash screen video is untested but might
work.

Supports MP3 audio.  Other audio formats are untested but might work.

Does not support multiple video or audio streams in the same file.

Does not emit C<videobitrate> and C<audiobitrate> in the meta tag.

Emits Greenwich time in the C<creationdate> meta tag, not local time.

=head1 SEE ALSO

FLV::FromSWF

FLV::ToSWF (does not yet exist...)

=head1 AUTHOR

Clotho Advanced Media Inc., I<cpan@clotho.com>

Primary Developer: Chris Dolan

=cut
