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

Calling stop too quickly after start generates an empty (0 byte) file #266

Open
andrewkolos opened this issue Dec 22, 2023 · 3 comments
Open
Labels
bug Something isn't working Windows

Comments

@andrewkolos
Copy link

andrewkolos commented Dec 22, 2023

Package version: 5.0.4

Environment
Windows 11 Pro
Version 22H2 (OS Build 22621.2861)

Starting a recording and quickly stopping it (within a small fraction of a second) risks creating a completely empty file.

To Reproduce

Repro project: https://github.com/andrewkolos/_repro_start_and_stop_record/tree/main/start_and_stop_empty_file

If using this project:

  • flutter run -d windows
  • Click the first button, which will try to make a recording with a length of zero. Check the logs for the path of the output audio file, which will be an empty file (0 bytes). Expected behavior: the file should instead be a valid audio file with a length of zero (or near zero).
  • If you have ffprobe available on your system's path, the program will print the length of the audio file. If the file is empty, ffprobe will fail, and its output will be empty.
Logs from me using this app to generate a zero-length recording
flutter: Started recording with a duration of 0:00:00.000000
flutter: Stopping recording at 35 milliseconds...
flutter: Finished stopping at 293 milliseconds.
flutter: You can find your audio file at C:\Users\Jozz\Documents\record_start_stop_empty_file_repro\599614901.m4a
flutter: Duration between .start() being called and .stop() being  called was 0:00:00.035000
flutter: Duration between .start() being called and .start() finishing was 0:00:00.035000
flutter: Duration between .start() finishing and .stop() being called was 0:00:00.000000
flutter: Duration between .start() finishing and .stop() finishing was 0:00:00.258000
flutter: Duration between .start() being called and .stop() finishing was 0:00:00.293000
flutter: Running ffprobe: ffprobe -i C:\Users\Jozz\Documents\record_start_stop_empty_file_repro\599614901.m4a -show_entries format=duration -sexagesimal -v quiet -of csv=p=0
flutter: ffprobe failed to run. Is the file empty?
flutter:

If not using the provided repro project, code similar to this will probably repro the issue:

recorder
    .start(
      const RecordConfig(encoder: AudioEncoder.aacLc),
      path: audioPath,
    )
    .then((_) => recorder.stop()); // Calls stop as soon as start is done.

Workaround

Since the audio file is empty, it's easy to determine that the file is not valid audio. Personally, I just check the audio file is empty before trying to process it.

@andrewkolos andrewkolos changed the title Calling stop too quickly after start generates an empty (0 byte) file instead of a zero-length audio file Calling stop too quickly after start generates an empty (0 byte) file Dec 22, 2023
@andrewkolos
Copy link
Author

andrewkolos commented Dec 22, 2023

Something I forgot to add is that this can happen even with non-zero-length recording sessions, as long as the duration is short enough. For example, calling stop ~50ms after start will still produce an empty file. I wonder if audio data is being lost?

Feel free to tweak the provided repro code to try this with different durations.

@llfbandit
Copy link
Owner

@andrewkolos I suppose the callback to fill audio data had no chance to be called before you stopped the recording so soon.
From here, internally there's a Finalize method called to fill headers and properly place end marker. In such case, I guess the writer doesn't know what to do and so does nothing...?
Well, in short, I need to investigate.

@akshatbaranwal Please a proper separated issue, this has nothing related with the current one.

@llfbandit llfbandit added bug Something isn't working Windows labels Jan 11, 2024
@atoka93
Copy link

atoka93 commented Mar 4, 2024

It is happening on iOS as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

No branches or pull requests

3 participants