Merge commit '2d2d6a4883479403798f4ed46941d5b365823570'

* commit '2d2d6a4883479403798f4ed46941d5b365823570':
  lavf: add a raw WavPack muxer.
  apetag: add support for writing APE tags
  matroskaenc: support muxing WavPack

Conflicts:
	libavformat/Makefile
	libavformat/allformats.c
	libavformat/apetag.h
	libavformat/version.h
	libavformat/wvenc.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
pull/23/head
Michael Niedermayer 12 years ago
commit d9cde3976c
  1. 1
      Changelog
  2. 4
      libavformat/Makefile
  3. 56
      libavformat/apetag.c
  4. 4
      libavformat/apetag.h
  5. 73
      libavformat/matroskaenc.c
  6. 2
      libavformat/version.h
  7. 73
      libavformat/wvenc.c
  8. 2
      tests/Makefile
  9. 10
      tests/fate/wavpack.mak

@ -57,6 +57,7 @@ version <next>:
- support for slice multithreading in libavfilter - support for slice multithreading in libavfilter
- Hald CLUT support (generation and filtering) - Hald CLUT support (generation and filtering)
- VC-1 interlaced B-frame support - VC-1 interlaced B-frame support
- support for WavPack muxing (raw and in Matroska)
version 1.2: version 1.2:

@ -195,7 +195,7 @@ OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \
isom.o rmsipr.o isom.o rmsipr.o
OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \ OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \
isom.o avc.o \ isom.o avc.o \
flacenc_header.o avlanguage.o flacenc_header.o avlanguage.o wv.o
OBJS-$(CONFIG_MD5_MUXER) += md5enc.o OBJS-$(CONFIG_MD5_MUXER) += md5enc.o
OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o OBJS-$(CONFIG_MGSTS_DEMUXER) += mgsts.o
OBJS-$(CONFIG_MICRODVD_DEMUXER) += microdvddec.o subtitles.o OBJS-$(CONFIG_MICRODVD_DEMUXER) += microdvddec.o subtitles.o
@ -399,7 +399,7 @@ OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcry
avlanguage.o mpegts.o isom.o avlanguage.o mpegts.o isom.o
OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o
OBJS-$(CONFIG_WV_DEMUXER) += wvdec.o wv.o apetag.o img2.o OBJS-$(CONFIG_WV_DEMUXER) += wvdec.o wv.o apetag.o img2.o
OBJS-$(CONFIG_WV_MUXER) += wvenc.o apetagenc.o OBJS-$(CONFIG_WV_MUXER) += wvenc.o wv.o apetag.o
OBJS-$(CONFIG_XA_DEMUXER) += xa.o OBJS-$(CONFIG_XA_DEMUXER) += xa.o
OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o
OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o

@ -23,10 +23,12 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "avformat.h" #include "avformat.h"
#include "avio_internal.h"
#include "apetag.h" #include "apetag.h"
#include "internal.h" #include "internal.h"
#define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) #define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31)
#define APE_TAG_FLAG_CONTAINS_FOOTER (1 << 30)
#define APE_TAG_FLAG_IS_HEADER (1 << 29) #define APE_TAG_FLAG_IS_HEADER (1 << 29)
#define APE_TAG_FLAG_IS_BINARY (1 << 1) #define APE_TAG_FLAG_IS_BINARY (1 << 1)
@ -167,3 +169,57 @@ int64_t ff_ape_parse_tag(AVFormatContext *s)
return tag_start; return tag_start;
} }
int ff_ape_write_tag(AVFormatContext *s)
{
AVDictionaryEntry *e = NULL;
int64_t start, end;
int size, count = 0;
if (!s->pb->seekable)
return 0;
start = avio_tell(s->pb);
// header
avio_write(s->pb, "APETAGEX", 8); // id
avio_wl32 (s->pb, APE_TAG_VERSION); // version
avio_wl32(s->pb, 0); // reserve space for size
avio_wl32(s->pb, 0); // reserve space for tag count
// flags
avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER |
APE_TAG_FLAG_IS_HEADER);
ffio_fill(s->pb, 0, 8); // reserved
while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
int val_len = strlen(e->value);
avio_wl32(s->pb, val_len); // value length
avio_wl32(s->pb, 0); // item flags
avio_put_str(s->pb, e->key); // key
avio_write(s->pb, e->value, val_len); // value
count++;
}
size = avio_tell(s->pb) - start;
// footer
avio_write(s->pb, "APETAGEX", 8); // id
avio_wl32 (s->pb, APE_TAG_VERSION); // version
avio_wl32(s->pb, size); // size
avio_wl32(s->pb, count); // tag count
// flags
avio_wl32(s->pb, APE_TAG_FLAG_CONTAINS_HEADER | APE_TAG_FLAG_CONTAINS_FOOTER);
ffio_fill(s->pb, 0, 8); // reserved
// update values in the header
end = avio_tell(s->pb);
avio_seek(s->pb, start + 12, SEEK_SET);
avio_wl32(s->pb, size);
avio_wl32(s->pb, count);
avio_seek(s->pb, end, SEEK_SET);
return 0;
}

@ -37,8 +37,8 @@
int64_t ff_ape_parse_tag(AVFormatContext *s); int64_t ff_ape_parse_tag(AVFormatContext *s);
/** /**
* Write an APEv2 tag * Write an APE tag into a file.
*/ */
void ff_ape_write(AVFormatContext *s); int ff_ape_write_tag(AVFormatContext *s);
#endif /* AVFORMAT_APETAG_H */ #endif /* AVFORMAT_APETAG_H */

@ -27,6 +27,7 @@
#include "isom.h" #include "isom.h"
#include "matroska.h" #include "matroska.h"
#include "riff.h" #include "riff.h"
#include "wv.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
@ -459,6 +460,15 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex
return 0; return 0;
} }
static int put_wv_codecpriv(AVIOContext *pb, AVCodecContext *codec)
{
if (codec->extradata && codec->extradata_size == 2)
avio_write(pb, codec->extradata, 2);
else
avio_wl16(pb, 0x403); // fallback to the version mentioned in matroska specs
return 0;
}
static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate) static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate)
{ {
MPEG4AudioConfig mp4ac; MPEG4AudioConfig mp4ac;
@ -488,6 +498,8 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecCo
ret = put_xiph_codecpriv(s, dyn_cp, codec); ret = put_xiph_codecpriv(s, dyn_cp, codec);
else if (codec->codec_id == AV_CODEC_ID_FLAC) else if (codec->codec_id == AV_CODEC_ID_FLAC)
ret = ff_flac_write_header(dyn_cp, codec, 1); ret = ff_flac_write_header(dyn_cp, codec, 1);
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) else if (codec->codec_id == AV_CODEC_ID_H264)
ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size); ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size);
else if (codec->codec_id == AV_CODEC_ID_ALAC) { else if (codec->codec_id == AV_CODEC_ID_ALAC) {
@ -1137,6 +1149,59 @@ static int mkv_write_ass_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *p
} }
#endif #endif
static int mkv_strip_wavpack(const uint8_t *src, uint8_t **pdst, int *size)
{
uint8_t *dst;
int srclen = *size;
int offset = 0;
int ret;
dst = av_malloc(srclen);
if (!dst)
return AVERROR(ENOMEM);
while (srclen >= WV_HEADER_SIZE) {
WvHeader header;
ret = ff_wv_parse_header(&header, src);
if (ret < 0)
goto fail;
src += WV_HEADER_SIZE;
srclen -= WV_HEADER_SIZE;
if (srclen < header.blocksize) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
if (header.initial) {
AV_WL32(dst + offset, header.samples);
offset += 4;
}
AV_WL32(dst + offset, header.flags);
AV_WL32(dst + offset + 4, header.crc);
offset += 8;
if (!(header.initial && header.final)) {
AV_WL32(dst + offset, header.blocksize);
offset += 4;
}
memcpy(dst + offset, src, header.blocksize);
src += header.blocksize;
srclen -= header.blocksize;
offset += header.blocksize;
}
*pdst = dst;
*size = offset;
return 0;
fail:
av_freep(&dst);
return ret;
}
static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
unsigned int blockid, AVPacket *pkt, int flags) unsigned int blockid, AVPacket *pkt, int flags)
{ {
@ -1154,7 +1219,13 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb,
if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 && if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 &&
(AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1))
ff_avc_parse_nal_units_buf(pkt->data, &data, &size); ff_avc_parse_nal_units_buf(pkt->data, &data, &size);
else else if (codec->codec_id == AV_CODEC_ID_WAVPACK) {
int ret = mkv_strip_wavpack(pkt->data, &data, &size);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Error stripping a WavPack packet.\n");
return;
}
} else
data = pkt->data; data = pkt->data;
if (codec->codec_id == AV_CODEC_ID_PRORES) { if (codec->codec_id == AV_CODEC_ID_PRORES) {

@ -30,7 +30,7 @@
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 55 #define LIBAVFORMAT_VERSION_MAJOR 55
#define LIBAVFORMAT_VERSION_MINOR 7 #define LIBAVFORMAT_VERSION_MINOR 8
#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_MICRO 100
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

@ -1,5 +1,6 @@
/* /*
* WavPack muxer * WavPack muxer
* Copyright (c) 2013 Kostya Shishkov <kostya.shishkov@gmail.com>
* Copyright (c) 2012 Paul B Mahol * Copyright (c) 2012 Paul B Mahol
* *
* This file is part of FFmpeg. * This file is part of FFmpeg.
@ -19,68 +20,74 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "libavutil/intreadwrite.h"
#include "avformat.h" #include "libavutil/attributes.h"
#include "internal.h"
#include "apetag.h" #include "apetag.h"
#include "avformat.h"
#include "wv.h"
typedef struct WVMuxContext { typedef struct WvMuxContext {
int64_t samples; int64_t samples;
} WVMuxContext; } WvMuxContext;
static int write_header(AVFormatContext *s) static av_cold int wv_write_header(AVFormatContext *ctx)
{ {
AVCodecContext *codec = s->streams[0]->codec; if (ctx->nb_streams > 1 ||
ctx->streams[0]->codec->codec_id != AV_CODEC_ID_WAVPACK) {
if (s->nb_streams > 1) { av_log(ctx, AV_LOG_ERROR, "This muxer only supports a single WavPack stream.\n");
av_log(s, AV_LOG_ERROR, "only one stream is supported\n");
return AVERROR(EINVAL);
}
if (codec->codec_id != AV_CODEC_ID_WAVPACK) {
av_log(s, AV_LOG_ERROR, "unsupported codec\n");
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
return 0; return 0;
} }
static int write_packet(AVFormatContext *ctx, AVPacket *pkt) static int wv_write_packet(AVFormatContext *ctx, AVPacket *pkt)
{ {
WVMuxContext *s = ctx->priv_data; WvMuxContext *s = ctx->priv_data;
WvHeader header;
int ret;
if (pkt->size < WV_HEADER_SIZE ||
(ret = ff_wv_parse_header(&header, pkt->data)) < 0) {
av_log(ctx, AV_LOG_ERROR, "Invalid WavPack packet.\n");
return AVERROR(EINVAL);
}
s->samples += header.samples;
if (pkt->size >= 24)
s->samples += AV_RL32(pkt->data + 20);
avio_write(ctx->pb, pkt->data, pkt->size); avio_write(ctx->pb, pkt->data, pkt->size);
avio_flush(ctx->pb);
return 0; return 0;
} }
static int write_trailer(AVFormatContext *ctx) static av_cold int wv_write_trailer(AVFormatContext *ctx)
{ {
WVMuxContext *s = ctx->priv_data; WvMuxContext *s = ctx->priv_data;
ff_ape_write(ctx);
if (ctx->pb->seekable && s->samples) { /* update total number of samples in the first block */
if (ctx->pb->seekable && s->samples &&
s->samples < UINT32_MAX) {
int64_t pos = avio_tell(ctx->pb);
avio_seek(ctx->pb, 12, SEEK_SET); avio_seek(ctx->pb, 12, SEEK_SET);
if (s->samples < 0xFFFFFFFFu) avio_wl32(ctx->pb, s->samples);
avio_wl32(ctx->pb, s->samples); avio_seek(ctx->pb, pos, SEEK_SET);
else
avio_wl32(ctx->pb, 0xFFFFFFFFu);
avio_flush(ctx->pb);
} }
ff_ape_write_tag(ctx);
return 0; return 0;
} }
AVOutputFormat ff_wv_muxer = { AVOutputFormat ff_wv_muxer = {
.name = "wv", .name = "wv",
.long_name = NULL_IF_CONFIG_SMALL("WavPack"), .long_name = NULL_IF_CONFIG_SMALL("raw WavPack"),
.priv_data_size = sizeof(WVMuxContext), .mime_type = "audio/x-wavpack",
.extensions = "wv", .extensions = "wv",
.priv_data_size = sizeof(WvMuxContext),
.audio_codec = AV_CODEC_ID_WAVPACK, .audio_codec = AV_CODEC_ID_WAVPACK,
.video_codec = AV_CODEC_ID_NONE, .video_codec = AV_CODEC_ID_NONE,
.write_header = write_header, .write_header = wv_write_header,
.write_packet = write_packet, .write_packet = wv_write_packet,
.write_trailer = write_trailer, .write_trailer = wv_write_trailer,
.flags = AVFMT_NOTIMESTAMPS, .flags = AVFMT_NOTIMESTAMPS,
}; };

@ -63,6 +63,8 @@ ENCDEC2 = $(call ALLYES, $(firstword $(1))_ENCODER $(lastword $(1))_DECODER \
DEMDEC = $(call ALLYES, $(1)_DEMUXER $(2:%=%_DECODER)) DEMDEC = $(call ALLYES, $(1)_DEMUXER $(2:%=%_DECODER))
ENCMUX = $(call ALLYES, $(1:%=%_ENCODER) $(2)_MUXER) ENCMUX = $(call ALLYES, $(1:%=%_ENCODER) $(2)_MUXER)
DEMMUX = $(call ALLYES, $(1)_DEMUXER $(2)_MUXER)
FILTERDEMDEC = $(call ALLYES, $(1)_FILTER $(2)_DEMUXER $(3)_DECODER) FILTERDEMDEC = $(call ALLYES, $(1)_FILTER $(2)_DEMUXER $(3)_DECODER)
FILTERDEMDECMUX = $(call ALLYES, $(1)_FILTER $(2)_DEMUXER $(3)_DECODER $(4)_MUXER) FILTERDEMDECMUX = $(call ALLYES, $(1)_FILTER $(2)_DEMUXER $(3)_DECODER $(4)_MUXER)
FILTERDEMDECENCMUX = $(call ALLYES, $(1)_FILTER $(2)_DEMUXER $(3)_DECODER $(4)_ENCODER $(5)_MUXER) FILTERDEMDECENCMUX = $(call ALLYES, $(1)_FILTER $(2)_DEMUXER $(3)_DECODER $(4)_ENCODER $(5)_MUXER)

@ -88,5 +88,15 @@ FATE_WAVPACK-$(call DEMDEC, WV, WAVPACK) += $(FATE_WAVPACK)
FATE_WAVPACK-$(call DEMDEC, MATROSKA, WAVPACK) += fate-wavpack-matroskamode FATE_WAVPACK-$(call DEMDEC, MATROSKA, WAVPACK) += fate-wavpack-matroskamode
fate-wavpack-matroskamode: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/special/matroska_mode.mka -f s16le fate-wavpack-matroskamode: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/special/matroska_mode.mka -f s16le
FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-mono
fate-wavpack-matroska_mux-mono: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/num_channels/mono_16bit_int.wv -c copy -flags +bitexact -f matroska
fate-wavpack-matroska_mux-mono: CMP = oneline
fate-wavpack-matroska_mux-mono: REF = 769c19bcd931d9e15f7d5aa7b390b0db
FATE_WAVPACK-$(call DEMMUX, WV, MATROSKA) += fate-wavpack-matroska_mux-61
fate-wavpack-matroska_mux-61: CMD = md5 -i $(TARGET_SAMPLES)/wavpack/num_channels/eva_2.22_6.1_16bit-partial.wv -c copy -flags +bitexact -f matroska
fate-wavpack-matroska_mux-61: CMP = oneline
fate-wavpack-matroska_mux-61: REF = 7f13234f0f3d5b7e00a4661412be025b
FATE_SAMPLES_AVCONV += $(FATE_WAVPACK-yes) FATE_SAMPLES_AVCONV += $(FATE_WAVPACK-yes)
fate-wavpack: $(FATE_WAVPACK-yes) fate-wavpack: $(FATE_WAVPACK-yes)

Loading…
Cancel
Save