Imported Debian version 2.4.3~trusty1
[deb_ffmpeg.git] / ffmpeg / tools / make_chlayout_test
1 #!/usr/bin/env perl
2
3 # Copyright (c) 2012 Nicolas George
4 #
5 # This file is part of FFmpeg.
6 #
7 # FFmpeg is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # FFmpeg is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 # See the GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 =head1 NAME
22
23 make_chlayout_test - produce a multichannel test file with the channels
24 clearly identified
25
26 =head1 SYNOPSIS
27
28 tools/make_chlayout_test I<channels> I<out_options>
29
30 =head1 DESCRIPTION
31
32 This script uses B<ffmpeg> and B<libflite> to produce a file with audio
33 channels clearly identified by their name. The resulting file can be used to
34 check that the layout and order of channels is correctly handled by a piece
35 of software, either a part of B<FFmpeg> or not.
36
37 I<channels> is a list of channels or channel layouts, separated by '+'.
38
39 I<out_options> is a list of valid ffmpeg outout options, including the
40 output file.
41
42 Note that some output codecs or formats can not handle arbitrary channel
43 layout.
44
45 This script requires a B<ffmpeg> binary, either in the source tree or in the
46 search path; it must have the flite audio source enabled.
47
48 =head1 EXAMPLES
49
50 Check that the speakers are correctly plugged:
51
52 tools/make_chlayout_test FL+FR -f alsa default
53
54 Produce a 5.1 FLAC file:
55
56 tools/make_chlayout_test 5.1 surround.flac
57
58 =cut
59
60 use strict;
61 use warnings;
62 use Getopt::Long ":config" => "require_order";
63 use Pod::Usage;
64
65 GetOptions (
66 "help|usage|?|h" => sub { pod2usage({ -verbose => 1, -exitval => 0 }) },
67 "manpage|m" => sub { pod2usage({ -verbose => 2, -exitval => 0 }) },
68 ) and @ARGV >= 2 or pod2usage({ -verbose => 1, -exitval => 1 });
69
70 my $channels = shift @ARGV;
71 my @out_options = @ARGV;
72
73 my $ffmpeg = exists $ENV{FFMPEG} ? $ENV{FFMPEG} :
74 $0 =~ /(.*)\// && -e "$1/../ffmpeg" ? "$1/../ffmpeg" :
75 "ffmpeg";
76
77 my %channel_label_to_descr;
78 my %layout_to_channels;
79
80 {
81 open my $stderr, ">&STDERR";
82 open STDERR, ">", "/dev/null";
83 open my $f, "-|", $ffmpeg, "-layouts" or die "$ffmpeg: $!\n";
84 open STDERR, ">&", $stderr;
85 while (<$f>) {
86 chomp;
87 next if /^NAME/ or /:$/ or /^$/; # skip headings
88 my ($name, $descr) = split " ", $_, 2;
89 next unless $descr;
90 if ($descr =~ /^[[:upper:]]+(?:\+[[:upper:]]+)*$/) {
91 $layout_to_channels{$name} = [ split /\+/, $descr ];
92 } else {
93 $channel_label_to_descr{$name} = $descr;
94 }
95 }
96 }
97
98 my @channels = map { @{$layout_to_channels{$_} // [$_]} } split /\+/, $channels;
99
100 my $layout = join "+", @channels;
101 my $graph = "";
102 my $concat_in = "";
103 for my $i (0 .. $#channels) {
104 my $label = $channels[$i];
105 my $descr = $channel_label_to_descr{$label}
106 or die "Channel $label not found\n";
107 $graph .= "flite=text='${descr}', aformat=channel_layouts=mono, " .
108 "pan=${layout}:${label}=c0 [ch$i] ;\n";
109 $concat_in .= "[ch$i] ";
110 }
111 $graph .= "${concat_in}concat=v=0:a=1:n=" . scalar(@channels);
112
113 exec $ffmpeg, "-f", "lavfi", "-i", $graph, @out_options
114 or die "$ffmpeg: $!\n";