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