From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 09A1240B23 for ; Mon, 27 Dec 2021 08:01:51 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7FA3D68B07E; Mon, 27 Dec 2021 10:01:49 +0200 (EET) Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5F6F868AEAD for ; Mon, 27 Dec 2021 10:01:43 +0200 (EET) Received: by mail-pj1-f45.google.com with SMTP id jw3so12825248pjb.4 for ; Mon, 27 Dec 2021 00:01:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=O3vuo/VAP2PI1LsHAhPtD5JJVoPdM715lmASRYhZ3k4=; b=aHSTHJC4At2r+HWQfEQ/sVeEM8QXVzNn1JfsM6M5o/bh3PUPb0g5ZLA57G4FrVlCal shk2XN14H1me/Y0qZncFsRSX/BjW4AbTQ3iI0Q96NL8dYLllpJpQePWfusbuoUN4jFZm U27TR3UBE49HCRuYLdSsfGBo4d90IH/9CsAlvKyJ+jYRM3a9wvlTtw6xuItGzhy/JHCT 62trcQghTFj7h5nu02n7hrCjQ/4/VupMlG+MWg1dFhiJUyUYO45HwZQ/0aNJeXLoQYLe lHE+mFXLxADOzDfHdqDs7lfNpXszIAaVZP2L8U8bEMIkX6MZKt2Cx4/WsUd6Tn21P+sX Yqfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=O3vuo/VAP2PI1LsHAhPtD5JJVoPdM715lmASRYhZ3k4=; b=iX84d8tqr0cmLYJTq6uvIGisMR/ZrpbjTO7wGrAiHBv+oASUXlBFZ0kasQtqZUfObG 6C76cU4ZDuIUc44/tn6cUaysCbKMD8nh1FMv6k0oDWgPQiISCY5pb0nCp1LzGaSXUnis QL7MAhspYJK+Jtrh4XuV5bsZfgU4HXRwas2u0LuxLd5DTBaNILbHJk82f0wNQqks1Bfd +g4saSwuRtXLod46PKA69659N2a3S1LbrXllJ+0iG2Uek1oIh0AJsCp3f1iJY0OgPj9f TaCKxydIbnmw3H+0xpllIL/fZbiS43/zDF2MoiPPObaLSNGLTuNtPrs+VZF7klzX7hg/ AD9g== X-Gm-Message-State: AOAM5311zWflMZ9C5B9j6I/GiaxmXj6Y3BkPgrdpAwqV36/wpkTYJmU7 xqk7ocgt14VTMh2TOY9cut5cWgqqLQs4EA== X-Google-Smtp-Source: ABdhPJzhac4cO3i/m7N6LSjcpKwY2/V4Kv30wvBNXnE4sS2EInz+Q+3JBKs/eQCVJWP4vGwnk58ovQ== X-Received: by 2002:a17:90b:1bcd:: with SMTP id oa13mr19642536pjb.192.1640592100072; Mon, 27 Dec 2021 00:01:40 -0800 (PST) Received: from ideapad.. ([161.81.112.246]) by smtp.gmail.com with ESMTPSA id a15sm6710769pjo.49.2021.12.27.00.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Dec 2021 00:01:39 -0800 (PST) From: Tom Yan To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Dec 2021 16:01:33 +0800 Message-Id: <20211227080133.340609-1-tom.ty89@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/wavenc: allow WAVEFORMATEXTENSIBLE to be suppressed 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: Tom Yan Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: While WAVEFORMATEX sort of mandates WAVEFORMATEXTENSIBLE to be used for audio with sample size other than 8 or 16, PCMWAVEFORMAT does not practically have any limitation in supporting higher sample size that is a multiple of 8 (or sample rate higher than 48000). In terms of sample size, the only real reason that the extension exists is that it allows both an actual sample size and a multiple-of-8 container size to be stored. However, such facility is of no use when the actual sample size is a multiple of 8, let alone that muxer never made use of it (since it never actually supported sample size like 20 anyway; at least not in the way it is supposed to.) Although WAVEFORMATEXTENSIBLE has been around for more than two decades, apparently programs and libraries that do not support the format still exist. Therefore, adding an option that allows the WAVEFORMATEXTENSIBLE "extensions" to be suppressed and the format tag field to be set to WAVE_FORMAT_PCM (0x0001) for audio with sample size higher than 16 (or sample rate higher than 48000). Signed-off-by: Tom Yan --- libavformat/riff.h | 5 +++++ libavformat/riffenc.c | 4 ++-- libavformat/wavenc.c | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libavformat/riff.h b/libavformat/riff.h index 85d6786663..5794857f53 100644 --- a/libavformat/riff.h +++ b/libavformat/riff.h @@ -57,6 +57,11 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int */ #define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK 0x00000002 +/** + * Tell ff_put_wav_header() not to write WAVEFORMATEXTENSIBLE extensions if possible. + */ +#define FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT 0x00000004 + /** * Write WAVEFORMAT header structure. * diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c index ffccfa3d48..4dc8ca6e0f 100644 --- a/libavformat/riffenc.c +++ b/libavformat/riffenc.c @@ -80,9 +80,9 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, waveformatextensible = (par->channels > 2 && par->channel_layout) || par->channels == 1 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_MONO || par->channels == 2 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_STEREO || - par->sample_rate > 48000 || par->codec_id == AV_CODEC_ID_EAC3 || - av_get_bits_per_sample(par->codec_id) > 16; + ((par->sample_rate > 48000 || av_get_bits_per_sample(par->codec_id) > 16) && + !(flags & FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT)); if (waveformatextensible) avio_wl16(pb, 0xfffe); diff --git a/libavformat/wavenc.c b/libavformat/wavenc.c index 2317700be1..bd41d6eeb3 100644 --- a/libavformat/wavenc.c +++ b/libavformat/wavenc.c @@ -83,6 +83,7 @@ typedef struct WAVMuxContext { int peak_block_pos; int peak_ppv; int peak_bps; + int extensible; } WAVMuxContext; #if CONFIG_WAV_MUXER @@ -324,9 +325,10 @@ static int wav_write_header(AVFormatContext *s) } if (wav->write_peak != PEAK_ONLY) { + int flags = !wav->extensible ? FF_PUT_WAV_HEADER_FORCE_PCMWAVEFORMAT : 0; /* format header */ fmt = ff_start_tag(pb, "fmt "); - if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, 0) < 0) { + if (ff_put_wav_header(s, pb, s->streams[0]->codecpar, flags) < 0) { av_log(s, AV_LOG_ERROR, "Codec %s not supported in WAVE format\n", avcodec_get_name(s->streams[0]->codecpar->codec_id)); return AVERROR(ENOSYS); @@ -494,6 +496,7 @@ static const AVOption options[] = { { "peak_block_size", "Number of audio samples used to generate each peak frame.", OFFSET(peak_block_size), AV_OPT_TYPE_INT, { .i64 = 256 }, 0, 65536, ENC }, { "peak_format", "The format of the peak envelope data (1: uint8, 2: uint16).", OFFSET(peak_format), AV_OPT_TYPE_INT, { .i64 = PEAK_FORMAT_UINT16 }, PEAK_FORMAT_UINT8, PEAK_FORMAT_UINT16, ENC }, { "peak_ppv", "Number of peak points per peak value (1 or 2).", OFFSET(peak_ppv), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, 2, ENC }, + { "extensible", "Write WAVEFORMATEXTENSIBLE extensions.", OFFSET(extensible), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC }, { NULL }, }; -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".