mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
Vorbis metadata writing. Patch by James Darnley <james.darnley gmail com>.
Fixes issue 555. Originally committed as revision 25034 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
7bac991fd9
commit
521d434fd5
@ -206,14 +206,14 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
|
static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
|
||||||
int *header_len, AVMetadata *m)
|
int *header_len, AVMetadata *m, int framing_bit)
|
||||||
{
|
{
|
||||||
const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
|
const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
|
||||||
int size;
|
int size;
|
||||||
uint8_t *p, *p0;
|
uint8_t *p, *p0;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
|
|
||||||
size = offset + ff_vorbiscomment_length(m, vendor, &count);
|
size = offset + ff_vorbiscomment_length(m, vendor, &count) + framing_bit;
|
||||||
p = av_mallocz(size);
|
p = av_mallocz(size);
|
||||||
if (!p)
|
if (!p)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -221,6 +221,8 @@ static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
|
|||||||
|
|
||||||
p += offset;
|
p += offset;
|
||||||
ff_vorbiscomment_write(&p, m, vendor, count);
|
ff_vorbiscomment_write(&p, m, vendor, count);
|
||||||
|
if (framing_bit)
|
||||||
|
bytestream_put_byte(&p, 1);
|
||||||
|
|
||||||
*header_len = size;
|
*header_len = size;
|
||||||
return p0;
|
return p0;
|
||||||
@ -254,7 +256,7 @@ static int ogg_build_flac_headers(AVCodecContext *avctx,
|
|||||||
bytestream_put_buffer(&p, streaminfo, FLAC_STREAMINFO_SIZE);
|
bytestream_put_buffer(&p, streaminfo, FLAC_STREAMINFO_SIZE);
|
||||||
|
|
||||||
// second packet: VorbisComment
|
// second packet: VorbisComment
|
||||||
p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m);
|
p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
|
||||||
if (!p)
|
if (!p)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
oggstream->header[1] = p;
|
oggstream->header[1] = p;
|
||||||
@ -285,7 +287,7 @@ static int ogg_build_speex_headers(AVCodecContext *avctx,
|
|||||||
AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
|
AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
|
||||||
|
|
||||||
// second packet: VorbisComment
|
// second packet: VorbisComment
|
||||||
p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m);
|
p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
|
||||||
if (!p)
|
if (!p)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
oggstream->header[1] = p;
|
oggstream->header[1] = p;
|
||||||
@ -352,6 +354,11 @@ static int ogg_write_header(AVFormatContext *s)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
uint8_t *p;
|
||||||
|
char *cstr = st->codec->codec_id == CODEC_ID_VORBIS ? "vorbis" : "theora";
|
||||||
|
int header_type = st->codec->codec_id == CODEC_ID_VORBIS ? 3 : 0x81;
|
||||||
|
int framing_bit = st->codec->codec_id == CODEC_ID_VORBIS ? 1 : 0;
|
||||||
|
|
||||||
if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
|
if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
|
||||||
st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42,
|
st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42,
|
||||||
oggstream->header, oggstream->header_len) < 0) {
|
oggstream->header, oggstream->header_len) < 0) {
|
||||||
@ -359,6 +366,17 @@ static int ogg_write_header(AVFormatContext *s)
|
|||||||
av_freep(&st->priv_data);
|
av_freep(&st->priv_data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p = ogg_write_vorbiscomment(7, st->codec->flags & CODEC_FLAG_BITEXACT,
|
||||||
|
&oggstream->header_len[1], s->metadata,
|
||||||
|
framing_bit);
|
||||||
|
if (!p)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
oggstream->header[1] = p;
|
||||||
|
bytestream_put_byte(&p, header_type);
|
||||||
|
bytestream_put_buffer(&p, cstr, 6);
|
||||||
|
|
||||||
if (st->codec->codec_id == CODEC_ID_THEORA) {
|
if (st->codec->codec_id == CODEC_ID_THEORA) {
|
||||||
/** KFGSHIFT is the width of the less significant section of the granule position
|
/** KFGSHIFT is the width of the less significant section of the granule position
|
||||||
The less significant section is the frame count since the last keyframe */
|
The less significant section is the frame count since the last keyframe */
|
||||||
|
Loading…
Reference in New Issue
Block a user