From patchwork Sun Oct 23 21:41:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 1154 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp1913983vsd; Sun, 23 Oct 2016 14:41:29 -0700 (PDT) X-Received: by 10.28.154.77 with SMTP id c74mr18691391wme.23.1477258889114; Sun, 23 Oct 2016 14:41:29 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x2si13045190wjd.77.2016.10.23.14.41.28; Sun, 23 Oct 2016 14:41:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 29B43689C88; Mon, 24 Oct 2016 00:41:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C7958689995 for ; Mon, 24 Oct 2016 00:41:16 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7A2BE100C49; Sun, 23 Oct 2016 23:41:19 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id phf3-Wsd0Xte; Sun, 23 Oct 2016 23:41:17 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 89E3CFF534; Sun, 23 Oct 2016 23:41:17 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Oct 2016 23:41:10 +0200 Message-Id: <1477258870-22625-1-git-send-email-cus@passwd.hu> X-Mailer: git-send-email 2.6.6 In-Reply-To: <20161016193722.GA44069@phare.normalesup.org> References: <20161016193722.GA44069@phare.normalesup.org> Subject: [FFmpeg-devel] [PATCHv2 1/3] tools: add loudnorm script example to use loudnorm X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Based on a patch by Kyle Swanson . Signed-off-by: Marton Balint --- tools/loudnorm.rb | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 tools/loudnorm.rb diff --git a/tools/loudnorm.rb b/tools/loudnorm.rb new file mode 100755 index 0000000..4ad374a --- /dev/null +++ b/tools/loudnorm.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env ruby + +require 'open3' +require 'json' + +ffmpeg_bin = 'ffmpeg' +target_il = -24.0 +target_lra = +11.0 +target_tp = -2.0 +samplerate = '48k' + +if ARGF.argv.count != 2 + puts "Usage: #{$PROGRAM_NAME} input.wav output.wav" + exit 1 +end + +ff_cmd = Array.new([ + ffmpeg_bin, + '-hide_banner', + '-i', ARGF.argv[0], + '-af', "loudnorm='I=#{target_il}:LRA=#{target_lra}:tp=#{target_tp}:print_format=json'", + '-f', 'null', + '-']); + +_stdin, _stdout, stderr, wait_thr = Open3.popen3(*ff_cmd) + +if wait_thr.value.success? + stats = JSON.parse(stderr.read.lines[-12, 12].join) + loudnorm_string = 'loudnorm=' + loudnorm_string += 'print_format=summary:' + loudnorm_string += 'linear=true:' + loudnorm_string += "I=#{target_il}:" + loudnorm_string += "LRA=#{target_lra}:" + loudnorm_string += "tp=#{target_tp}:" + loudnorm_string += "measured_I=#{stats['input_i']}:" + loudnorm_string += "measured_LRA=#{stats['input_lra']}:" + loudnorm_string += "measured_tp=#{stats['input_tp']}:" + loudnorm_string += "measured_thresh=#{stats['input_thresh']}:" + loudnorm_string += "offset=#{stats['target_offset']}" +else + puts stderr.read + exit 1 +end + +ff_cmd = Array.new([ + ffmpeg_bin, + '-y', '-hide_banner', + '-i', ARGF.argv[0], + '-af', loudnorm_string, + '-ar', samplerate, + ARGF.argv[1].to_s]); + +_stdin, _stdout, stderr, wait_thr = Open3.popen3(*ff_cmd) + +if wait_thr.value.success? + puts stderr.read.lines[-12, 12].join + exit 0 +else + puts stderr.read + exit 1 +end