From patchwork Sun Nov 12 17:26:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 6015 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp1257315jah; Sun, 12 Nov 2017 09:26:28 -0800 (PST) X-Google-Smtp-Source: AGs4zMYCL8QTBlskFj/XqIK6ZtSQtpztri6BpKEQGnTHmPE/2wgpMlX6ThgdvZBfoOluRFuLT1ny X-Received: by 10.28.18.1 with SMTP id 1mr5229200wms.88.1510507588666; Sun, 12 Nov 2017 09:26:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510507588; cv=none; d=google.com; s=arc-20160816; b=nEfqXU9uIM4cze24zL+RhgYEux2FzN3hRJA3djYRAAUS0vzuLHcDqOk2uLcQxRNiUP DHVWqMbmw8ijK0AcxIfiQn0FZXcFoOWvnoBqsbhXq0QOr8rl6re/YcLVq4FtiZhFrEQw Mrc1ZzXD3j7eh5CkFrlF7e0ZKZjPfcYQQI9+ycyw1OrOCFxxnjZcw8YWiGJtYKnrbdot 4ulJBScRQTKg6fBiDbgl7bpRyieCY9vo6LYfbItAbfT/PX3EexKH+50XL63JK4ikrslN oX72OFitgwmxBR6P8yVQ3wtRNv5FACzfelLN7tqVNIrNPC0Qp7DMW5VzHKzPVUcYsW1C tMoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=rssiHgkaDrEu/9sm7APGNbHX9ph/TGuTD3jVp1GtPjk=; b=YoIxVCqumKBxlSiw/GJIcVRs9Gt7EKJC5FgVSF8X2eF3u3nDbdTz6nk2zOWc7oRN9d gyFL4XV4jRl1ShEZVFDyUS8IySuOrl2PHexock3JqxFMNz332QuRLcZCLyGBy/qJ+EpA CP3QjE7ddPxyhXHWW+oS+bc5UIVdggip3mtUpTrag1SyfYerML4cE00HPjbTSTNBc108 g/lhGr4i5HaakphJprplbh4hLvbtnjp6YffMAR6+i3KIt2HvCahrHRX77ywb3yhLhgup i/Je/6ubpJzzP/3CtirFmKjmeRUp4/T95I32Ti2XvuJ+bSLwhgFEQTjHNO+OQYDBkLJi b1jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=emh+O9Sn; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d8si668562wmi.225.2017.11.12.09.26.28; Sun, 12 Nov 2017 09:26:28 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=emh+O9Sn; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF885689D74; Sun, 12 Nov 2017 19:26:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4B1936883D4 for ; Sun, 12 Nov 2017 19:26:07 +0200 (EET) Received: by mail-wm0-f48.google.com with SMTP id b189so4155319wmd.0 for ; Sun, 12 Nov 2017 09:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=l5WAoSr1vexg8TSZY9yYtTSkaq6l3z9qdc+ZumPfcII=; b=emh+O9SnaE+nqNZbamP1XJsYg9gq5JunZsSp0tE444ZWj7y4cT/0gOPB92C24dOsMl QNJvY1kL94MKt86ePwfHzigO4Gta02wlk7mU6nyQqWq+TGtEolV7wXS9WrqQcf6zsvCq qTmeY7fjbCzDxCNJUsAQVFh4XIx7nqwF71qQV+6vbcX8thGMiywslJwPBFOc7F+wWqyS rpkEo9ibYXJYVH8Iq50w5M4wLELoXq0wFyabqunw4VbAi2EGDAzfIP/ISu5NZ4EDqMu5 p2mImUGv2oPkM3E1rVGo9GPNvXGC0UxgNh9azQVQnnT5GaEWQFVIReBwVFl2deo4kCuS ifhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=l5WAoSr1vexg8TSZY9yYtTSkaq6l3z9qdc+ZumPfcII=; b=SXdRP9Ala1TVAa17ncNFH548HHqYYcUu91bwKmqwwzweEIKahUPOIk2t0pXnRGky9Z e0G+ypk6YW4V7DgdOvJJMXd6E3jJq/CeSqYsVQJvxhn0qaxQD9+dlnFyJypvd0+3Zwwc tlq8bKq3t8LQNzbSo3mSWwQ0pbaPeimzXKDQU/2O5pl1P40jIh1EXDD25Yo6iYoSCNSW POq83Lz/CEfZjHKc8F5ThWS7GbLQ1yozR2cbJcpoY8QePHjNpo7HdkiBkQ6IzX+92dtl Bb57PFCj29L20es26mlAQYLeVZ2VDekKCKw96c5PotjArADSv30issjz9ZqQwrFDVKfK qixw== X-Gm-Message-State: AJaThX5KESHP2S+BgXjXqh4iJnNO3j0FQvH6mO1P50CxjACwGlT9Pz5N eHjSr9y2xwb/pOCFxPrsqXIkjQ== X-Received: by 10.80.162.231 with SMTP id 94mr9511872edm.280.1510507580990; Sun, 12 Nov 2017 09:26:20 -0800 (PST) Received: from [192.168.0.3] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id x49sm5262184edb.76.2017.11.12.09.26.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Nov 2017 09:26:20 -0800 (PST) To: ffmpeg-devel@ffmpeg.org References: <20171004211840.GB24666@sunshine.barsnick.net> <31846c44-6a8b-887a-8cfa-9a4e7fa07302@gmail.com> <20171109194444.GS6009@nb4> <5e88663c-bd75-75b1-3317-9e8f99d81e20@gmail.com> <20171110001236.GX6009@nb4> <7ed2b80e-1b72-5461-0050-3656e042d3f9@gmail.com> <20171111000728.GZ6009@nb4> <6111ca51-c953-284a-9d57-905bf8b5fcf1@gmail.com> <20171112160048.GQ6009@nb4> <20171112163827.GT6009@nb4> From: "pkv.stream" Message-ID: <19c44254-1279-b685-3f46-0f03b2fa7a07@gmail.com> Date: Sun, 12 Nov 2017 18:26:18 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171112163827.GT6009@nb4> Content-Language: fr X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [DEVEL][PATCH v3] ffmpeg: fix channel_layout bug on non-default layout 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Le 12/11/2017 à 5:38 PM, Michael Niedermayer a écrit : > On Sun, Nov 12, 2017 at 05:07:04PM +0100, Kv Pham wrote: >> Le 12 nov. 2017 5:01 PM, "Michael Niedermayer" a >> écrit : >> >> On Sat, Nov 11, 2017 at 02:15:25AM +0100, pkv.stream wrote: >>> Le 11/11/2017 à 1:07 AM, Michael Niedermayer a écrit : >>>> On Fri, Nov 10, 2017 at 10:27:48PM +0100, pkv.stream wrote: >>>>> Le 10/11/2017 à 1:12 AM, Michael Niedermayer a écrit : >>>>>> On Thu, Nov 09, 2017 at 09:37:33PM +0100, pkv.stream wrote: >>>>>>> Hi Michael, >>>>>>> >>>>>>>>> ffmpeg_opt.c | 11 ++++++++++- >>>>>>>>> 1 file changed, 10 insertions(+), 1 deletion(-) >>>>>>>>> 2af07f4366efdfaf1018bb2ea29be672befe0823 0001-ffmpeg-fix-channel_ >> layout-bug-on-non-default-layout.patch >>>>>>>>> From 4ec55dc88923108132307b41300a1abddf32e6f7 Mon Sep 17 00:00:00 >> 2001 >>>>>>>>> From: pkviet >>>>>>>>> Date: Mon, 2 Oct 2017 11:14:31 +0200 >>>>>>>>> Subject: [PATCH] ffmpeg: fix channel_layout bug on non-default >> layout >>>>>>>>> Fix for ticket 6706. >>>>>>>>> The -channel_layout option was not working when the channel layout >> was not >>>>>>>>> a default one (ex: for 4 channels, quad was interpreted as 4.0 >> which is >>>>>>>>> the default layout for 4 channels; or octagonal interpreted as 7.1). >>>>>>>>> This led to the spurious auto-insertion of an auto-resampler filter >>>>>>>>> remapping the channels even if input and output had identical >> channel >>>>>>>>> layouts. >>>>>>>>> The fix operates by directly calling the channel layout if defined >> in >>>>>>>>> options. If the layout is undefined, the default layout is selected >> as >>>>>>>>> before the fix. >>>>>>>>> --- >>>>>>>>> ffmpeg_opt.c | 11 ++++++++++- >>>>>>>>> 1 file changed, 10 insertions(+), 1 deletion(-) >>>>>>>>> >>>>>>>>> diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c >>>>>>>>> index 100fa76..cf5a63c 100644 >>>>>>>>> --- a/ffmpeg_opt.c >>>>>>>>> +++ b/ffmpeg_opt.c >>>>>>>>> @@ -1804,6 +1804,12 @@ static OutputStream *new_audio_stream(OptionsContext >> *o, AVFormatContext *oc, in >>>>>>>>> MATCH_PER_STREAM_OPT(audio_channels, i, >> audio_enc->channels, oc, st); >>>>>>>>> + AVDictionaryEntry *output_layout = >> av_dict_get(o->g->codec_opts, >>>>>>>>> + >> "channel_layout", >>>>>>>>> + NULL, >> AV_DICT_MATCH_CASE); >>>>>>>> This doesnt look right >>>>>>>> >>>>>>>> not an issue of the patch as such but >>>>>>>> why is the channel_layout option per file and not per stream? >>>>>>> just my ignorance; do you mean this is not the right way to retrieve >>>>>>> the channel_layout option from an audio stream ? >>>>>> I think there is more buggy with how the channel_layout is handled >>>>>> >>>>>> try this: >>>>>> ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -channel_layout 5 test.wav >>>>>> and this: >>>>>> ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -channel_layout:a 5 test.wav >>>>>> >>>>>> while it may appear that the are both working this is deceiving. >>>>>> I think only the channel number gets actually used in the 2nd case >>>>>> >>>>>> Look at what your code with av_dict_get() reads. >>>>>> It does not obtain the 5 in the 2nd case >>>>> ok I fixed that by using the flag AV_DICT_IGNORE_SUFFIX ; now >>>>> -channel_layout:a works as expected. >>>>> I fixed also all the styling issues you spotted (mixed declarations, >>>>> {} for if etc). >>>>> >>>>> Still not understanding your initial comment though : >>>>> 'why is the channel_layout option per file and not per stream?' >>>>> >>>>> do you mean o->g->codec_opts is not where I should retrieve the >>>>> channel_layout ? if not where from ? >>>>> >>>>> Thanks >>>>> >>>>>> [...] >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> ffmpeg-devel mailing list >>>>>> ffmpeg-devel@ffmpeg.org >>>>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel >>>>> ffmpeg_opt.c | 12 ++++++++++-- >>>>> 1 file changed, 10 insertions(+), 2 deletions(-) >>>>> 849898d28e989ffa5cc598c6fe4d43847b636132 0001-ffmpeg-fix-channel_ >> layout-bug-on-non-default-layout.patch >>>>> From 6d4f1c14135f9473b77e1c649d0e7bbaeba00a50 Mon Sep 17 00:00:00 2001 >>>>> From: pkviet >>>>> Date: Mon, 2 Oct 2017 11:14:31 +0200 >>>>> Subject: [PATCH] ffmpeg: fix channel_layout bug on non-default layout >>>>> >>>>> Fix for ticket 6706. >>>>> The -channel_layout option was not working when the channel layout was >> not >>>>> a default one (ex: for 4 channels, quad was interpreted as 4.0 which is >>>>> the default layout for 4 channels; or octagonal interpreted as 7.1). >>>>> This led to the spurious auto-insertion of an auto-resampler filter >>>>> remapping the channels even if input and output had identical channel >>>>> layouts. >>>>> The fix operates by directly calling the channel layout if defined in >>>>> options. If the layout is undefined, the default layout is selected as >>>>> before the fix. >>>>> --- >>>>> fftools/ffmpeg_opt.c | 12 ++++++++++-- >>>>> 1 file changed, 10 insertions(+), 2 deletions(-) >>>>> >>>>> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c >>>>> index ca6f10d..cb25d7b 100644 >>>>> --- a/fftools/ffmpeg_opt.c >>>>> +++ b/fftools/ffmpeg_opt.c >>>>> @@ -1785,6 +1785,7 @@ static OutputStream *new_audio_stream(OptionsContext >> *o, AVFormatContext *oc, in >>>>> AVStream *st; >>>>> OutputStream *ost; >>>>> AVCodecContext *audio_enc; >>>>> + AVDictionaryEntry *output_layout; >>>>> ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index); >>>>> st = ost->st; >>>>> @@ -1799,7 +1800,10 @@ static OutputStream *new_audio_stream(OptionsContext >> *o, AVFormatContext *oc, in >>>>> char *sample_fmt = NULL; >>>>> MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, >> oc, st); >>>>> - >>>>> + output_layout = av_dict_get(o->g->codec_opts,"channel_layout", >> NULL, AV_DICT_IGNORE_SUFFIX); >>>> i didnt try but i assume >>>> this would fail if there are 2 audio streams each with different >>>> layout >>> ah ok, I understand now; thanks for elaborating. >>> i tested with two output streams, it's not failing and working correctly. >>> >>> ex: ffmpeg -channel_layout octagonal -i source.wav -c:a pcm_s16le >>> -channel_layout octagonal out1.wav -c:a pcm_s16le -channel_layout >>> quad out2.wav >>> >>> (if I pick layout 0x5 as in your examples it fails because the >>> rematrix is not supported, so this is expected behavior although >>> failing; but with pan filter it eventually works) >>> >>> Tested also with two source streams used for two ouputs. Working too. >> have you tried with different layouts for each stream ? >> >> >> Yes. >> Different layouts for input streams as well as output streams. >> >> Other tests to do ? > just test with 2 streams: > > ./ffmpeg -i ~/videos/matrixbench_mpeg2.mpg -map 0:a -map 0:a -channel_layout:a:0 quad -channel_layout:a:1 5.1 -y test.nut > > av_dict_get() will likely return the same layout twice instead of the > correct layout for each stream > > [...] > ok should be fixed with this new patch version. Changed o->g->codec_opts with ost->encoder_opts Now it's working correctly with two streams. Regards > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From fb7f7f6e01cc242e13d0e640f583dffe6e7a8ada Mon Sep 17 00:00:00 2001 From: pkviet Date: Mon, 2 Oct 2017 11:14:31 +0200 Subject: [PATCH] ffmpeg: fix channel_layout bug on non-default layout Fix for ticket 6706. The -channel_layout option was not working when the channel layout was not a default one (ex: for 4 channels, quad was interpreted as 4.0 which is the default layout for 4 channels; or octagonal interpreted as 7.1). This led to the spurious auto-insertion of an auto-resampler filter remapping the channels even if input and output had identical channel layouts. The fix operates by directly calling the channel layout if defined in options. If the layout is undefined, the default layout is selected as before the fix. --- fftools/ffmpeg_opt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ca6f10d..8941d66 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1785,6 +1785,7 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in AVStream *st; OutputStream *ost; AVCodecContext *audio_enc; + AVDictionaryEntry *output_layout; ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index); st = ost->st; @@ -1799,7 +1800,10 @@ static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, in char *sample_fmt = NULL; MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st); - + output_layout = av_dict_get(ost->encoder_opts,"channel_layout", NULL, AV_DICT_IGNORE_SUFFIX); + if (output_layout) { + audio_enc->channel_layout = strtoull(output_layout->value, NULL, 10); + } MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st); if (sample_fmt && (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) { @@ -2523,7 +2527,11 @@ loop_end: (count + 1) * sizeof(*f->sample_rates)); } if (ost->enc_ctx->channels) { - f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels); + if (ost->enc_ctx->channel_layout) { + f->channel_layout = ost->enc_ctx->channel_layout; + } else { + f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels); + } } else if (ost->enc->channel_layouts) { count = 0; while (ost->enc->channel_layouts[count])