-
-
Save anonymous/9d18cd2ccba26e247333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use File::Find::Rule; | |
use File::Path; | |
use File::Basename; | |
use File::Copy; | |
use POSIX; | |
use IPC::Open3; | |
sub videoInfo { | |
# ffmpeg command | |
my $ffmpeg = 'ffmpeg'; | |
my %finfo = ( | |
'duration' => "00:00:00.00", | |
'durationsecs' => "0", | |
'bitrate' => "0", | |
'vcodec' => "", | |
'vformat' => "", | |
'acodec' => "", | |
'asamplerate' => "0", | |
'achannels' => "0", | |
); | |
my $file = shift; | |
# escaping characters | |
$file =~ s/(\W)/\\$1/g; | |
open3( "</dev/null", ">/dev/null", \*ERPH, "$ffmpeg -i $file" ) or die "can't run $ffmpeg\n"; | |
my @res = <ERPH>; | |
# parse ffmpeg output | |
foreach (@res) { | |
# duration | |
if (m!Duration: ([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])!) { | |
$finfo{'duration'} = $1; | |
} | |
# bitrate | |
if (m!bitrate: (\d*) kb/s!) { | |
$finfo{'bitrate'} = $1; | |
} | |
# vcodec and vformat | |
if (/Video: (\w*), (\w*),/) { | |
$finfo{'vcodec'} = $1; | |
$finfo{'vformat'} = $2; | |
} | |
# Stream #0.1(und): Audio: aac, 48000 Hz, 1 channels, s16, 64 kb/s | |
# acodec, samplerate, stereo and audiorate | |
if (m!Audio: (\w*), (\d*) Hz, (\d*)!) { | |
$finfo{'acodec'} = $1; | |
$finfo{'asamplerate'} = $2; | |
$finfo{'achannels'} = $3; | |
} | |
} | |
my $tenths = substr( $finfo{'duration'}, 9, 2 ); | |
my $seconds = substr( $finfo{'duration'}, 6, 2 ); | |
my $minutes = substr( $finfo{'duration'}, 3, 2 ); | |
my $hours = substr( $finfo{'duration'}, 0, 2 ); | |
$finfo{'durationsecs'} = ( $tenths * .01 ) + $seconds + ( $minutes * 60 ) + ( $hours * 360 ); | |
return %finfo; | |
} | |
sub seconds_to_duration { | |
my $sec = shift; | |
$days = $sec/(24*60*60); | |
$hours = ($sec/(60*60))%24; | |
$min = ($sec/60)%60; | |
$sec = $sec%60; | |
$duration_str = sprintf("%02d", $hours) . ":" . sprintf("%02d", $min) . ":" . sprintf("%02d", $sec) ; | |
return $duration_str; | |
} | |
my $vid1 = $ARGV[0]; | |
my $delta = $ARGV[1]; | |
print $delta; | |
%vid1info = videoInfo($vid1); | |
my $vidduration = $vid1info{'durationsecs'}; | |
my($filename, $directories, $suffix) = fileparse($vid1, qr/\.[^.]*/); | |
my $success_time = 0; | |
my $thisTime = time(); | |
my $outfilename = $directories . $filename . "_" . $thisTime; | |
my $frameNow = 1; | |
open(OUTFILE, ">>$outfilename.bp"); | |
print OUTFILE $vidduration . "\n"; | |
print OUTFILE $delta . "\n"; | |
my $percentComplete = 0; | |
print `date`; | |
while($frameNow < $vidduration){ | |
my $clipFrame = "ffmpeg -ss $frameNow -i $vid1 -vframes 1 -sameq -s hd480 $outfilename.jpg 2>/dev/null "; | |
$ctmp = `$clipFrame`; | |
my $cf1 = "./drip $outfilename.jpg 15 15 15"; | |
#contains information regarding the first frame's drip | |
$cf1 = `$cf1`; | |
print OUTFILE $frameNow . ":" . $cf1 . "\n"; | |
$frameNow += $delta; | |
if(floor(($frameNow / $vidduration) * 100 ) > $percentComplete){ | |
$percentComplete = floor(($frameNow / $vidduration) * 100); | |
print $percentComplete . "\n"; | |
print `date`; | |
} | |
} | |
close OUTFILE; | |
print "Processing complete\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment