| 1 | package Media::Convert::Asset::Concat; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | extends 'Media::Convert::Asset'; | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Media::Convert::Asset::Concat - a Media::Convert::Asset made up of multiple assets | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | use Media::Convert::Asset; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | use Media::Convert::Asset::Concat; | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | use Media::Convert::Pipe; | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | my $file1 = Media::Convert::Asset->new(url => $input_file_1); | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | my $file2 = Media::Convert::Asset->new(url => $input_file_2); | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | my $input = Media::Convert::Asset::Concat->new(url => "/tmp/concat.txt", components => [$file1, $file2]); | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | my $output = Media::Convert::Asset->new(url => $output_file); | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | Media::Convert::Pipe->new(inputs => [$input], output => $output, vcopy => 1, acopy => 1)->run(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | The C<ffmpeg> command has a "concat" file format, selected with | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | C<-f concat>, which is essentially a text file containing a header, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | followed by a number of URLs to other files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | When C<ffmpeg> is asked to read from such a file, it will start reading | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | from the first file, and then move on to the next file when the data | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | from the first file is complete. | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | In order for this to work well, note that I<all files must be the same | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | format>, to beyond the level that C<Media::Convert::Asset> can detect. | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | It is probably not safe to use C<Media::Convert::Asset::Concat> except | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | on files that were created from the same recording. | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | Since the files I<should> be the same, C<Media::Convert::Asset::Concat> | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | assumes that they are, and will run C<ffprobe> on only the first of its | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | components when requested. | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | C<Media::Convert::Asset::Concat> supports all attributes supported by | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | L<Media::Convert::Asset> plus the following: | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | =head2 components | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | Should be an array of L<Media::Convert::Asset> objects making up the | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | contents of this asset. | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | To add more components, the C<add_component> handle exists. | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | has 'components' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | isa => 'ArrayRef[Media::Convert::Asset]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | add_component => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | has '+duration' => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | builder => '_build_duration', | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub readopts { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readopts: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if(($self->has_pass && $self->pass < 2) || !$self->has_pass) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->has_pass and $self->pass < 2 or not $self->has_pass
$self->has_pass and $self->pass < 2
MC/DC0%0/3
$self->has_pass and $self->pass < 2 or not $self->has_pass
$self->has_pass
$self->pass < 2
not $self->has_pass
Truth table0%0/5
A and B or not(C)
A= $self->has_passB= $self->pass < 2C= not $self->has_pass
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | die "refusing to overwrite file " . $self->url . "!\n" if (-f $self->url); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $content = "ffconcat version 1.0\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | foreach my $component(@{$self->components}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $input = $component->url; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $content .= "file '$input'\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | print "Writing " . $self->url . " with content:\n$content\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | open my $concat, ">", $self->url; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | print $concat $content; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | close $concat; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return ('-f', 'concat', '-safe', '0', $self->Media::Convert::Asset::readopts()); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub _build_duration { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_duration: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $rv = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | foreach my $component(@{$self->components}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $rv += $component->duration; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $rv; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | sub _probe { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_probe: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return $self->components->[0]->_get_probedata; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||