[FFmpeg-devel] [PATCH] flac encoding, issue 526

Justin Ruggles justinruggles
Sat Jul 19 17:24:49 CEST 2008


Mathieu Velten wrote:
> Index: libavcodec/flacenc.c
> ===================================================================
> --- libavcodec/flacenc.c	(revision 14300)
> +++ libavcodec/flacenc.c	(working copy)
> @@ -103,7 +103,9 @@
>      int samplerate;
>      int sr_code[2];
>      int max_framesize;
> +    int last_framesize;

This is not needed.

>      uint32_t frame_count;
> +    uint64_t sample_count;
>      FlacFrame frame;
>      CompressionOptions options;
>      AVCodecContext *avctx;
> @@ -142,8 +144,8 @@
>      put_bits(&pb, 20, s->samplerate);
>      put_bits(&pb, 3, s->channels-1);
>      put_bits(&pb, 5, 15);       /* bits per sample - 1 */
> +    put_bits(&pb, 36, s->sample_count);
>      flush_put_bits(&pb);
> -    /* total samples = 0 */
>      /* MD5 signature = 0 */
>  }

You can't write 36 bits in a single put_bits()

>  
> @@ -382,7 +384,9 @@
>      avctx->extradata = streaminfo;
>      avctx->extradata_size = FLAC_STREAMINFO_SIZE;
>  
> +    s->last_framesize = 0;
>      s->frame_count = 0;
> +    s->sample_count = 0;
>  
>      avctx->coded_frame = avcodec_alloc_frame();
>      avctx->coded_frame->key_frame = 1;
> @@ -1464,6 +1468,14 @@
>      }
>  
>      s->frame_count++;
> +    s->sample_count += avctx->frame_size;
> +
> +    // When the last block is reached, rewrite the header with the correct length in case of the muxer needs it
> +    if ((data == NULL) || (avctx->frame_size < s->last_framesize)) {
> +        write_streaminfo(s, avctx->extradata);
> +    }
> +    s->last_framesize = avctx->frame_size;
> +
>      return out_bytes;
>  }

This can be simplified to just check avctx->frame_size against
s->frame.blocksize.

> Index: libavformat/raw.c
> ===================================================================
> --- libavformat/raw.c	(revision 14300)
> +++ libavformat/raw.c	(working copy)
> @@ -43,7 +43,25 @@
>      return 0;
>  }
>  
> +static int flac_write_trailer(struct AVFormatContext *s)
> +{
> +    ByteIOContext *pb = s->pb;
> +    uint8_t *streaminfo = s->streams[0]->codec->extradata;
> +    int len = s->streams[0]->codec->extradata_size;
> +    offset_t file_size;
>  
> +    if (!url_is_streamed(s->pb)) {
> +        file_size = url_ftell(pb);
> +        url_fseek(pb, 8, SEEK_SET);
> +        put_buffer(pb, streaminfo, len);
> +
> +        url_fseek(pb, file_size, SEEK_SET);
> +
> +        put_flush_packet(pb);		
> +    }
> +    return 0;
> +}
> +
>  static int roq_write_header(struct AVFormatContext *s)
>  {
>      static const uint8_t header[] = {
> @@ -617,6 +635,7 @@
>      CODEC_ID_NONE,
>      flac_write_header,
>      raw_write_packet,
> +    flac_write_trailer,
>      .flags= AVFMT_NOTIMESTAMPS,
>  };
>  #endif //CONFIG_MUXERS

This part looks ok.

-Justin





More information about the ffmpeg-devel mailing list