[FFmpeg-devel] [PATCH] read metadata in FLAC demuxer
Michael Niedermayer
michaelni
Sun Sep 30 12:16:20 CEST 2007
On Sun, Sep 30, 2007 at 12:48:08AM -0400, Justin Ruggles wrote:
> Hi,
>
> Here is a patch to fix issue 187 in the FFmpeg Issue Tracker, "flac decoder
> fails with large metadata".
>
> For raw FLAC files, the metadata header(s) are read in the demuxer rather
> than the decoder. This correctly skips any irrelevant metadata blocks, and
> it also parses vorbiscomment info.
what happens with flac in avi and matroska ?
[...]
> + /* create AVStream */
> st = av_new_stream(s, 0);
cosmetic
> if (!st)
> return AVERROR(ENOMEM);
> st->codec->codec_type = CODEC_TYPE_AUDIO;
> st->codec->codec_id = CODEC_ID_FLAC;
> - st->need_parsing = AVSTREAM_PARSE_FULL;
> - /* the parameters will be extracted from the compressed bitstream */
> +
> + /* verify fLaC tag */
> + if(get_be32(pb) != MKBETAG('f','L','a','C'))
> + return -1;
> +
> + /* read metadata blocks */
> + do {
> + int tmp, type, size;
> + tmp = get_byte(pb);
> + last_metablock = tmp >> 7;
> + type = tmp & 0x7F;
> + size = get_be24(pb);
> + if(size) {
> + if(type == 0) {
> + /* read streaminfo to codec extradata */
> + GetBitContext gb;
> + int64_t samples;
> + st->codec->extradata = av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
> + get_buffer(pb, st->codec->extradata, size);
> + init_get_bits(&gb, st->codec->extradata, FLAC_STREAMINFO_SIZE*8);
> +
> + skip_bits(&gb, 16*2+24*2);
> + st->codec->sample_rate = get_bits_long(&gb, 20);
> + st->codec->channels = get_bits(&gb, 3) + 1;
> + skip_bits(&gb, 5);
> + samples = get_bits(&gb, 4);
> + samples = (samples << 32) | get_bits_long(&gb, 32);
> + if(!st->codec->sample_rate) {
> + av_freep(&st->codec->extradata);
> + return -1;
> + }
> + st->codec->extradata_size = FLAC_STREAMINFO_SIZE;
> + av_set_pts_info(st, 64, 1, st->codec->sample_rate);
> + if(samples) {
> + s->start_time = 0;
> + s->duration = samples * AV_TIME_BASE / st->codec->sample_rate;
> + }
> + } else if(type == 4) {
> + /* read and parse vorbiscomment metadata block */
> + uint8_t *vorbiscomment = av_malloc(size);
> + get_buffer(pb, vorbiscomment, size);
> + vorbis_comment(s, vorbiscomment, size);
> + av_freep(&vorbiscomment);
> + } else {
> + url_fskip(pb, size);
> + }
> + }
> + } while(!last_metablock);
also thats duplicating code (from the decoder)
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070930/0fb14812/attachment.pgp>
More information about the ffmpeg-devel
mailing list