mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-26 19:01:44 +02:00
WAV muxer: add RF64 support
This commit is contained in:
parent
0957041221
commit
1ecce266fa
@ -17,6 +17,7 @@ version <next>:
|
|||||||
- tee muxer
|
- tee muxer
|
||||||
- il filter ported from libmpcodecs
|
- il filter ported from libmpcodecs
|
||||||
- support ID3v2 tags in ASF files
|
- support ID3v2 tags in ASF files
|
||||||
|
- RF64 support in WAV muxer
|
||||||
|
|
||||||
|
|
||||||
version 1.1:
|
version 1.1:
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include "libavutil/avutil.h"
|
#include "libavutil/avutil.h"
|
||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_MAJOR 54
|
#define LIBAVFORMAT_VERSION_MAJOR 54
|
||||||
#define LIBAVFORMAT_VERSION_MINOR 62
|
#define LIBAVFORMAT_VERSION_MINOR 63
|
||||||
#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, \
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
* Sony Wave64 muxer
|
* Sony Wave64 muxer
|
||||||
* Copyright (c) 2012 Paul B Mahol
|
* Copyright (c) 2012 Paul B Mahol
|
||||||
*
|
*
|
||||||
|
* WAV muxer RF64 support
|
||||||
|
* Copyright (c) 2013 Daniel Verkamp <daniel@drv.nu>
|
||||||
|
*
|
||||||
* This file is part of FFmpeg.
|
* This file is part of FFmpeg.
|
||||||
*
|
*
|
||||||
* FFmpeg is free software; you can redistribute it and/or
|
* FFmpeg is free software; you can redistribute it and/or
|
||||||
@ -36,14 +39,20 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "riff.h"
|
#include "riff.h"
|
||||||
|
|
||||||
|
#define RF64_AUTO (-1)
|
||||||
|
#define RF64_NEVER 0
|
||||||
|
#define RF64_ALWAYS 1
|
||||||
|
|
||||||
typedef struct WAVMuxContext {
|
typedef struct WAVMuxContext {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
int64_t data;
|
int64_t data;
|
||||||
int64_t fact_pos;
|
int64_t fact_pos;
|
||||||
|
int64_t ds64;
|
||||||
int64_t minpts;
|
int64_t minpts;
|
||||||
int64_t maxpts;
|
int64_t maxpts;
|
||||||
int last_duration;
|
int last_duration;
|
||||||
int write_bext;
|
int write_bext;
|
||||||
|
int rf64;
|
||||||
} WAVMuxContext;
|
} WAVMuxContext;
|
||||||
|
|
||||||
#if CONFIG_WAV_MUXER
|
#if CONFIG_WAV_MUXER
|
||||||
@ -107,10 +116,24 @@ static int wav_write_header(AVFormatContext *s)
|
|||||||
AVIOContext *pb = s->pb;
|
AVIOContext *pb = s->pb;
|
||||||
int64_t fmt;
|
int64_t fmt;
|
||||||
|
|
||||||
|
if (wav->rf64 == RF64_ALWAYS) {
|
||||||
|
ffio_wfourcc(pb, "RF64");
|
||||||
|
avio_wl32(pb, -1); /* RF64 chunk size: use size in ds64 */
|
||||||
|
} else {
|
||||||
ffio_wfourcc(pb, "RIFF");
|
ffio_wfourcc(pb, "RIFF");
|
||||||
avio_wl32(pb, 0); /* file length */
|
avio_wl32(pb, 0); /* file length */
|
||||||
|
}
|
||||||
|
|
||||||
ffio_wfourcc(pb, "WAVE");
|
ffio_wfourcc(pb, "WAVE");
|
||||||
|
|
||||||
|
if (wav->rf64 != RF64_NEVER) {
|
||||||
|
/* write empty ds64 chunk or JUNK chunk to reserve space for ds64 */
|
||||||
|
ffio_wfourcc(pb, wav->rf64 == RF64_ALWAYS ? "ds64" : "JUNK");
|
||||||
|
avio_wl32(pb, 28); /* chunk size */
|
||||||
|
wav->ds64 = avio_tell(pb);
|
||||||
|
ffio_fill(pb, 0, 28);
|
||||||
|
}
|
||||||
|
|
||||||
/* format header */
|
/* format header */
|
||||||
fmt = ff_start_tag(pb, "fmt ");
|
fmt = ff_start_tag(pb, "fmt ");
|
||||||
if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) {
|
if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) {
|
||||||
@ -163,31 +186,65 @@ static int wav_write_trailer(AVFormatContext *s)
|
|||||||
{
|
{
|
||||||
AVIOContext *pb = s->pb;
|
AVIOContext *pb = s->pb;
|
||||||
WAVMuxContext *wav = s->priv_data;
|
WAVMuxContext *wav = s->priv_data;
|
||||||
int64_t file_size;
|
int64_t file_size, data_size;
|
||||||
|
int64_t number_of_samples = 0;
|
||||||
|
int rf64 = 0;
|
||||||
|
|
||||||
avio_flush(pb);
|
avio_flush(pb);
|
||||||
|
|
||||||
if (s->pb->seekable) {
|
if (s->pb->seekable) {
|
||||||
ff_end_tag(pb, wav->data);
|
|
||||||
|
|
||||||
/* update file size */
|
/* update file size */
|
||||||
file_size = avio_tell(pb);
|
file_size = avio_tell(pb);
|
||||||
|
data_size = file_size - wav->data;
|
||||||
|
if (wav->rf64 == RF64_ALWAYS || (wav->rf64 == RF64_AUTO && file_size - 8 > UINT32_MAX)) {
|
||||||
|
rf64 = 1;
|
||||||
|
} else {
|
||||||
avio_seek(pb, 4, SEEK_SET);
|
avio_seek(pb, 4, SEEK_SET);
|
||||||
avio_wl32(pb, (uint32_t)(file_size - 8));
|
avio_wl32(pb, (uint32_t)(file_size - 8));
|
||||||
avio_seek(pb, file_size, SEEK_SET);
|
avio_seek(pb, file_size, SEEK_SET);
|
||||||
|
|
||||||
|
ff_end_tag(pb, wav->data);
|
||||||
avio_flush(pb);
|
avio_flush(pb);
|
||||||
|
}
|
||||||
|
|
||||||
if(s->streams[0]->codec->codec_tag != 0x01) {
|
|
||||||
/* Update num_samps in fact chunk */
|
|
||||||
int number_of_samples;
|
|
||||||
number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
|
number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration,
|
||||||
s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
|
s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num,
|
||||||
s->streams[0]->time_base.den);
|
s->streams[0]->time_base.den);
|
||||||
|
|
||||||
|
if(s->streams[0]->codec->codec_tag != 0x01) {
|
||||||
|
/* Update num_samps in fact chunk */
|
||||||
avio_seek(pb, wav->fact_pos, SEEK_SET);
|
avio_seek(pb, wav->fact_pos, SEEK_SET);
|
||||||
|
if (rf64 || (wav->rf64 == RF64_AUTO && number_of_samples > UINT32_MAX)) {
|
||||||
|
rf64 = 1;
|
||||||
|
avio_wl32(pb, -1);
|
||||||
|
} else {
|
||||||
avio_wl32(pb, number_of_samples);
|
avio_wl32(pb, number_of_samples);
|
||||||
avio_seek(pb, file_size, SEEK_SET);
|
avio_seek(pb, file_size, SEEK_SET);
|
||||||
avio_flush(pb);
|
avio_flush(pb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rf64) {
|
||||||
|
/* overwrite RIFF with RF64 */
|
||||||
|
avio_seek(pb, 0, SEEK_SET);
|
||||||
|
ffio_wfourcc(pb, "RF64");
|
||||||
|
avio_wl32(pb, -1);
|
||||||
|
|
||||||
|
/* write ds64 chunk (overwrite JUNK if rf64 == RF64_AUTO) */
|
||||||
|
avio_seek(pb, wav->ds64 - 8, SEEK_SET);
|
||||||
|
ffio_wfourcc(pb, "ds64");
|
||||||
|
avio_wl32(pb, 28); /* ds64 chunk size */
|
||||||
|
avio_wl64(pb, file_size - 8); /* RF64 chunk size */
|
||||||
|
avio_wl64(pb, data_size); /* data chunk size */
|
||||||
|
avio_wl64(pb, number_of_samples); /* fact chunk number of samples */
|
||||||
|
avio_wl32(pb, 0); /* number of table entries for non-'data' chunks */
|
||||||
|
|
||||||
|
/* write -1 in data chunk size */
|
||||||
|
avio_seek(pb, wav->data - 4, SEEK_SET);
|
||||||
|
avio_wl32(pb, -1);
|
||||||
|
|
||||||
|
avio_seek(pb, file_size, SEEK_SET);
|
||||||
|
avio_flush(pb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -197,6 +254,10 @@ static int wav_write_trailer(AVFormatContext *s)
|
|||||||
#define ENC AV_OPT_FLAG_ENCODING_PARAM
|
#define ENC AV_OPT_FLAG_ENCODING_PARAM
|
||||||
static const AVOption options[] = {
|
static const AVOption options[] = {
|
||||||
{ "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, ENC },
|
{ "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, ENC },
|
||||||
|
{ "rf64", "Use RF64 header rather than RIFF for large files.", OFFSET(rf64), AV_OPT_TYPE_INT, { .i64 = RF64_NEVER },-1, 1, ENC, "rf64" },
|
||||||
|
{ "auto", "Write RF64 header if file grows large enough.", 0, AV_OPT_TYPE_CONST, { .i64 = RF64_AUTO }, 0, 0, ENC, "rf64" },
|
||||||
|
{ "always", "Always write RF64 header regardless of file size.", 0, AV_OPT_TYPE_CONST, { .i64 = RF64_ALWAYS }, 0, 0, ENC, "rf64" },
|
||||||
|
{ "never", "Never write RF64 header regardless of file size.", 0, AV_OPT_TYPE_CONST, { .i64 = RF64_NEVER }, 0, 0, ENC, "rf64" },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user