FFMPEG-Effects
view release on metacpan or search on metacpan
lib/FFMPEG/Effects.pm view on Meta::CPAN
$self->SetParams(@inputargs);
if ($self->{'debug'} != 0)
{
print("FadeIn:\n");
print Dumper($self) . "\n";
}
my $videofile=$self->{'videofile'};
my $outputfile = `basename "$videofile" 2>&1`;
chomp($outputfile);
my $size=$self->{'size'};
my $framerate=$self->{'framerate'};
my $fadeinframes=$self->{'fadeinframes'};
my $fadeoutframes=$self->{'fadeoutframes'};
my $holdframes=$self->{'holdframes'};
my $titleframes=$self->{'titleframes'};
my $color=$self->{'color'};
my $opacity=$self->{'opacity'};
my $width=$self->{'width'};
my $height=$self->{'height'};
my $DurationSecs=$self->{'DurationSecs'};
my $prec1=$self->{'prec1'};
my $prec2=$self->{'prec2'};
my $aspect=$self->{'aspect'};
my $frameno=0;
my $fade=($opacity / 100);
my $fadefactor=( ($fade / $fadeinframes) );
my $fadeval=sprintf("%.2f", $fade);
my $skipsecs=0;
my $skip=sprintf("%.2f", $skipsecs);
my $next=( 1 / $framerate);
my $nextval=sprintf("%.3f", $next);
if ($self->{'debug'} != 0)
{
print("Skip Seconds: $skip\n");
print("Next Frame At: $nextval sec.\n\n");
}
my $frameindex = $frameno;
print ("Generating $holdframes Hold Frames...\n");
for ( $frameno = 1; $frameno <= $holdframes; $frameno++)
{
$frameindex = $frameno;
my $framecount=sprintf("%05d", $frameindex);
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $videofile -r $framerate -s $size -qmin 1 -qmax 2 -g 0 -vframes 1 $outputfile-holdframe-$framecount.png 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
}
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $outputfile-holdframe-%05d.png -r $framerate -qmin 1 -qmax 2 -g 0 -vf \"color=color=$color\@$fade:size=$size [layer1]; [in][layer1] overlay=0:0\" $outputfile-hold.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $videofile -r $framerate -s $size -qmin 1 -qmax 2 -g 0 -vframes $fadeinframes $outputfile-%05d.png 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
print ("Generating FadeIn Frames...\n");
for ( $frameno = 1; $frameno <= $fadeinframes; $frameno++)
{
my $framecount=sprintf("%05d", $frameno);
$frameno=sprintf("%0"."$prec2"."d", "$frameno");
print("Frame No: $frameno\n");
$fade=($fade - $fadefactor);
if ( $frameno == $fadeinframes)
{
$fade=0;
}
$fadeval=sprintf("%.2f", $fade);
print("Opacity: $fadeval\n");
$skip=( $skip + $next );
$nextval=sprintf("%.3f", $skip);
print("Next Frame at: $nextval sec.\n\n");
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $outputfile-$framecount.png -r $framerate -vf \"color=color=$color\@$fade:size=$size [layer1]; [in][layer1] overlay=0:0\" -s $size -qmin 1 -qmax 2 -g 0 -vframes 1 $outputfile-$framecount.effect.png 2>&...
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
}
print ("Processing Effect Into Output Video: $outputfile-fadein.mpg\n");
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $outputfile-%05d.effect.png -r $framerate -qmin 1 -qmax 2 -g 0 $outputfile-effect.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -ss $skip -i $videofile -r $framerate -s $size -qmin 1 -qmax 2 -g 0 $outputfile-remainder.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
$FFCommand="ffmpeg -y -g 0 -qmin 1 -qmax 2 -r $framerate -i \"concat:$outputfile-hold.mpg|$outputfile-effect.mpg|$outputfile-remainder.mpg\" -g 0 -qmin 1 -qmax 2 -r $framerate -s $size $outputfile-fadein.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
unless ($self->{'debug'} != 0)
{
$ProcData=`rm $outputfile-holdframe-?????.png $outputfile-hold.mpg $outputfile-?????.png $outputfile-?????.effect.png $outputfile-effect.mpg $outputfile-remainder.mpg`;
}
$self->{'outputfile'} = "$outputfile-fadein.mpg";
return;
}
##### FadeOut() Fade Out From Scene To Solid Or Transparent Color.
sub FadeOut
{
my ( $self, @inputargs) = @_;
$self->SetParams(@inputargs);
if ($self->{'debug'} != 0)
{
print("FadeOut:\n");
print Dumper($self) . "\n";
}
my $videofile=$self->{'videofile'};
lib/FFMPEG/Effects.pm view on Meta::CPAN
my $fadeval=sprintf("%.2f", $fade);
my $skipsecs=( (($framerate * $DurationSecs ) - $fadeoutframes) / $framerate );
my $skip=sprintf("%.2f", $skipsecs);
my $next=( 1 / $framerate);
my $nextval=sprintf("%.3f", $skipsecs);
my $lastframetime=($skip - $next);
my $holdframe="";
my $frontframes=($framerate * $skipsecs);
my $front=sprintf("%d", $frontframes);
print ("Preparing Input File...\n");
print("Duration: $DurationSecs sec.\n");
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $videofile -r $framerate -s $size -g 0 -qmin 1 -qmax 2 -aspect:v $width:$height $outputfile-tmp.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
print ("Extracting Pre-Effect Frames...\n");
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $outputfile-tmp.mpg -r $framerate -s $size -vframes $front -g 0 -qmin 1 -qmax 2 $outputfile-front.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
print("Skipping To: $skip sec.\n");
print ("Generating Frames For FadeOut Effect...\n");
my $frameindex = $frameno;
my $framecount=sprintf("%05d", $frameindex);
for ( $frameno = 1; $frameno <= $fadeoutframes; $frameno++)
{
$frameno=sprintf("%0"."$prec2"."d", "$frameno");
print("Frame No $frameno\n");
$frameindex = $frameno;
$framecount=sprintf("%05d", $frameindex);
$fade=($fade + $fadefactor);
if ( $frameno == $fadeoutframes)
{
$fade=($opacity / 100 );
print ("Generating Hold Frames... This Frame Repeated $holdframes Times.\n");
for ( $holdframe = 1; $holdframe <= $holdframes; $holdframe++)
{
$frameindex = $holdframe;
$framecount=sprintf("%05d", $frameindex);
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -ss $skip -i $outputfile-tmp.mpg -r $framerate -vf \"color=color=$color\@$fade:size=$size [layer1]; [in][layer1] overlay=0:0\" -s $size -qmin 1 -qmax 2 -g 0 -vframes 1 $outputfile-holdframe-$framecount.p...
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
}
next;
}
$fadeval=sprintf("%.2f", $fade);
print("Opacity: $fadeval\n");
$skip=( $skip + $next );
$nextval=sprintf("%.3f", $skip);
print("Next Frame At: $nextval\n\n");
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -ss $skip -i $outputfile-tmp.mpg -r $framerate -vf \"color=color=$color\@$fade:size=$size [layer1]; [in][layer1] overlay=0:0\" -s $size -qmin 1 -qmax 2 -g 0 -vframes 1 $outputfile-effect-$framecount.png 2...
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
}
print ("Transcoding To Output File... $outputfile-fadeout.mpg\n");
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $outputfile-effect-%05d.png -r $framerate -s $size -qmin 1 -qmax 2 -g 0 $outputfile-effect.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
$FFCommand="ffmpeg -y -qmin 1 -qmax 2 -g 0 -i $outputfile-holdframe-%05d.png -r $framerate -s $size -qmin 1 -qmax 2 -g 0 $outputfile-hold.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
$FFCommand="ffmpeg -y -g 0 -qmin 1 -qmax 2 -r $framerate -i \"concat:$outputfile-front.mpg|$outputfile-effect.mpg|$outputfile-hold.mpg\" -g 0 -qmin 1 -qmax 2 -r $framerate -s $size $outputfile-fadeout.mpg 2>&1";
$ProcData=`$FFCommand`;
if ($self->{'debug'} != 0)
{
print ("Executing: $FFCommand\n");
print ("$ProcData\n");
}
unless ($self->{'debug'} != 0)
{
$ProcData=`rm $outputfile-holdframe-?????.png $outputfile-hold.mpg $outputfile-tmp.mpg $outputfile-effect-?????.png $outputfile-effect.mpg $outputfile-front.mpg`;
}
$self->{'outputfile'} = "$outputfile-fadeout.mpg";
return;
}
##### Transition() Transition Between Scenes. TBD
sub Transition
{
my ( $self, @inputargs) = @_;
$self->SetParams(@inputargs);
if ($self->{'debug'} != 0)
{
print("Transition");
print Dumper($self) . "\n";
}
}
lib/FFMPEG/Effects.pm view on Meta::CPAN
my $videofile=$self->{'videofile'};
my $size=$self->{'size'};
my $framerate=$self->{'framerate'};
my $fadeinframes=$self->{'fadeinframes'};
my $fadeoutframes=$self->{'fadeoutframes'};
my $holdframes=$self->{'holdframes'};
my $titleframes=$self->{'titleframes'};
my $color=$self->{'color'};
my $opacity=$self->{'opacity'};
my $width=$self->{'width'};
my $height=$self->{'height'};
my $DurationSecs=$self->{'DurationSecs'};
my $prec1=$self->{'prec1'};
my $prec2=$self->{'prec2'};
my $aspect=$self->{'aspect'};
my $gsize = $height . 'x' . $width;
my $frameno=0;
my $fadefactor=( ($opacity / $fadeinframes) );
my $fade=($opacity / 100);
### Here is where the main difficulty is:
### GhostScript seems to be a bit buggy when generating PNG Images.
### When a PNG Image is successfully generated, the FFMPEG
### Functions usually will work just fine.
if ( ( ! $self->{'pngfile'} ) || ( $self->{'pngfile'} eq 'none' ) )
{
$self->PSTitleFrame();
$ProcData=`gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha -g"$size" -sOutputFile=title.png Title.ps`;
}
else
{
$self->PSTitleFrame();
$ProcData=`gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha -g"$size" -sOutputFile=title.png Title.ps`;
$ProcData=`convert $self->{'pngfile'} -resize $self->{'size'}! pngfile.png`;
$ProcData=`convert pngfile.png title.png -composite -size $size composite.png`;
$ProcData=`mv composite.png title.png`;
}
my $skipsecs=0;
# print("skipsecs: $skipsecs\n");
my $skip=sprintf("%.2f", $skipsecs);
my $next=( 1 / $framerate);
# print("skip: $skip\n");
# print("nextval: $next\n");
system("convert -size $size xc:$color $color.png");
my $runtime = ($titleframes * $next);
$ProcData=`ffmpeg -y -loop 1 -f image2 -i $color.png -t $runtime $outputfile-titlesplash.background.mpg 2>&1 `;
if ($self->{'debug'} != 0)
{
print ("$ProcData\n");
}
$ProcData=`ffmpeg -y -i $outputfile-titlesplash.background.mpg -vf "movie=title.png [title]; [in][title] overlay=0:0" -qmin 1 -qmax 2 -g 0 -s $size titlesplash.mpg 2>&1 `;
if ($self->{'debug'} != 0)
{
print ("$ProcData\n");
}
$self->FadeIn("videofile=titlesplash.mpg", "size=$size", "framerate=$framerate", "color=$color", "opacity=$opacity", "fadeinframes=$fadeinframes", "fadeoutframes=$fadeoutframes", "holdframes=$holdframes", "titleframes=$titleframes" );
$self->FadeOut("videofile=titlesplash.mpg-fadein.mpg", "size=$size", "framerate=$framerate", "color=$color", "opacity=$opacity", "fadeinframes=$fadeinframes", "fadeoutframes=$fadeoutframes", "holdframes=$holdframes", "titleframes=$titleframes" );
print ("Saving Output As: $outputfile-titlesplash.mpg\n");
$ProcData=`cp $self->{'outputfile'} $outputfile-titlesplash.mpg 2>&1`;
unless ($self->{'debug'} != 0)
{
$ProcData=`rm $outputfile-titlesplash.background.mpg $color.png title.png titlesplash.mpg titlesplash.mpg-fadein.mpg titlesplash.mpg-fadein.mpg-fadeout.mpg Title.ps 2>&1`;
}
return;
}
##### PSTitleFrame() Returns PostScript Title Frame Template.
sub PSTitleFrame {
my ( $self, @inputargs) = @_;
$self->SetParams(@inputargs);
if ($self->{'debug'} != 0)
{
print("PSTitleFrame:\n");
print Dumper($self) . "\n";
}
my $height = $self->{'height'};
my $width = $self->{'width'};
my $justify = $self->{'justify'};
my $hscale = ( $height * 10 );
my $wscale = ( $width * 10 );
my $verysmallfontsize = 12;
my $smallfontsize = 18;
my $mediumfontsize = 28;
# my $largefontsize = 43;
# my $autofontsize = 310;
my $fontsize;
my $cyan = '0.7777';
my $magenta = '0.7777';
my $yellow = '0.7777';
my $black = '0.0000';
my $redline = "0.1111 0.7777 0.7777 0.0000 SET_CMYK \n";
my $blueline = "0.7777 0.7777 0.1111 0.0000 SET_CMYK \n";
my $greenline = "0.7777 0.1111 0.7777 0.0000 SET_CMYK \n";
my $cyanline = "0.7777 0.1111 0.1111 0.0000 SET_CMYK \n";
( run in 1.625 second using v1.01-cache-2.11-cpan-7fcb06a456a )