[FFmpeg-devel] [PATCH] tools: add make_chlayout_test perl script.

Nicolas George nicolas.george at normalesup.org
Mon Jul 30 13:22:06 CEST 2012


This script uses the flite source to produce files
suitable to test channels order and layout.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 tools/make_chlayout_test |  109 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100755 tools/make_chlayout_test

diff --git a/tools/make_chlayout_test b/tools/make_chlayout_test
new file mode 100755
index 0000000..d8c1b7f
--- /dev/null
+++ b/tools/make_chlayout_test
@@ -0,0 +1,109 @@
+#!/usr/bin/env perl
+
+# Copyright (c) 2012 Nicolas George
+#
+# This file is part of FFmpeg.
+#
+# FFmpeg is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# FFmpeg is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+# Produce a multichannel test file with the channels clearly identified.
+#
+# The test file can be used to check that the layout and order of channels
+# is correctly handled by a piece of software, either a part of ffmpeg or
+# not.
+#
+# Usage:
+# tools/make_chlayout_test <channels> <out options>
+#
+# <channels> is a list of channels or channel layouts, separated by '+'.
+#
+# <out options> is a list of valid ffmpeg outout options, including the
+# output file.
+#
+# Note that some output codecs or formats can not handle arbitrary channel
+# layout.
+#
+# This script requires a ffmpeg binary, either in the source tree or in the
+# search path; it must have the flite audio source enabled.
+#
+# Examples:
+#
+# Check that the speakers are correctly plugged:
+# tools/make_chlayout_test FL+FR -f alsa default
+#
+# Produce a 5.1 FLAC file:
+# tools/make_chlayout_test 5.1 surround.flac
+
+
+use strict;
+use warnings;
+
+sub usage($) {
+  my ($die) = @_;
+  my $msg = "Usage: $0 <channel> <out options>\n";
+  die $msg if $die;
+  print $msg;
+  exit 0;
+}
+
+usage 0 if @ARGV && $ARGV[0] =~ /^-+h(?:elp)?/;
+usage 1 unless @ARGV >= 2;
+
+my $channels = shift @ARGV;
+my @out_options = @ARGV;
+
+my $ffmpeg = exists $ENV{FFMPEG} ? $ENV{FFMPEG} :
+             $0 =~ /(.*)\// && -e "$1/../ffmpeg" ? "$1/../ffmpeg" :
+             "ffmpeg";
+
+my %channel_label_to_descr;
+my %layout_to_channels;
+
+{
+  open my $stderr, ">&STDERR";
+  open STDERR, ">", "/dev/null";
+  open my $f, "-|", $ffmpeg, "-channel_layouts" or die "$ffmpeg: $!\n";
+  open STDERR, ">&", $stderr;
+  while (<$f>) {
+    chomp;
+    next if /^NAME/ or /:$/ or /^$/; # skip headings
+    my ($name, $descr) = split " ", $_, 2;
+    next unless $descr;
+    if ($descr =~ /^[[:upper:]]+(?:\+[[:upper:]]+)*$/) {
+      $layout_to_channels{$name} = [ split /\+/, $descr ];
+    } else {
+      $channel_label_to_descr{$name} = $descr;
+    }
+  }
+}
+
+my @channels = map { @{$layout_to_channels{$_} // [$_]} } split /\+/, $channels;
+
+my $layout = join "+", @channels;
+my $graph = "";
+my $concat_in = "";
+for my $i (0 .. $#channels) {
+  my $label = $channels[$i];
+  my $descr = $channel_label_to_descr{$label}
+    or die "Channel $label not found\n";
+  $graph .= "flite=text='${descr}', aformat=channel_layouts=mono, " .
+            "pan=${layout}:${label}=c0 [ch$i] ;\n";
+  $concat_in .= "[ch$i] ";
+}
+$graph .= "${concat_in}concat=v=0:a=1:n=" . scalar(@channels);
+
+exec $ffmpeg, "-f", "lavfi", "-i", $graph, @out_options
+  or die "$ffmpeg: $!\n";
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list