File: mc-encode

package info (click to toggle)
libmedia-convert-perl 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,424 kB
  • sloc: perl: 2,059; makefile: 2
file content (102 lines) | stat: -rw-r--r-- 2,567 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w

=head1 NAME

mc-encode - use the Media::Convert library to transcode a file from one format to another

=head1 SYNOPSIS

mc-encode --input input.mkv --output output.webm --profile webm --multipass

=cut

use strict;
use warnings;

use Media::Convert::Asset;
use Media::Convert::Asset::ProfileFactory;
use Media::Convert::Pipe;
use File::Basename qw/dirname basename/;
use Getopt::Long;
use Data::Dumper;
use JSON::MaybeXS;

my $inputname;
my $outputname;
my $acopy = 0;
my $vcopy = 0;
my $multipass = 0;
my $profilename;

=head1 OPTIONS

=head2 B<--input>=FILE

Use C<FILE> as the input file to read video data from. Passed unmodified
to L<ffmpeg(1)>'s C<-i> parameter. No default; required.

=head2 B<--output>=FILE

Use C<FILE> as the output file to write the transcoded video to. Passed
unmodified to L<ffmpeg(1)> as the output file name. Default: the base
name (with whatever comes after the final dot, if anything, removed) of
the input file, supplemented with the default extension for the used
profile.

=head2 B<--acopy>

Enable the C<acopy> option to the L<Media::Convert::Pipe> being used,
which tells ffmpeg that it should not transcode the audio but just copy
it from one container to another, unmodified.

=head2 B<--vcopy>

Enable the C<vcopy> option to the L<Media::Convert::Pipe> being used,
which has the same effect to video that C<--acopy> has to audio.

=head2 B<--multipass>

Enable a 2-pass transcode.

=head2 B<--profile>

Select the profile to be used.

=cut

GetOptions("input=s" => \$inputname,
	   "output=s" => \$outputname,
	   "acopy" => \$acopy,
	   "vcopy" => \$vcopy,
	   "multipass" => \$multipass,
	   "profile=s" => \$profilename)
or die "Error in command line arguments";

die "need input filename!" unless defined($inputname);
die "need profile name!" unless defined($profilename);

sub progress {
	my $perc = shift;
	print "$outputname: $perc\%\r";
}

my $profiles = {};

if(exists($ENV{MC_EXTRA_PROFILES})) {
	$profiles = decode_json($ENV{MC_EXTRA_PROFILES});
}

my $input = Media::Convert::Asset->new(url => $inputname);
my $profile = Media::Convert::Asset::ProfileFactory->create($profilename, $input, $profiles);
if(!defined($outputname)) {
	$outputname = $inputname;
	$outputname =~ s/\.[^\.]*$//g;
	$outputname .= "." . $profile->exten;
}
my $output = Media::Convert::Asset->new(url => $outputname, reference => $profile);

$| = 1;

Media::Convert::Pipe->new(inputs => [$input], output => $output, acopy => $acopy, vcopy => $vcopy, multipass => $multipass, progress => \&progress)->run();

print "\n";