| 1 | package Media::Convert::FfmpegInfo; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use MooseX::Singleton; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use SemVer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use JSON::MaybeXS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | has 'codecs' => ( | |||||||||
| 8 | is => 'ro', | ||||||||||
| 9 | isa => 'HashRef', | ||||||||||
| 10 | lazy => 1, | ||||||||||
| 11 | builder => '_build_codecs', | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | sub _build_codecs { | ||||||||
|
Subroutine
_build_codecs: called CC=14 SCAR=48.9
| |||||||||||
| 15 | 2 | local $/ = ""; | |||||||||
| 16 | 2 | open my $ffmpeg, "-|", "ffmpeg -codecs 2>/dev/null"; | |||||||||
| 17 | 2 | my $codeclist = <$ffmpeg>; | |||||||||
| 18 | 2 | close $ffmpeg; | |||||||||
| 19 | 2 | my $parsing = 0; | |||||||||
| 20 | 2 | my $rv = {}; | |||||||||
| 21 | 2 | foreach my $line(split /\n/, $codeclist) { | |||||||||
| 22 | 0 | ▶ | if(!$parsing) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | ▶ | if($line =~ /^ ---+/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | $parsing = 1; | |||||||||
| 25 | } | ||||||||||
| 26 | 0 | next; | |||||||||
| 27 | } | ||||||||||
| 28 | 0 | my ($decode, $encode, $type, $intra, $lossy, $lossless, $name, $desc) = unpack("xAAAAAAxA20xA*", $line); | |||||||||
| 29 | 0 | my $h = {}; | |||||||||
| 30 | 0 | ▶ | $h->{decode} = ($decode eq "D") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | ▶ | $h->{encode} = ($encode eq "E") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | $h->{type} = $type; | |||||||||
| 33 | 0 | ▶ | $h->{is_video} = ($type eq "V") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | ▶ | $h->{is_audio} = ($type eq "A") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | ▶ | $h->{is_subtitle} = ($type eq "S") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | $h->{is_data} = ($type eq "D") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | ▶ | $h->{is_attachment} = ($type eq "T") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | ▶ | $h->{is_intra_only} = ($intra eq "I") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | ▶ | $h->{is_lossy} = ($lossy eq "L") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | ▶ | $h->{is_lossless} = ($lossless eq "S") ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | $h->{name} = $name; | |||||||||
| 42 | 0 | $h->{description} = $desc; | |||||||||
| 43 | 0 | $rv->{$name} = $h; | |||||||||
| 44 | }; | ||||||||||
| 45 | 2 | return $rv; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | has version => ( | |||||||||
| 49 | is => 'ro', | ||||||||||
| 50 | isa => 'SemVer', | ||||||||||
| 51 | lazy => 1, | ||||||||||
| 52 | builder => '_build_version', | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub _build_version { | ||||||||
|
Subroutine
_build_version: not called CC=3 SCAR=24.8
| |||||||||||
| 56 | 0 | open my $ffprobe, "-|", "ffprobe -loglevel quiet -show_program_version -print_format json"; | |||||||||
| 57 | 0 | local $/ = undef; | |||||||||
| 58 | 0 | my $json = decode_json(<$ffprobe>); | |||||||||
| 59 | 0 | my $version = $json->{program_version}{version}; | |||||||||
| 60 | 0 | ▶ | if($version =~ /([0-9.]+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | my $ver = $1; | |||||||||
| 62 | 0 | ▶ | while(scalar(split /\./, $ver) < 3) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $ver .= ".0"; | |||||||||
| 64 | } | ||||||||||
| 65 | 0 | return SemVer->new($ver); | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | 1; | |||||||||