3 # Copyright (c) 2012 Nicolas George
5 # This file is part of FFmpeg.
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.
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.
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
23 make_chlayout_test - produce a multichannel test file with the channels
28 tools/make_chlayout_test I<channels> I<out_options>
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.
37 I<channels> is a list of channels or channel layouts, separated by '+'.
39 I<out_options> is a list of valid ffmpeg outout options, including the
42 Note that some output codecs or formats can not handle arbitrary channel
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.
50 Check that the speakers are correctly plugged:
52 tools/make_chlayout_test FL+FR -f alsa default
54 Produce a 5.1 FLAC file:
56 tools/make_chlayout_test 5.1 surround.flac
62 use Getopt
::Long
":config" => "require_order";
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 });
70 my $channels = shift @ARGV;
71 my @out_options = @ARGV;
73 my $ffmpeg = exists $ENV{FFMPEG
} ?
$ENV{FFMPEG
} :
74 $0 =~ /(.*)\// && -e "$1/../ffmpeg" ? "$1/../ffmpeg
" :
77 my %channel_label_to_descr;
78 my %layout_to_channels;
81 open my $stderr, ">&STDERR
";
82 open STDERR, ">", "/dev/null
";
83 open my $f, "-|", $ffmpeg, "-layouts
" or die "$ffmpeg: $!\n";
84 open STDERR, ">&", $stderr;
87 next if /^NAME/ or /:$/ or /^$/; # skip headings
88 my ($name, $descr) = split " ", $_, 2;
90 if ($descr =~ /^[[:upper:]]+(?:\+[[:upper:]]+)*$/) {
91 $layout_to_channels{$name} = [ split /\+/, $descr ];
93 $channel_label_to_descr{$name} = $descr;
98 my @channels = map { @{$layout_to_channels{$_} // [$_]} } split /\+/, $channels;
100 my $layout = join "+", @channels;
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] ";
111 $graph .= "${concat_in
}concat
=v
=0:a
=1:n
=" . scalar(@channels);
113 exec $ffmpeg, "-f
", "lavfi
", "-i
", $graph, @out_options
114 or die "$ffmpeg: $!\n";