[Flac-dev] Can a libFLAC encoder be initialize and called from inside a libFLAC decoder callback?

Brian Willoughby brianw at sounds.wa.com
Tue May 24 11:15:38 PDT 2011


Have you tried decoding to memory, and encoding from that memory?   
This technique would avoid file I/O.

If you are reluctant to allocate enough memory for the full file (and  
why not, with a 64-bit system?), then you could implement a FIFO.   
You would need a semaphore to keep track of the decoder's progress,  
and multithreaded coding.  The decoder would pause, whenever the FIFO  
gets full, until the encoder empties out the samples so far.

It's also possible that you have made a mistake in InitializeEncoder 
() where the new file format does not match the incoming Buffer blocks.

Brian Willoughby
Sound Consulting


On May 24, 2011, at 10:16, David Troendle wrote:
> I am getting large, corrupted native FLAC files when trying to call  
> the encoder from inside the decoder.  The metadata in the output  
> file is OK.
>
> Is initializing and calling an encoder from inside a libFLAC  
> decoder write callback supported?  The encoder is initialized on  
> the first write callback.
>
> Here is some context. The static callback calls the instance  
> callback.  Encoder is initialized on line with “m_HaveEncoder =  
> InitializeEncoder();”.  Samples are submitted to the encoder on  
> line with “FLAC__bool OK = FLAC__stream_encoder_process(m_Encoder,  
> Buffer, Blocksize);”.
>
> I have a version that decodes to a WAV file and then re-encodes the  
> WAV file, but would like to avoid all that I/O.
>
>




More information about the Flac-dev mailing list