From patchwork Sat Sep 23 21:02:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 43882 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:2a18:b0:15d:8365:d4b8 with SMTP id e24csp395545pzh; Sat, 23 Sep 2023 14:02:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuE41Fu0A0eDJcuu8mmtzpKDE/g2Z5O9G9T1SxSuVu3gOOPImdjz27Fm8kwQjWtU74VM46 X-Received: by 2002:a05:600c:2489:b0:3fb:b248:67c with SMTP id 9-20020a05600c248900b003fbb248067cmr2612942wms.22.1695502942804; Sat, 23 Sep 2023 14:02:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695502942; cv=none; d=google.com; s=arc-20160816; b=HLG0TnYgHh4t7e51XD8nDtmlke6MPOZMs/ZzaZUcIq6JRBjm7VnpdFNJbZGjmEGlcU 9oOsmyLKfilyvBgAxllySKp1fGN/JWeCBS0ulQ9ROd3VFs4dRqZ4w9eePwkgnNXtms0b a3VEaaduGJfFZvJ+0dCTz1sQpA4fKIzAh2QA1sJxrSwjpERxoVQ/58Akcby6s2gMlYt9 q/0odInat53sCAIk3vhFxK30WEXceSsG/FGE7wk6OimloDb7O+UdsDBaTLzNOcXkG+0i LlK1yU0ZvRwP/Q2/V9M5d6N0uBwwU+/rk7XGgQoRGo0WIjF15pjVDLgjr/P/PF1jnNLw yhFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=/wDYMg+7nYrwXxQg/P0Lr16fhiLlQbqew+lCZ1J8mUc=; fh=jVfZMLWnLI+bakVFfbrZwhq45mnB0EcYmqPCZWdiETs=; b=PTnmpXpPbAc9Ob/11MH1v49AP/cBDDadufSsS678o/kAv14hCtDc08GdXquPWIV8LI pa2ngcXqKxySRmeet4Hm1zYt1wfwnesU9S29v42kbc7f83Sfr4Z98Rt2aBEYwZl80M5i cx0GidqlmsfeDCSC4QJCIBvU4+5FR8Q0GU575CkPya8t74BMOM3f0j9tWwkUYyqHQRXy Zk/AVAtAlclj3HBr25YQr4yVpTMJcgR8TNK+u7ZM8lqsoNKMq3kFHuqMncc3Nk/3zHJv 9kfv6NWHwV81Vq+f5Ffz20I9gE0j6gzqRdgOqqqyKoAf1+tuboMbFjjz3if7DaMYacVG 2J2Q== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y14-20020aa7d50e000000b0052e9a08ef08si6139479edq.519.2023.09.23.14.02.22; Sat, 23 Sep 2023 14:02:22 -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 94B9B68C9F6; Sun, 24 Sep 2023 00:02:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DCB5568B88E for ; Sun, 24 Sep 2023 00:02:11 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id D4551FF803; Sat, 23 Sep 2023 21:02:10 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 23 Sep 2023 23:02:10 +0200 Message-Id: <20230923210210.3830-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH] libswresample/swresample: avoid s16p internal transfer format X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Paul B Mahol MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: crUqdpc9MQln From: Paul B Mahol Instead use float one by default for sample rate conversions. The s16p internal transfer format produces visible and hearable quantization artifacts. Signed-off-by: Paul B Mahol for S8 we continue to use S16 as it should have enough precision Fate is adjusted so bitexactness is maintained between mips/arm/x86 if more tests became bit-inexact on some platform, the same change can be done to them The use of higher precision and float intermediates inevitably leads to more differences between platforms. Signed-off-by: Michael Niedermayer --- libswresample/swresample.c | 8 +++++++- tests/fate/acodec.mak | 8 ++++---- tests/fate/lavf-container.mak | 16 ++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libswresample/swresample.c b/libswresample/swresample.c index fb3d7bccbf1..f2a9b404743 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -331,8 +331,14 @@ av_cold int swr_init(struct SwrContext *s){ s->rematrix_custom; if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){ + // 16bit or less to 16bit or less with the same sample rate if( av_get_bytes_per_sample(s-> in_sample_fmt) <= 2 - && av_get_bytes_per_sample(s->out_sample_fmt) <= 2){ + && av_get_bytes_per_sample(s->out_sample_fmt) <= 2 + && s->out_sample_rate==s->in_sample_rate) { + s->int_sample_fmt= AV_SAMPLE_FMT_S16P; + // 8 -> 8, 16->8, 8->16bit + } else if( av_get_bytes_per_sample(s-> in_sample_fmt) + +av_get_bytes_per_sample(s->out_sample_fmt) <= 3 ) { s->int_sample_fmt= AV_SAMPLE_FMT_S16P; }else if( av_get_bytes_per_sample(s-> in_sample_fmt) <= 2 && !s->rematrix diff --git a/tests/fate/acodec.mak b/tests/fate/acodec.mak index b15b1dcc205..7b09e3bd63d 100644 --- a/tests/fate/acodec.mak +++ b/tests/fate/acodec.mak @@ -156,14 +156,14 @@ fate-acodec-ra144: CMP_SHIFT = -320 FATE_ACODEC-$(call ENCDEC, ROQ_DPCM, ROQ, ARESAMPLE_FILTER) += fate-acodec-roqaudio fate-acodec-roqaudio: FMT = roq fate-acodec-roqaudio: CODEC = roq_dpcm -fate-acodec-roqaudio: ENCOPTS = -ar 22050 -fate-acodec-roqaudio: DECOPTS = -ar 44100 +fate-acodec-roqaudio: ENCOPTS = -af aresample=22050:tsf=s16p +fate-acodec-roqaudio: DECOPTS = -af aresample=44100:tsf=s16p FATE_ACODEC-$(call ENCDEC, S302M, MPEGTS, ARESAMPLE_FILTER) += fate-acodec-s302m fate-acodec-s302m: FMT = mpegts fate-acodec-s302m: CODEC = s302m -fate-acodec-s302m: ENCOPTS = -ar 48000 -strict -2 -fate-acodec-s302m: DECOPTS = -ar 44100 +fate-acodec-s302m: ENCOPTS = -af aresample=48000:tsf=s16p -strict -2 +fate-acodec-s302m: DECOPTS = -af aresample=44100:tsf=s16p FATE_ACODEC-$(call ENCDEC, WAVPACK, WV, ARESAMPLE_FILTER) += fate-acodec-wavpack fate-acodec-wavpack: FMT = wv diff --git a/tests/fate/lavf-container.mak b/tests/fate/lavf-container.mak index d4a0ac7510f..69330ae3b6f 100644 --- a/tests/fate/lavf-container.mak +++ b/tests/fate/lavf-container.mak @@ -39,13 +39,13 @@ $(FATE_LAVF_CONTAINER): $(AREF) $(VREF) fate-lavf-asf: CMD = lavf_container "" "-c:a mp2 -ar 44100" "-r 25" fate-lavf-avi fate-lavf-nut: CMD = lavf_container "" "-c:a mp2 -ar 44100 -threads 1" fate-lavf-dv: CMD = lavf_container "-ar 48000 -channel_layout stereo" "-r 25 -s pal" -fate-lavf-dv_pal: CMD = lavf_container_timecode_nodrop "-ar 48000 -r 25 -s pal -ac 2 -f dv" -fate-lavf-dv_ntsc: CMD = lavf_container_timecode_drop "-ar 48000 -pix_fmt yuv411p -s ntsc -ac 2 -f dv" +fate-lavf-dv_pal: CMD = lavf_container_timecode_nodrop "-af aresample=48000:tsf=s16p -r 25 -s pal -ac 2 -f dv" +fate-lavf-dv_ntsc: CMD = lavf_container_timecode_drop "-af aresample=48000:tsf=s16p -pix_fmt yuv411p -s ntsc -ac 2 -f dv" fate-lavf-flv fate-lavf-swf: CMD = lavf_container "" "-an" fate-lavf-flm: CMD = lavf_container "" "-pix_fmt rgba" -fate-lavf-gxf: CMD = lavf_container "-ar 48000" "-r 25 -s pal -ac 1 -threads 1" -fate-lavf-gxf_pal: CMD = lavf_container_timecode_nodrop "-ar 48000 -r 25 -s pal -ac 1 -threads 1 -f gxf" -fate-lavf-gxf_ntsc: CMD = lavf_container_timecode_drop "-ar 48000 -s ntsc -ac 1 -threads 1 -f gxf" +fate-lavf-gxf: CMD = lavf_container "-af aresample=48000:tsf=s16p" "-r 25 -s pal -ac 1 -threads 1" +fate-lavf-gxf_pal: CMD = lavf_container_timecode_nodrop "-af aresample=48000:tsf=s16p -r 25 -s pal -ac 1 -threads 1 -f gxf" +fate-lavf-gxf_ntsc: CMD = lavf_container_timecode_drop "-af aresample=48000:tsf=s16p -s ntsc -ac 1 -threads 1 -f gxf" fate-lavf-ismv: CMD = lavf_container_timecode "-an -write_tmcd 1 -c:v mpeg4 -threads 1" fate-lavf-mkv: CMD = lavf_container "" "-c:a mp2 -c:v mpeg4 -ar 44100 -threads 1" fate-lavf-mkv_attachment: CMD = lavf_container_attach "-c:a mp2 -c:v mpeg4 -threads 1 -f matroska" @@ -53,9 +53,9 @@ fate-lavf-mov: CMD = lavf_container_timecode "-movflags +faststart -c:a pcm_alaw fate-lavf-mov_rtphint: CMD = lavf_container "" "-movflags +rtphint -c:a pcm_alaw -c:v mpeg4 -threads 1 -f mov" fate-lavf-mp4: CMD = lavf_container_timecode "-c:v mpeg4 -an -threads 1" fate-lavf-mpg: CMD = lavf_container_timecode "-ar 44100 -threads 1" -fate-lavf-mxf: CMD = lavf_container_timecode "-ar 48000 -bf 2 -threads 1" -fate-lavf-mxf_d10: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,pad=720:608:0:32,setfield=tff -c:v mpeg2video -g 0 -flags +ildct+low_delay -dc 10 -non_linear_quant 1 -intra_vlc 1 -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10" -fate-lavf-mxf_dv25: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,setdar=4/3,setfield=bff -c:v dvvideo -pix_fmt yuv420p -b 25000k -f mxf" +fate-lavf-mxf: CMD = lavf_container_timecode "-af aresample=48000:tsf=s16p -bf 2 -threads 1" +fate-lavf-mxf_d10: CMD = lavf_container "-af aresample=48000:tsf=s16p -ac 2" "-r 25 -vf scale=720:576,pad=720:608:0:32,setfield=tff -c:v mpeg2video -g 0 -flags +ildct+low_delay -dc 10 -non_linear_quant 1 -intra_vlc 1 -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10" +fate-lavf-mxf_dv25: CMD = lavf_container "-af aresample=48000:tsf=s16p -ac 2" "-r 25 -vf scale=720:576,setdar=4/3,setfield=bff -c:v dvvideo -pix_fmt yuv420p -b 25000k -f mxf" fate-lavf-mxf_dvcpro50: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,setdar=16/9,setfield=bff -c:v dvvideo -pix_fmt yuv422p -b 50000k -f mxf" fate-lavf-mxf_dvcpro100: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=1440:1080,setdar=16/9,setfield=bff -c:v dvvideo -pix_fmt yuv422p -b 100000k -f mxf" fate-lavf-mxf_ffv1: CMD = lavf_container "-an" "-r 25 -vf scale=720:576,setdar=4/3 -c:v ffv1 -level 3 -pix_fmt yuv420p -f mxf"