diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-05-28 13:19:26 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-05-28 13:19:26 +0200 |
commit | 61917a104e0ce8d7b3b74ad66624a4f295b41c71 (patch) | |
tree | ab83309115176af4990636e4e468bd87714bb69f | |
parent | dff4aa6afd40bcc6c71b5a21d229fb941f9fc1eb (diff) | |
parent | 106b62f4ba600f24415eaded5e020aeceb23fd59 (diff) | |
download | ffmpeg-61917a104e0ce8d7b3b74ad66624a4f295b41c71.tar.gz |
Merge commit '106b62f4ba600f24415eaded5e020aeceb23fd59'
* commit '106b62f4ba600f24415eaded5e020aeceb23fd59':
matroskaenc: write the channel mask for FLAC
Conflicts:
libavformat/matroskaenc.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/Makefile | 2 | ||||
-rw-r--r-- | libavformat/matroskaenc.c | 47 |
2 files changed, 47 insertions, 2 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile index 365481ecb2..fdd0123811 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -209,7 +209,7 @@ OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \ oggparsevorbis.o vorbiscomment.o OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \ isom.o avc.o hevc.o \ - flacenc_header.o avlanguage.o wv.o + flacenc_header.o avlanguage.o vorbiscomment.o wv.o OBJS-$(CONFIG_MD5_MUXER) += md5enc.o OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o OBJS-$(CONFIG_MICRODVD_DEMUXER) += microdvddec.o subtitles.o diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 980bf3a739..67ba3c3fe3 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -32,9 +32,11 @@ #include "matroska.h" #include "riff.h" #include "subtitles.h" +#include "vorbiscomment.h" #include "wv.h" #include "libavutil/avstring.h" +#include "libavutil/channel_layout.h" #include "libavutil/dict.h" #include "libavutil/intfloat.h" #include "libavutil/intreadwrite.h" @@ -505,6 +507,49 @@ static int put_wv_codecpriv(AVIOContext *pb, AVCodecContext *codec) return 0; } +static int put_flac_codecpriv(AVFormatContext *s, + AVIOContext *pb, AVCodecContext *codec) +{ + int write_comment = (codec->channel_layout && + !(codec->channel_layout & ~0x3ffffULL) && + !ff_flac_is_native_layout(codec->channel_layout)); + int ret = ff_flac_write_header(pb, codec, !write_comment); + + if (ret < 0) + return ret; + + if (write_comment) { + const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ? + "Libav" : LIBAVFORMAT_IDENT; + AVDictionary *dict = NULL; + uint8_t buf[32], *data, *p; + int len; + + snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); + av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); + + len = ff_vorbiscomment_length(dict, vendor); + data = av_malloc(len + 4); + if (!data) { + av_dict_free(&dict); + return AVERROR(ENOMEM); + } + + data[0] = 0x84; + AV_WB24(data + 1, len); + + p = data + 4; + ff_vorbiscomment_write(&p, &dict, vendor); + + avio_write(pb, data, len + 4); + + av_freep(&data); + av_dict_free(&dict); + } + + return 0; +} + static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate) { MPEG4AudioConfig mp4ac; @@ -533,7 +578,7 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecCo if (codec->codec_id == AV_CODEC_ID_VORBIS || codec->codec_id == AV_CODEC_ID_THEORA) ret = put_xiph_codecpriv(s, dyn_cp, codec); else if (codec->codec_id == AV_CODEC_ID_FLAC) - ret = ff_flac_write_header(dyn_cp, codec, 1); + ret = put_flac_codecpriv(s, dyn_cp, codec); else if (codec->codec_id == AV_CODEC_ID_WAVPACK) ret = put_wv_codecpriv(dyn_cp, codec); else if (codec->codec_id == AV_CODEC_ID_H264) |