On 10.09.2015 15:28, Tobias Rapp wrote:
On 10.09.2015 14:57, Derek Buitenhuis wrote:
On 9/10/2015 1:25 PM, Tobias Rapp wrote:
My use-case is handling recorded AVI files which have an
unknown/empty/unsupported channel layout. Instead of writing the guessed
channel layout into the output file, using "-write_channel_mask off"
allows to write an empty channel mask instead.
Are such files even valid?
I guess so as the docs at [1] say in chapter "Details about dwChannelMask":
"If, for example in a multi-channel audio authoring application, no
speaker location is desired on any of the mono streams, the
dwChannelMask should explicitly be set to 0."
BTW: I just noticed that FATE is failing after applying the patch so
I'll need to take a closer look and update the patch before it can be
applied.
Forgot to add a reference to AVClass in AVIContext. Attached an updated
version of the patch.
/Tobias
>From 6b2c3feb43870398005ea307d6d9ee4736dd2d11 Mon Sep 17 00:00:00 2001
From: Tobias Rapp <t.r...@noa-audio.com>
Date: Thu, 10 Sep 2015 14:04:18 +0200
Subject: [PATCH] avformat/avienc: add muxer option "write_channel_mask"
Allow writing an empty channel mask into the wave format header. Useful
if the input file contains an unknown channel layout.
---
libavformat/avienc.c | 23 +++++++++++++++++++++--
libavformat/riff.h | 5 +++++
libavformat/riffenc.c | 5 +++--
3 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index a79f156..649961d 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -34,6 +34,7 @@
#include "libavutil/dict.h"
#include "libavutil/avassert.h"
#include "libavutil/timestamp.h"
+#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavcodec/raw.h"
@@ -58,9 +59,11 @@ typedef struct AVIIndex {
} AVIIndex;
typedef struct AVIContext {
+ const AVClass *class;
int64_t riff_start, movi_list, odml_list;
int64_t frames_hdr_all;
int riff_id;
+ int write_channel_mask;
} AVIContext;
typedef struct AVIStream {
@@ -339,7 +342,7 @@ static int avi_write_header(AVFormatContext *s)
ff_end_tag(pb, strh);
if (enc->codec_type != AVMEDIA_TYPE_DATA) {
- int ret;
+ int ret, flags;
enum AVPixelFormat pix_fmt;
strf = ff_start_tag(pb, "strf");
@@ -367,7 +370,8 @@ static int avi_write_header(AVFormatContext *s)
av_get_pix_fmt_name(enc->pix_fmt));
break;
case AVMEDIA_TYPE_AUDIO:
- if ((ret = ff_put_wav_header(pb, enc, 0)) < 0)
+ flags = (avi->write_channel_mask == 0) ? FF_PUT_WAV_HEADER_SKIP_CHANNELMASK : 0;
+ if ((ret = ff_put_wav_header(pb, enc, flags)) < 0)
return ret;
break;
default:
@@ -782,6 +786,20 @@ static int avi_write_trailer(AVFormatContext *s)
return res;
}
+#define OFFSET(x) offsetof(AVIContext, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "write_channel_mask", "write channel mask into wave format header", OFFSET(write_channel_mask), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, ENC },
+ { NULL },
+};
+
+static const AVClass avi_muxer_class = {
+ .class_name = "AVI muxer",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVOutputFormat ff_avi_muxer = {
.name = "avi",
.long_name = NULL_IF_CONFIG_SMALL("AVI (Audio Video Interleaved)"),
@@ -796,4 +814,5 @@ AVOutputFormat ff_avi_muxer = {
.codec_tag = (const AVCodecTag * const []) {
ff_codec_bmp_tags, ff_codec_wav_tags, 0
},
+ .priv_class = &avi_muxer_class,
};
diff --git a/libavformat/riff.h b/libavformat/riff.h
index 399c527..d6d91ef 100644
--- a/libavformat/riff.h
+++ b/libavformat/riff.h
@@ -53,6 +53,11 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *t
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX 0x00000001
/**
+ * Tell ff_put_wav_header() to write an empty channel mask.
+ */
+#define FF_PUT_WAV_HEADER_SKIP_CHANNELMASK 0x00000002
+
+/**
* Write WAVEFORMAT header structure.
*
* @param flags a combination of FF_PUT_WAV_HEADER_* constants
diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c
index 85c953f..ceb27f2 100644
--- a/libavformat/riffenc.c
+++ b/libavformat/riffenc.c
@@ -168,8 +168,9 @@ int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc, int flags)
}
/* write WAVEFORMATEXTENSIBLE extensions */
if (waveformatextensible) {
- int write_channel_mask = enc->strict_std_compliance < FF_COMPLIANCE_NORMAL ||
- enc->channel_layout < 0x40000;
+ int write_channel_mask = !(flags & FF_PUT_WAV_HEADER_SKIP_CHANNELMASK) &&
+ (enc->strict_std_compliance < FF_COMPLIANCE_NORMAL ||
+ enc->channel_layout < 0x40000);
/* 22 is WAVEFORMATEXTENSIBLE size */
avio_wl16(pb, riff_extradata - riff_extradata_start + 22);
/* ValidBitsPerSample || SamplesPerBlock || Reserved */
--
1.9.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel