[Ffmpeg-devel] [PATCH] flacenc - md5

Michael Niedermayer michaelni
Sun Jul 2 23:15:21 CEST 2006


On Sun, Jul 02, 2006 at 12:56:24PM -0400, Justin Ruggles wrote:
> Hi,
> This patch enables writing the MD5 checksum in the FLAC header.  It also
> writes the total number of samples.  The solution is based on the way
> that the WAV muxer seeks back & writes over portions of the header after
> encoding is finished.
> I am not 100% happy with how I had to do the md5 calculation, but I
> can't think of any other way...  The problem I ran into is that there is
> no way for the encoder to know when it is encoding the last frame.

set CODEC_CAP_DELAY and you should get a last zero size frame to indicate the

> Looking for a smaller frame would do it most of the time, but not if the
> sample count is an even multiple of the block size.  So the solution I
> came up with was to write the MD5 value to the extradata when encoding
> every frame, as if every frame was the last one.  To do this, I had to
> copy the working MD5 struct to a temporary struct before running
> av_md5_final().  Since 'struct AVMD5' is an incomplete type, the
> solution looks a bit ugly, but it works.

hmm, seems flac is almost beating ogg in the most idiotic design category
* putting a checksum of the whole stream at the begin makes flac unuseable for
  streaming, and anything realtime
* doing the checksum over the unencoded data instead of the encoded makes
  it impossible to check without decoding, impossible to add the checksum
  at the muxer level where it belongs too and its slower too as the
  unencoded data is larger then the encoded not to mention that without
  specifiying the byteorder or channel interleaving of the input the
  checksum is of course not well defined

now to your patch, of course i dont like it, extradata is for a global header
that means it should be set early by the encoder and it must never change

my first idea for a solution is to simply set the md5 to 0, what will break?
players cannot check the md5 so they cant notice it, its only tools
which transcode the whole file which might complain about a md5 missmatch

all other solutions seems messy
* buffer all frames in the encoder before writing any (not possible due to
  the memory requirements)
* set extradata at the end and have a special case in the raw muxer, what
  about ogg, avi, nut, mov and all other general propose containers?
* put the header at the end and have a external program copy it to the start
* 2pass encoding, first will just calculate md5 ... (this seems like its not
  that bad?)


Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is

More information about the ffmpeg-devel mailing list