llfbandit / record

Audio recorder from microphone to a given file path. No external dependencies, MediaRecorder is used for Android an AVAudioRecorder for iOS.
https://pub.dev/packages/record
232 stars 193 forks source link

Recorded file's duration is zero [m4a format, aacLc] #253

Closed arreshashikant closed 6 months ago

arreshashikant commented 9 months ago

Package version record: ^5.0.1

Environment

Describe the bug

Recording works fine. But, when we try to get the duration of recorded file (either through ffmpeg or audioplayers plugin), it returns Zero Duration.

RecordConfig - Default

  const RecordConfig({
    this.encoder = AudioEncoder.aacLc,
    this.bitRate = 128000,
    this.sampleRate = 44100,
    this.numChannels = 2,
    this.device,
    this.autoGain = false,
    this.echoCancel = false,
    this.noiseSuppress = false,
  });

To Reproduce

Steps to reproduce the behavior: Sample repository - https://github.com/arreshashikant/buggy_repo/tree/recordDurationZero branch - recordDurationZero

Expected behavior Return valid duration of the recorded file

Additional context The recorded bytes returns valid duration if we start recording with startStream

Hatemsla commented 9 months ago

Same problem

arsyad-revo commented 9 months ago

I'm having the same issue too... hopefully, it can be fixed soon...

llfbandit commented 9 months ago

Released in record_android 1.0.4. Sorry, this issue was closed for no reason...

Evgentret commented 9 months ago

Still have a problem with zero record duration, record_android 1.04

llfbandit commented 9 months ago

This issue is very unclear to me. I don't reproduce any issue with the duration. @arreshashikant Your reproducer is wrongly set, this is not how audioplayers works. You must rely on streams to get your info.

I updated the example in the repository to show the audio duration before playing it.

If other participants have more or other info to share, it is time before I close this.

arreshashikant commented 9 months ago

I agree that we should rely on streams to get duration. But, There's no issue with player when AudioPlayer.getDuration() call is made after setSource future is complete.

Evgentret commented 8 months ago

This issue is very unclear to me. I don't reproduce any issue with the duration. @arreshashikant Your reproducer is wrongly set, this is not how audioplayers works. You must rely on streams to get your info.

I updated the example in the repository to show the audio duration before playing it.

If other participants have more or other info to share, it is time before I close this.

When compile and build your example I've got duration 00:00:00.023 on Android real device in any way. But when I run this example on iPhone - duration is correct. Also, all audio recorded using iPhone had correct duration when playing in Android and all audio recorded in Android has near-the-zero duration in iPhone. Another example, when I send recorded audio by your example to the Telegram, if audio from iPhone - it has correct duration, when I send recorded audio from Android - duration showed zero.

Flutter (Channel stable, 3.16.5, on macOS 13.6.1 22G313 darwin-x64)

Problem only with codecs aacLc, aacEld, aacHe Opus on Android work well

Plugin output:

I/MediaCodec(11566): Codec shutdown complete W/MPEG4Writer(11566): 0-duration samples found: 117 I/MPEG4Writer(11566): Received total/0-length (118/0) buffers and encoded 118 frames. - Audio I/MPEG4Writer(11566): Audio track drift time: 0 us I/MPEG4Writer(11566): Normal stop process D/MPEG4Writer(11566): Audio track stopping. Stop source D/MPEG4Writer(11566): Audio track source stopping D/MPEG4Writer(11566): Audio track source stopped D/MPEG4Writer(11566): Audio track stopped. Stop source D/MPEG4Writer(11566): Stopping writer thread D/MPEG4Writer(11566): 0 chunks are written in the last batch D/MPEG4Writer(11566): Writer thread stopped I/MPEG4Writer(11566): The mp4 file will not be streamable. D/MPEG4Writer(11566): Audio track stopping. Stop source

Allenxuxu commented 8 months ago

I have the same issue.

utkudenis commented 7 months ago

We had similar issue with player new version 5.0.x everyting is perfect 4.4.4 however, when we updated to 5.0.x there was unstable problem. although records can listen on the recorded phone. they were not working other devices. An Example, recorder settings screenshot image

We used ai to compare working and notworking voice record. image

The problem was on the bitrate.

Summary, records on the android was problematic.
file extension was .m4a

blok5025 commented 7 months ago

We had similar issue with player new version 5.0.x everyting is perfect 4.4.4 however, when we updated to 5.0.x there was unstable problem. although records can listen on the recorded phone. they were not working other devices. An Example, recorder settings screenshot image

We used ai to compare working and notworking voice record. image

The problem was on the bitrate.

Summary, records on the android was problematic. file extension was .m4a

Did you find a Solution?

I have an issue where files recorded on Android don't have an extension but can be listened on the device it was recorded but not on iOS

utkudenis commented 7 months ago

We had similar issue with player new version 5.0.x everyting is perfect 4.4.4 however, when we updated to 5.0.x there was unstable problem. although records can listen on the recorded phone. they were not working other devices. An Example, recorder settings screenshot image We used ai to compare working and notworking voice record. image The problem was on the bitrate. Summary, records on the android was problematic. file extension was .m4a

Did you find a Solution?

I have an issue where files recorded on Android don't have an extension but can be listened on the device it was recorded but not on iOS

version 4.4.4.

blok5025 commented 7 months ago

@llfbandit This is a major issue as it's linked to the default settings of the RecordConfig(). Android files are corrupted and unreadable from the backend.

llfbandit commented 7 months ago

I can't reproduce this issue with the two devices I own.

Here's what I get when using default settings. This is perfectly fine (at least it seems).

Format                      : MPEG-4
Format profile              : Base Media / Version 2
Codec ID                    : mp42 (isom/mp42)
File size                   : 54.3 KiB
Duration                    : 3 s 251 ms
Overall bit rate mode       : Constant
Overall bit rate            : 137 kb/s
Encoded date                : 2024-02-20 17:28:29 UTC
Tagged date                 : 2024-02-20 17:28:29 UTC
com.android.version         : 14

Audio
ID                          : 1
Format                      : AAC LC
Format/Info                 : Advanced Audio Codec Low Complexity
Codec ID                    : mp4a-40-2
Duration                    : 3 s 251 ms
Source duration             : 3 s 274 ms
Bit rate mode               : Constant
Bit rate                    : 128 kb/s
Channel(s)                  : 2 channels
Channel layout              : L R
Sampling rate               : 44.1 kHz

Can someone send me audio files for comparison?

blok5025 commented 7 months ago

@llfbandit

The Android file get recognized as a Video file. Perhaps that's why it's unreadable with an audio decoder

Try using the android Emulator to reproduce the issue.

llfbandit commented 7 months ago

Please, send me the files.

blok5025 commented 7 months ago

To whomever is using this package and audioplayers while fetching data from Firebase Storage. I was able to fix this issue in ^5.0.4 by passing the metadata manually with the file because, for some unknown reason, Firebase is not able to understand the file format of the Android Encoded file and without a File extension, the files are unreadable on iOS. (See Troubleshoot)

Shawn-sudo commented 6 months ago

@llfbandit I have an example file here: https://drive.google.com/file/d/1Upa2y9py4yeOgzehWXl1jzCZa0gu9pkV/view?usp=sharing

llfbandit commented 6 months ago

Could someone test with current code of record_android on git?

shichunlei commented 4 months ago

I still have this problem in record: ^5.1.0. How did you solve it?

utkudenis commented 3 months ago

Hi everyone, I'm still using record 4.4.4 because of the problem on this issue.

Is there any garantee for the 5.1.1

Because of the recording our app main feature, I cannot get risk to update package version. However, I need to update record with new flutter version requirement and dependencies

utkudenis commented 2 months ago

@Shawn-sudo , @shichunlei , @llfbandit and @blok5025 can you share how is going on last version of the record package 5.1.2 ? i need to update my package 4.4.4 to 5.1.2