Why write to temp file?

#16 · closed · 3 comments

View on GitHub ↗

tasinet

Why the piping though the temporary file? It seems to be a wasteful write to disk.

Comments

ArtskydJ

Good question. I wish it worked consistently without the temp file. However, sox has issues reading from a piped stream sometimes. I think certain formats just didn't work without a temp file. If I recall correctly, FLAC or MP3 had issues when being piped in w/o a temp file.

tasinet

Thanks! I realised this yesterday: I added buffers on another implementation that works with in-memory streams and hit the same problem (FLAC corruption). WAV works thankfully, so I can still use it. Any idea what the underlying cause may be?

ArtskydJ

I don't think there's a good way for sox to handle streams in all cases. For efficiency/performance reasons, sox can't buffer the entire file. - Without the entire file, you might lose some metadata in the ID3 tags, or equivalent in whatever format you use. I would hope that the metadata could be buffered. - Without the entire file, (again, depending on the format) you might not know how long the input is. But maybe you need to write the length to the beginning/head of the output file. These are just guesses.