| 1 | package Media::Info::Mediainfo; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | our $DATE = '2019-01-28'; # DATE | |||||||||||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.004'; # VERSION | |||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Capture::Tiny qw(capture); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IPC::System::Options 'system', -log=>1; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Perinci::Sub::Util qw(err); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||
| 16 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||
| 17 | 1 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||
| 18 | get_media_info | ||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||
| 21 | 1 | our %SPEC; | |||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | $SPEC{get_media_info} = { | ||||||||||||||||||||||||||||||||||||||
| 24 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||||||||
| 25 | summary => 'Return information on media file/URL, using the `mediainfo` program', | ||||||||||||||||||||||||||||||||||||||
| 26 | args => { | ||||||||||||||||||||||||||||||||||||||
| 27 | media => { | ||||||||||||||||||||||||||||||||||||||
| 28 | summary => 'Media file', | ||||||||||||||||||||||||||||||||||||||
| 29 | schema => 'str*', | ||||||||||||||||||||||||||||||||||||||
| 30 | pos => 0, | ||||||||||||||||||||||||||||||||||||||
| 31 | req => 1, | ||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||
| 34 | deps => { | ||||||||||||||||||||||||||||||||||||||
| 35 | prog => 'mediainfo', | ||||||||||||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub get_media_info { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_media_info: not called CC=27 SCAR=65.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 39 | 0 | require File::Which; | |||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | no warnings 'numeric'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | File::Which::which("mediainfo") | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 45 | or return err(412, "Can't find mediainfo in PATH"); | ||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $media = $args{media} or return err(400, "Please specify media"); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | # make sure user can't sneak in cmdline options to ffmpeg | ||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $media = "./$media" if $media =~ /\A-/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my ($stdout, $stderr, $exit) = capture { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | local $ENV{LANG} = "C"; | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | system("mediainfo", "--Language=raw", $media); | |||||||||||||||||||||||||||||||||||||
| 54 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return err(500, "Can't execute mediainfo successfully ($exit)") if $exit; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $info = {}; | |||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $cur_section; | |||||||||||||||||||||||||||||||||||||
| 60 | 0 | for my $line (split /^/, $stdout) { | |||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | next unless $line =~ /\S/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 62 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless ($line =~ /:/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $cur_section = $line; | |||||||||||||||||||||||||||||||||||||
| 65 | 0 | next; | |||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my ($key, $val) = $line =~ /(\S+.*?)\s*:\s*(\S.*)/ or next; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 68 | #say "D:section=<$cur_section> key=<$key> val=<$val>"; | ||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($cur_section eq 'General') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $info->{duration} = $1 * 3600 + $2 * 60 + $3 if $key eq 'DURATION' && $val =~ /(\d+):(\d+):(\d+\.\d+)/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "DURATION" and $val =~ /(\d+):(\d+):(\d+\.\d+)/
MC/DC0%0/2
$key eq "DURATION" and $val =~ /(\d+):(\d+):(\d+\.\d+)/
$key eq "DURATION"
$val =~ /(\d+):(\d+):(\d+\.\d+)/
Truth table0%0/3
A and B
A= $key eq "DURATION"B= $val =~ /(\d+):(\d+):(\d+\.\d+)/
| |||||||||||||||||||||||||||||||||||||||
| 71 | } elsif ($cur_section eq 'Video') { | ||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $info->{video_format} = $val if $key eq 'Format'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $info->{video_width} = $val+0 if $key eq 'Width/String'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $info->{video_height} = $val+0 if $key eq 'Height/String'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $info->{video_aspect} = $1/$2 if $key eq 'DisplayAspectRatio/String' && $val =~ /(\d+):(\d+)/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "DisplayAspectRatio/String" and $val =~ /(\d+):(\d+)/
MC/DC0%0/2
$key eq "DisplayAspectRatio/String" and $val =~ /(\d+):(\d+)/
$key eq "DisplayAspectRatio/String"
$val =~ /(\d+):(\d+)/
Truth table0%0/3
A and B
A= $key eq "DisplayAspectRatio/String"B= $val =~ /(\d+):(\d+)/
| |||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $info->{video_fps} = $val+0 if $key eq 'FrameRate/String'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $info->{rotate} = $1 if $key eq 'Rotation/String' && $val =~ /(\d+)/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$key eq "Rotation/String" and $val =~ /(\d+)/
MC/DC0%0/2
$key eq "Rotation/String" and $val =~ /(\d+)/
$key eq "Rotation/String"
$val =~ /(\d+)/
Truth table0%0/3
A and B
A= $key eq "Rotation/String"B= $val =~ /(\d+)/
| |||||||||||||||||||||||||||||||||||||||
| 78 | # XXX video_bitrate | ||||||||||||||||||||||||||||||||||||||
| 79 | } elsif ($cur_section =~ /^Audio/) { | ||||||||||||||||||||||||||||||||||||||
| 80 | # XXX handle multiple audio streams | ||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $info->{audio_format} //= $val if $key eq 'Format'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$info->{"audio_format"} //= $val
MC/DC0%0/2
$info->{"audio_format"} //= $val
$info->{"audio_format"}
$val
Truth table0%0/3
A //= B
A= $info->{"audio_format"}B= $val
| |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $info->{audio_rate} //= $1*1000 if $key eq 'SamplingRate/String' && $val =~ /(\d+(?:\.\d+)?) KHz/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$key eq "SamplingRate/String" and $val =~ /(\d+(?:\.\d+)?) KHz/
$info->{"audio_rate"} //= $1 * 1000
MC/DC0%0/2
$key eq "SamplingRate/String" and $val =~ /(\d+(?:\.\d+)?) KHz/
$key eq "SamplingRate/String"
$val =~ /(\d+(?:\.\d+)?) KHz/
MC/DC0%0/1
$info->{"audio_rate"} //= $1 * 1000
$info->{"audio_rate"}
Truth table0%0/3
A and B
A= $key eq "SamplingRate/String"B= $val =~ /(\d+(?:\.\d+)?) KHz/
Truth table0%0/2
A
A= $info->{"audio_rate"}
| |||||||||||||||||||||||||||||||||||||||
| 83 | # XXX audio_bitrate | ||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | [200, "OK", $info, {"func.raw_output"=>$stdout}]; | |||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 91 | # ABSTRACT: Return information on media file/URL, using the `mediainfo` program | ||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||||||||||||