blib/lib/Media/Convert/AccurateCut.pm

filter: Statementstmt 45.2% 33 / 73 Branchbran 0.0% 0 / 12 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 1 totaltotal 39.4% 43 / 109 CC 11 SCAR 41.9
CC
11
Cov
37%
run
119.5
_build_profile
2.0
BEGIN
1.0
CRAP 66.2
« blib/lib/Media/Convert/FfmpegInfo.pm ↑ Summary blib/lib/Media/Convert/Asset/Concat.pm »
1 package Media::Convert::AccurateCut;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Media::Convert::Asset;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Media::Convert::Asset::Concat;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Media::Convert::Asset::ProfileFactory;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Media::Convert::KeyframeFinder;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Media::Convert::Map;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Media::Convert::Pipe;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 has input => (
12 is => 'rw',
13 required => 1,
14 isa => 'Media::Convert::Asset',
15 );
16  
17 2 has output => (
18 is => 'rw',
19 required => 1,
20 isa => 'Media::Convert::Asset',
21 );
22  
23 2 has profile => (
24 is => 'rw',
25 isa => 'Media::Convert::Asset',
26 builder => '_build_profile',
27 lazy => 1,
28 );
29  
30 0 ▶sub _build_profile {
Subroutine _build_profile: not called CC=1 SCAR=6.9
31 0 my $self = shift;
32 0 my $rv = Media::Convert::Asset::ProfileFactory->create("copy", $self->input);
33 0 $rv->video_codec($self->input->video_codec);
34 0 return $rv;
35 }
36  
37 2 has start => (
38 is => 'rw',
39 isa => 'Num',
40 required => 1,
41 );
42  
43 2 has duration => (
44 is => 'rw',
45 isa => 'Num',
46 predicate => 'has_duration',
47 );
48  
49 has workdir => (
50 is => 'rw',
51 isa => 'Str',
52 2 ▶ default => $ENV{TMPDIR} // '/tmp',
Condition50%1/2
$ENV{"TMPDIR"} // "/tmp"
l!l
02
MC/DC0%0/1
$ENV{"TMPDIR"} // "/tmp"
$ENV{"TMPDIR"}
Truth table50%1/2
A
A= $ENV{"TMPDIR"}
Aresult
11
00
53 lazy => 1,
54 );
55  
56 1 ▶sub run {
Subroutine run: called CC=11 SCAR=47.8
Pod undocumented
57 1 my $self = shift;
58  
59 1 my $kfs = Media::Convert::KeyframeFinder->new(asset => $self->input)->keyframes;
60 0 my $last = 0;
61 0 my $next;
62 0 my $workdir = $self->workdir;
63 0 my $final_source;
64 KF:
65 0 foreach my $kf(@$kfs) {
66 0 $next = $kf;
67 0 ▶ last KF if $kf > $self->start;
Branch: 1 branch
BranchTrueFalseTotal
if $kf > $self->start 0 0 0
68 0 $last = $kf;
69 }
70 0 my @cleanups = ();
71 0 my $full_frame = $self->input->video_frame_length;
72 0 my $half_frame = $full_frame / 2;
73 0 ▶ if($last == $next) {
Branch: 3 branches
BranchTrueFalseTotal
if ($last == $next) { } 0 0 0
elsif ($last - $half_frame < $self->start and $last + $half_frame > $self->start) { } 0 0 0
elsif ($next - $full_frame < $self->start and $next + $half_frame > $self->start) { } 0 0 0
74 # edge case: desired cut point is after the last key frame in
75 # the file. Snap to that last key frame.
76 0 $final_source = $self->input;
77 0 $self->output->fragment_start($last);
78 ▶ } elsif(($last - $half_frame < $self->start) && $last + $half_frame > $self->start) {
Condition0%0/3
$last - $half_frame < $self->start and $last + $half_frame > $self->start
!ll&&!rl&&r
000
MC/DC0%0/2
$last - $half_frame < $self->start and $last + $half_frame > $self->start
$last - $half_frame < $self->start $last + $half_frame > $self->start
Truth table0%0/3
A and B
A= $last - $half_frame < $self->startB= $last + $half_frame > $self->start
ABresult
0X0
100
111
79 # If the previous key frame is less than half a frame
80 # before the desired start point, snap the desired start
81 # point to the previous key frame instead.
82 0 $final_source = $self->input;
83 0 $self->output->fragment_start($last);
84 ▶ } elsif(($next - $full_frame < $self->start) && $next + $half_frame > $self->start) {
Condition0%0/3
$next - $full_frame < $self->start and $next + $half_frame > $self->start
!ll&&!rl&&r
000
MC/DC0%0/2
$next - $full_frame < $self->start and $next + $half_frame > $self->start
$next - $full_frame < $self->start $next + $half_frame > $self->start
Truth table0%0/3
A and B
A= $next - $full_frame < $self->startB= $next + $half_frame > $self->start
ABresult
0X0
100
111
85 # If the next key frame is less than a full frame after
86 # the desired start point, snap the desired start point
87 # to the next key frame instead.
88 0 $final_source = $self->input;
89 0 $self->output->fragment_start($next);
90 } else {
91 0 my $tmp = Media::Convert::Asset->new(url => "$workdir/segment.mkv",
92 fragment_start => $last,
93 duration => $next - $last,
94 video_codec => "yuv4",
95 );
96 0 push @cleanups, $tmp->url;
97 0 Media::Convert::Pipe->new(inputs => [$self->input],
98 output => $tmp,
99 map => [Media::Convert::Map->new(input => $self->input, type => 'allcopy')],
100 acopy => 1,
101 )->run();
102 0 my $convert = Media::Convert::Asset->new(url => "$workdir/concat1.mkv",
103 reference => $self->profile,
104 fragment_start => $self->start - $last,
105 audio_codec => $self->input->audio_codec,
106 );
107 0 push @cleanups, $convert->url;
108 0 Media::Convert::Pipe->new(inputs => [$tmp],
109 output => $convert,
110 map => [Media::Convert::Map->new(input => $tmp, type => 'allcopy')],
111 acopy => 0,
112 )->run();
113 0 my $rest = Media::Convert::Asset->new(url => "$workdir/concat2.mkv",
114 fragment_start => $next,
115 audio_codec => 'copy',
116 );
117 0 ▶ if($self->has_duration) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_duration) 0 0 0
118 0 $rest->duration($self->duration);
119 }
120 0 push @cleanups, $rest->url;
121 0 Media::Convert::Pipe->new(inputs => [$self->input],
122 output => $rest,
123 vcopy => 1,
124 acopy => 1,
125 map => [Media::Convert::Map->new(input => $self->input, type => 'allcopy')],
126 )->run();
127 0 $final_source = Media::Convert::Asset::Concat->new(
128 url => "$workdir/concat.txt",
129 components => [$convert, $rest],
130 input_params => {fflags => "+nofillin"}
131 );
132 0 push @cleanups, $final_source->url;
133 }
134 0 ▶ if($self->has_duration) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_duration) 0 0 0
135 0 $self->output->duration($self->duration);
136 }
137 0 Media::Convert::Pipe->new(inputs => [$final_source],
138 output => $self->output,
139 map => [Media::Convert::Map->new(input => $final_source, type => "allcopy")],
140 vcopy => 1,
141 acopy => 1,
142 )->run();
143 0 foreach my $cleanup(@cleanups) {
144 0 unlink $cleanup;
145 }
146 }
147  
148 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
149  
150 2 1;
« blib/lib/Media/Convert/FfmpegInfo.pm ↑ Summary blib/lib/Media/Convert/Asset/Concat.pm »