[FFmpeg-devel] [PATCH]Write channel layout in aif files, v2
Carl Eugen Hoyos
cehoyos at ag.or.at
Thu Apr 28 11:13:13 CEST 2011
Hi!
Attached allows to write the CHAN channel layout chunk to aif files.
Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 428c641..f1390fe 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -24,7 +24,7 @@ OBJS-$(CONFIG_AC3_MUXER) += rawenc.o
OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o
OBJS-$(CONFIG_AEA_DEMUXER) += aea.o pcm.o
OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o isom.o
-OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o riff.o
+OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o riff.o isom.o
OBJS-$(CONFIG_AMR_DEMUXER) += amr.o
OBJS-$(CONFIG_AMR_MUXER) += amr.o
OBJS-$(CONFIG_ANM_DEMUXER) += anm.o
diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c
index cc3cbc4..8632e8c 100644
--- a/libavformat/aiffenc.c
+++ b/libavformat/aiffenc.c
@@ -22,6 +22,7 @@
#include "avformat.h"
#include "aiff.h"
#include "avio_internal.h"
+#include "isom.h"
typedef struct {
int64_t form;
@@ -36,6 +37,7 @@ static int aiff_write_header(AVFormatContext *s)
AVCodecContext *enc = s->streams[0]->codec;
AVExtFloat sample_rate;
int aifc = 0;
+ uint32_t layout_tag = ff_mov_get_chan(enc->channel_layout);
/* First verify if format is ok */
if (!enc->codec_tag)
@@ -61,6 +63,19 @@ static int aiff_write_header(AVFormatContext *s)
avio_wb32(pb, 0xA2805140);
}
+ if (enc->channels > 2 && layout_tag) {
+ ffio_wfourcc(pb, "CHAN");
+ avio_wb32(pb, 12); //< mChunkSize
+ avio_wb32(pb, layout_tag); //< mChannelLayoutTag
+ avio_wb32(pb, 0); //< mChannelBitmap
+ avio_wb32(pb, 0); //< mNumberChannelDescriptions
+ } else if (enc->channels > 2 && enc->channel_layout) {
+ char name[32];
+ av_get_channel_layout_string(name, sizeof(name), enc->channels,
+ enc->channel_layout);
+ av_log(s, AV_LOG_WARNING, "Unsupported channel layout %s\n", name);
+ }
+
/* Common chunk */
ffio_wfourcc(pb, "COMM");
avio_wb32(pb, aifc ? 24 : 18); /* size */
diff --git a/libavformat/isom.c b/libavformat/isom.c
index 76a7082..bb575f3 100644
--- a/libavformat/isom.c
+++ b/libavformat/isom.c
@@ -480,3 +480,11 @@ void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec)
avio_skip(pb, 8);
}
+int32_t ff_mov_get_chan(uint64_t channel_layout) {
+ const MovChannelLayout *layouts;
+ for (layouts = mov_channel_layout; layouts->channel_layout; layouts++)
+ if (channel_layout == layouts->channel_layout)
+ return layouts->layout_tag;
+ return 0;
+}
+
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 081d227..3090ab9 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -157,5 +157,6 @@ enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec);
+int32_t ff_mov_get_chan(uint64_t channel_layout);
#endif /* AVFORMAT_ISOM_H */
More information about the ffmpeg-devel
mailing list