| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | mc-encode - use the Media::Convert library to transcode a file from one format to another | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | mc-encode --input input.mkv --output output.webm --profile webm --multipass | ||||||||||
| 10 | |||||||||||
| 11 | =cut | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use Media::Convert::Asset; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use Media::Convert::Asset::ProfileFactory; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use Media::Convert::Pipe; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use File::Basename qw/dirname basename/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | ▶ | use Getopt::Long; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 1 | ▶ | use JSON::MaybeXS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | my $inputname; | |||||||||
| 25 | my $outputname; | ||||||||||
| 26 | 1 | my $acopy = 0; | |||||||||
| 27 | 1 | my $vcopy = 0; | |||||||||
| 28 | 1 | my $multipass = 0; | |||||||||
| 29 | 1 | my $profilename; | |||||||||
| 30 | |||||||||||
| 31 | =head1 OPTIONS | ||||||||||
| 32 | |||||||||||
| 33 | =head2 B<--input>=FILE | ||||||||||
| 34 | |||||||||||
| 35 | Use C<FILE> as the input file to read video data from. Passed unmodified | ||||||||||
| 36 | to L<ffmpeg(1)>'s C<-i> parameter. No default; required. | ||||||||||
| 37 | |||||||||||
| 38 | =head2 B<--output>=FILE | ||||||||||
| 39 | |||||||||||
| 40 | Use C<FILE> as the output file to write the transcoded video to. Passed | ||||||||||
| 41 | unmodified to L<ffmpeg(1)> as the output file name. Default: the base | ||||||||||
| 42 | name (with whatever comes after the final dot, if anything, removed) of | ||||||||||
| 43 | the input file, supplemented with the default extension for the used | ||||||||||
| 44 | profile. | ||||||||||
| 45 | |||||||||||
| 46 | =head2 B<--acopy> | ||||||||||
| 47 | |||||||||||
| 48 | Enable the C<acopy> option to the L<Media::Convert::Pipe> being used, | ||||||||||
| 49 | which tells ffmpeg that it should not transcode the audio but just copy | ||||||||||
| 50 | it from one container to another, unmodified. | ||||||||||
| 51 | |||||||||||
| 52 | =head2 B<--vcopy> | ||||||||||
| 53 | |||||||||||
| 54 | Enable the C<vcopy> option to the L<Media::Convert::Pipe> being used, | ||||||||||
| 55 | which has the same effect to video that C<--acopy> has to audio. | ||||||||||
| 56 | |||||||||||
| 57 | =head2 B<--multipass> | ||||||||||
| 58 | |||||||||||
| 59 | Enable a 2-pass transcode. | ||||||||||
| 60 | |||||||||||
| 61 | =head2 B<--profile> | ||||||||||
| 62 | |||||||||||
| 63 | Select the profile to be used. | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | GetOptions("input=s" => \$inputname, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | "output=s" => \$outputname, | ||||||||||
| 69 | "acopy" => \$acopy, | ||||||||||
| 70 | "vcopy" => \$vcopy, | ||||||||||
| 71 | "multipass" => \$multipass, | ||||||||||
| 72 | "profile=s" => \$profilename) | ||||||||||
| 73 | or die "Error in command line arguments"; | ||||||||||
| 74 | |||||||||||
| 75 | 1 | ▶ | die "need input filename!" unless defined($inputname); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 1 | ▶ | die "need profile name!" unless defined($profilename); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub progress { | ||||||||
|
Subroutine
progress: not called CC=1 SCAR=6.9
| |||||||||||
| 79 | 0 | my $perc = shift; | |||||||||
| 80 | 0 | print "$outputname: $perc\%\r"; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 1 | my $profiles = {}; | |||||||||
| 84 | |||||||||||
| 85 | 1 | ▶ | if(exists($ENV{MC_EXTRA_PROFILES})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $profiles = decode_json($ENV{MC_EXTRA_PROFILES}); | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 1 | my $input = Media::Convert::Asset->new(url => $inputname); | |||||||||
| 90 | 1 | my $profile = Media::Convert::Asset::ProfileFactory->create($profilename, $input, $profiles); | |||||||||
| 91 | 1 | ▶ | if(!defined($outputname)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | $outputname = $inputname; | |||||||||
| 93 | 0 | $outputname =~ s/\.[^\.]*$//g; | |||||||||
| 94 | 0 | $outputname .= "." . $profile->exten; | |||||||||
| 95 | } | ||||||||||
| 96 | 1 | my $output = Media::Convert::Asset->new(url => $outputname, reference => $profile); | |||||||||
| 97 | |||||||||||
| 98 | 1 | $| = 1; | |||||||||
| 99 | |||||||||||
| 100 | 1 | Media::Convert::Pipe->new(inputs => [$input], output => $output, acopy => $acopy, vcopy => $vcopy, multipass => $multipass, progress => \&progress)->run(); | |||||||||
| 101 | |||||||||||
| 102 | 0 | print "\n"; | |||||||||