Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opusenc from git fails to encode very short flac files on windows #78

Open
MarcroSoft opened this issue Jun 30, 2023 · 4 comments · May be fixed by #95
Open

Opusenc from git fails to encode very short flac files on windows #78

MarcroSoft opened this issue Jun 30, 2023 · 4 comments · May be fixed by #95

Comments

@MarcroSoft
Copy link

Hi.
I made an issue about this in the opus repo but it's related to opus-tools instead.
When I try to encode a short flac file with opusenc it says:
ERROR: Could not open FLAC stream.
Error: unsupported input file: synth1.flac
I compiled opus-tools 0.2 with dynamic libflac and that worked, but not the version from git, neither dynamic or static. (Haven't tried 0.2 static yet).
I can try to bisect it, but as I get no audio by inverting a file with the git version and 0.2 it's really low priority.
But if you know of a git change after 0.2 that has to do with flac input that might be it.
Thanks,
Marc

@MarcroSoft
Copy link
Author

I'm finished bisecting, and here it is:
5d0ac20 is the first bad commit
commit 5d0ac20
Author: Thomas Daede [email protected]
Date: Fri Jan 21 07:03:46 2022 -0800

Allow FLAC files with ID3 tags to pass the ID check.                                                                
                                                                                                                    
Signed-off-by: Mark Harris <[email protected]>                                                                     

src/audio-in.c | 10 ++++------
src/flac.c | 19 ++++++++++++++++---
2 files changed, 20 insertions(+), 9 deletions(-)

Which makes sence because the commit has to do with flac files.
You can take a look at it if you want.

@vlakoff
Copy link

vlakoff commented Dec 3, 2024

I encountered the same error. See in Chocobo1/opus-tools_win32-build#13, where I attached an example FLAC file of 14.2 KB.

  • The changes by 5d0ac20 in open_audio_file() and flac_id() seem to be correct.
  • The error message is in flac_open(), and I could emit these suppositions:
    • This function might need some update accordingly (but I don't think that's the case).
    • TheFLAC__stream_decoder_process_until_end_of_metadata() function that is called might not support such ID3 tags.
  • For completeness: a few months after 5d0ac20, some related fix has been implemented in read_callback(): ecd50e5.

ping @tdaede

@Chocobo1
Copy link
Contributor

Chocobo1 commented Dec 4, 2024

I briefly looked into it. Here is my findings:

if(FLAC__stream_decoder_process_until_end_of_metadata(flac->decoder)&&

Here the FLAC__stream_decoder_process_until_end_of_metadata failed and FLAC__stream_decoder_get_state == FLAC__STREAM_DECODER_END_OF_STREAM.
Of all the callbacks, only the eof_callback is called once and it returns true and the entire flac procedure just stopped.
This is due to 5d0ac20, it reads a lot of data (64K) which easily read all data of a small file and the FILE position goes to eof.

I guess it has something to do with flac internal implementation which couldn't handle this specific eof case properly.

A dirty workaround is to just disable the eof_callback:

A little more proper workaround is to add rewind(in) to reset the FILE position at here:

flac->f=in;

I'll take a shot at it in PR #95.

Chocobo1 added a commit to Chocobo1/opus-tools that referenced this issue Dec 4, 2024
The file handle might be at EOF if the input .opus file is small. So
reset the file position properly before any further handling.

Fixes xiph#78.
@Chocobo1 Chocobo1 linked a pull request Dec 4, 2024 that will close this issue
Chocobo1 added a commit to Chocobo1/opus-tools that referenced this issue Dec 4, 2024
The file handle might be at EOF if the input .opus file is small. So
reset the file position properly before any further handling.

Fixes xiph#78.
@Toby-Haynes
Copy link

I see this error regularly for files which are entirely silence, for which the flac file is extremely small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants