-
Notifications
You must be signed in to change notification settings - Fork 0
/
vinfo
executable file
·104 lines (100 loc) · 2.76 KB
/
vinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl -s
sub dbg(@) {
print "## @_\n" if $v;
}
# total duration in seconds
my $totalDuration=0;
my $verbose = $q ? 1 : 0;
my $showOnlyVertical = 0;
$showOnlyVertical = 1 if $x;
my $showAbbreviated = 0;
$showAbbreviated = 1 if $e;
if(scalar @ARGV == 0) {
push(@ARGV, <*.m??>);
push(@ARGV, <*.webm>);
@ARGV = sort @ARGV;
}
my @files = @ARGV;
foreach my $vid (@ARGV) {
if(-d $vid) {
push @ARGV, <"${vid}"/*.m??>;
push @ARGV, <"${vid}"/*.webm>;
@ARGV = sort @ARGV;
next;
}
dbg "# vid=$vid\n";
next unless $vid =~ /\.(mpg|mpeg|mkv|mov|mp4|m4v|flv|webm|rm|wmv|avi|asf|mp3|m4a|ogg|)$/i;
open(FFMPEG, "ffmpeg -hide_banner -i \"$vid\" 2>&1 |") || die "${0}: can't read \"$vid\": $!\n";
my $duration="";
my $bitrate="";
my $milliseconds=0;
while(<FFMPEG>) {
chomp;
dbg "line: $_";
# get rid of an parenthesized stuff that might have commas
s/ *\([^)]*\)//g;
if(m#Duration: (\d\d):(\d\d):([\d.]+).*bitrate: (\d+ [a-z/]+)#) {
my $hours = $1;
my $minutes = $2;
my $seconds = $3;
my $h=sprintf("%dh", ${hours});
my $m="${minutes}m";
my $s="${seconds}s";
$totalDuration += ${seconds} + 60*${minutes} + 3600*${hours};
if($h eq "0h") {
$h="";
$m=sprintf("%dm", ${minutes});
if($m eq "0m") {
$m="";
$s=sprintf("%ds", ${seconds});
}
}
$duration="$h$m$s";
$milliseconds=($seconds + $minutes*60 + $hours*3600)* 1000;
$bitrate=$4;
}
# Video: hevc (Main), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn (default)
if(m#Video: ([^,]*), ([^,]*), (\d+)x(\d+)[^,]*,.* ([^,]* fps), ([^,]*), ([^,]*)#) {
dbg "video - $1 - $2 - $3 - $4 - $5 - $6\n";
# note: above regexp uses commas to delineate
if($showAbbreviated) {
printf("%d %s\n", ($milliseconds+500)/1000, $q ? "" : " $vid")
} else {
if($showOnlyVertical) {
printf("%13s %d ms %d s %12s %6sp $5 $1 \"%s\"\n", $duration, $milliseconds, $milliseconds/1000, $bitrate, $4, $vid)
} else {
printf("%13s %d ms %d s %12s %9s $5 $1 \"%s\"\n", $duration, $milliseconds, $milliseconds/1000, $bitrate, "${4}x${3}", $vid)
}
}
last;
}
if(m#(Audio|Stream)#) {
print "$_, Duration: $duration\n";
}
}
}
unless($showAbbreviated) {
my $hours="";
my $minutes="";
my $totalSeconds = int $totalDuration + 0.5;
if($totalDuration > 60) {
if($totalDuration > 3600) {
my $h = int($totalDuration/3600);
$hours = sprintf("%dh", $h);
$totalDuration -= $h*3600;
}
my $m=int($totalDuration/60);
$minutes = sprintf("%dm", $m);
$totalDuration -= $m*60;
}
my $seconds=sprintf("%04.2fs", $totalDuration);
if($q) {
if($d) {
print "${totalSeconds}\n";
} else {
print "${hours}${minutes}${seconds}\n";
}
} elsif($t) {
print "Total duration: ${hours}${minutes}${seconds}\n\n";
}
}