|
|
|
@ -27,6 +27,7 @@ |
|
|
|
|
#include "isom.h" |
|
|
|
|
#include "matroska.h" |
|
|
|
|
#include "riff.h" |
|
|
|
|
#include "wv.h" |
|
|
|
|
|
|
|
|
|
#include "libavutil/avstring.h" |
|
|
|
|
#include "libavutil/dict.h" |
|
|
|
@ -450,6 +451,15 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
MPEG4AudioConfig mp4ac; |
|
|
|
@ -479,6 +489,8 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecCo |
|
|
|
|
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); |
|
|
|
|
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) |
|
|
|
|
ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size); |
|
|
|
|
else if (codec->codec_id == AV_CODEC_ID_ALAC) { |
|
|
|
@ -1054,6 +1066,59 @@ static int mkv_write_ass_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *p |
|
|
|
|
return max_duration; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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, |
|
|
|
|
unsigned int blockid, AVPacket *pkt, int flags) |
|
|
|
|
{ |
|
|
|
@ -1069,7 +1134,13 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, |
|
|
|
|
if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 && |
|
|
|
|
(AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
if (codec->codec_id == AV_CODEC_ID_PRORES) { |
|
|
|
|